Skip to content

Commit bad99aa

Browse files
authored
Merge pull request #32 from coder/add-gh-actions-for-release
Add support for automated releases Draft releases - triggered on push and pull request events - prepares a draft release of the GitHub Releases page for manual verification Publish to Release page - triggers the Release workflow when `Publish release` is used. - it also patches the Changelog with a new empty section for the next releae
2 parents 1ad97e0 + 3674ee5 commit bad99aa

File tree

2 files changed

+120
-1
lines changed

2 files changed

+120
-1
lines changed

.github/workflows/build.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# - run Qodana inspections,
55
# - run 'buildPlugin' task and prepare artifact for the further tests,
66
# - run 'runPluginVerifier' task,
7+
# - create a draft release.
78
#
89
# Workflow is triggered on push and pull_request events.
910
#
@@ -120,4 +121,38 @@ jobs:
120121
uses: actions/upload-artifact@v3
121122
with:
122123
name: ${{ steps.artifact.outputs.filename }}
123-
path: ./build/distributions/content/*/*
124+
path: ./build/distributions/content/*/*
125+
126+
# Prepare a draft release for GitHub Releases page for the manual verification
127+
# If accepted and published, release workflow would be triggered
128+
releaseDraft:
129+
name: Release Draft
130+
if: github.event_name != 'pull_request'
131+
needs: build
132+
runs-on: ubuntu-latest
133+
steps:
134+
135+
# Check out current repository
136+
- name: Fetch Sources
137+
uses: actions/checkout@v2.4.0
138+
139+
# Remove old release drafts by using the curl request for the available releases with draft flag
140+
- name: Remove Old Release Drafts
141+
env:
142+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
143+
run: |
144+
gh api repos/{owner}/{repo}/releases \
145+
--jq '.[] | select(.draft == true) | .id' \
146+
| xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{}
147+
# Create new release draft - which is not publicly visible and requires manual acceptance
148+
- name: Create Release Draft
149+
env:
150+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151+
run: |
152+
gh release create v${{ needs.build.outputs.version }} \
153+
--draft \
154+
--title "v${{ needs.build.outputs.version }}" \
155+
--notes "$(cat << 'EOM'
156+
${{ needs.build.outputs.changelog }}
157+
EOM
158+
)"

.github/workflows/release.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# GitHub Actions Workflow created for handling the release process based on the draft release prepared with the Build workflow.
2+
3+
name: Release
4+
on:
5+
release:
6+
types: [prereleased, released]
7+
8+
jobs:
9+
10+
# Prepare and publish the plugin to the Marketplace repository
11+
release:
12+
name: Publish Plugin
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
# Check out current repository
17+
- name: Fetch Sources
18+
uses: actions/checkout@v2.4.0
19+
with:
20+
ref: ${{ github.event.release.tag_name }}
21+
22+
# Setup Java 11 environment for the next steps
23+
- name: Setup Java
24+
uses: actions/setup-java@v2
25+
with:
26+
distribution: zulu
27+
java-version: 11
28+
cache: gradle
29+
30+
# Set environment variables
31+
- name: Export Properties
32+
id: properties
33+
shell: bash
34+
run: |
35+
CHANGELOG="$(cat << 'EOM' | sed -e 's/^[[:space:]]*$//g' -e '/./,$!d'
36+
${{ github.event.release.body }}
37+
EOM
38+
)"
39+
40+
CHANGELOG="${CHANGELOG//'%'/'%25'}"
41+
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
42+
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
43+
44+
echo "::set-output name=changelog::$CHANGELOG"
45+
46+
# Update Unreleased section with the current release note
47+
- name: Patch Changelog
48+
if: ${{ steps.properties.outputs.changelog != '' }}
49+
env:
50+
CHANGELOG: ${{ steps.properties.outputs.changelog }}
51+
run: |
52+
./gradlew patchChangelog --release-note="$CHANGELOG"
53+
54+
# Build the zip distribution
55+
- name: Build Zip Plugin
56+
run: ./gradlew buildPlugin
57+
58+
# Upload artifact as a release asset
59+
- name: Upload Release Asset
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/*
63+
64+
# Create pull request
65+
- name: Create Pull Request
66+
if: ${{ steps.properties.outputs.changelog != '' }}
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
run: |
70+
VERSION="${{ github.event.release.tag_name }}"
71+
BRANCH="changelog-update-$VERSION"
72+
73+
git config user.email "action@github.com"
74+
git config user.name "GitHub Action"
75+
76+
git checkout -b $BRANCH
77+
git commit -am "Changelog update - $VERSION"
78+
git push --set-upstream origin $BRANCH
79+
80+
gh pr create \
81+
--title "Changelog update - \`$VERSION\`" \
82+
--body "Current pull request contains patched \`CHANGELOG.md\` file for the \`$VERSION\` version." \
83+
--base main \
84+
--head $BRANCH

0 commit comments

Comments
 (0)