-
-
Notifications
You must be signed in to change notification settings - Fork 793
131 lines (110 loc) · 4.91 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# GitHub Actions Workflow created for handling the release process based on the draft release prepared
# with the Build workflow. Running the publishPlugin task requires the PUBLISH_TOKEN secret provided.
name: Release
on:
release:
types: [ released ]
env:
AUTO_SNAPSHOT_VERSION: false
jobs:
# Prepare and publish the plugin to the Marketplace repository
release:
name: Publish Plugin
runs-on: ubuntu-latest
steps:
# Check out current repository
- name: Fetch Sources
uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}
# Setup Java 11 environment for the next steps
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
cache: gradle
# Set environment variables
- name: Export Properties
id: properties
shell: bash
run: |
PROPERTIES="$(./gradlew properties --console=plain -q)"
PLUGIN_VERSION="$(echo "$PROPERTIES" | grep "^pluginVersion:" | cut -f2- -d ' ')"
PLUGIN_PRERELEASE_VERSION="$(echo "$PROPERTIES" | grep "^pluginPreReleaseVersion:" | cut -f2- -d ' ')"
PLUGIN_BUILD_METADATA="$(echo "$PROPERTIES" | grep "^pluginBuildMetadata:" | cut -f2- -d ' ')"
CHANGELOG="$(cat << 'EOM' | sed -e "/## What's Changed/d" -e 's/^[[:space:]]*$//g' -e '/./,$!d'
${{ github.event.release.body }}
EOM
)"
echo "pluginVersion: $PLUGIN_VERSION"
echo "pluginPrereleaseVersion: $PLUGIN_PRERELEASE_VERSION"
echo "pluginBuildMetadata: $PLUGIN_BUILD_METADATA"
echo "changelog:"
echo "$CHANGELOG"
echo "pluginVersion=$PLUGIN_VERSION" >> $GITHUB_OUTPUT
echo "pluginPrereleaseVersion=$PLUGIN_PRERELEASE_VERSION" >> $GITHUB_OUTPUT
echo "pluginBuildMetadata=$PLUGIN_BUILD_METADATA" >> $GITHUB_OUTPUT
echo 'changelog<<EOF' >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
# Update Unreleased section with the current release note
- name: Patch Changelog
if: steps.properties.outputs.pluginBuildMetadata == '' && steps.properties.outputs.changelog != ''
run: |
./gradlew patchChangelog --release-note="$(cat << 'EOM'
${{ steps.properties.outputs.changelog }}
EOM
)"
# Publish the plugin to the Marketplace
- name: Publish Plugin
env:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
run: ./gradlew publishPlugin
# Upload artifact as a release asset
- name: Upload Release Asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload v${{ steps.properties.outputs.pluginVersion }} ./build/distributions/*
# Create pull request
- name: Create Pull Request
if: steps.properties.outputs.pluginBuildMetadata == '' && steps.properties.outputs.changelog != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ github.event.release.tag_name }}"
BRANCH="changelog-update-$VERSION"
LABEL="release changelog 📑"
git config user.email "action@github.com"
git config user.name "GitHub Action"
git checkout -b $BRANCH
git commit -am ":rocket: ${VERSION}" -m "[skip ci]"
git push --set-upstream origin $BRANCH
gh label create "$LABEL" \
--color B39DDB \
--description "Pull requests with release changelog update" \
|| true
gh pr create \
--title ":rocket: \`$VERSION\`" \
--body "Current pull request contains patched \`CHANGELOG.md\` file for the \`$VERSION\` version." \
--base "${{ github.event.release.target_commitish }}" \
--label "$LABEL" \
--head $BRANCH
# Close the milestone
- name: Close Milestone
if: steps.properties.outputs.pluginPrereleaseVersion == '' && steps.properties.outputs.pluginBuildMetadata == ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api repos/{owner}/{repo}/milestones \
--jq '.[] | select(.title == "${{ github.event.release.tag_name }}") | .number' \
| xargs -I '{}' gh api -X PATCH repos/{owner}/{repo}/milestones/{} -F state='closed'
# Delete the release if the version has build metadata
- name: Delete Release
if: steps.properties.outputs.pluginBuildMetadata != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api repos/{owner}/{repo}/releases \
--jq ".[] | select(.tag_name == \"${{ github.event.release.tag_name }}\") | .id" \
| xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{}