From 0a58953d5428bd8b98de18a1e442e39065578e28 Mon Sep 17 00:00:00 2001 From: Ioan Faur Date: Wed, 29 Jun 2022 22:52:57 +0300 Subject: [PATCH 1/2] Add support for draft releases - triggered on push and pull request events - prepares a draft release of the GitHub Releases page for manual verification --- .github/workflows/build.yml | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f518e1e1..7deb459e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,7 @@ # - run Qodana inspections, # - run 'buildPlugin' task and prepare artifact for the further tests, # - run 'runPluginVerifier' task, +# - create a draft release. # # Workflow is triggered on push and pull_request events. # @@ -120,4 +121,38 @@ jobs: uses: actions/upload-artifact@v3 with: name: ${{ steps.artifact.outputs.filename }} - path: ./build/distributions/content/*/* \ No newline at end of file + path: ./build/distributions/content/*/* + + # Prepare a draft release for GitHub Releases page for the manual verification + # If accepted and published, release workflow would be triggered + releaseDraft: + name: Release Draft + if: github.event_name != 'pull_request' + needs: build + runs-on: ubuntu-latest + steps: + + # Check out current repository + - name: Fetch Sources + uses: actions/checkout@v2.4.0 + + # Remove old release drafts by using the curl request for the available releases with draft flag + - name: Remove Old Release Drafts + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api repos/{owner}/{repo}/releases \ + --jq '.[] | select(.draft == true) | .id' \ + | xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{} + # Create new release draft - which is not publicly visible and requires manual acceptance + - name: Create Release Draft + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create v${{ needs.build.outputs.version }} \ + --draft \ + --title "v${{ needs.build.outputs.version }}" \ + --notes "$(cat << 'EOM' + ${{ needs.build.outputs.changelog }} + EOM + )" \ No newline at end of file From 3674ee5deca28722837d304e80556910fe85c3d8 Mon Sep 17 00:00:00 2001 From: Ioan Faur Date: Wed, 29 Jun 2022 23:09:19 +0300 Subject: [PATCH 2/2] Upload plugin artifact to Releases page - triggers the Release workflow when `Publish release` is used. - it also patches the Changelog with a new empty section for the next releae --- .github/workflows/release.yml | 84 +++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..d8d8848e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,84 @@ +# GitHub Actions Workflow created for handling the release process based on the draft release prepared with the Build workflow. + +name: Release +on: + release: + types: [prereleased, released] + +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@v2.4.0 + with: + ref: ${{ github.event.release.tag_name }} + + # Setup Java 11 environment for the next steps + - name: Setup Java + uses: actions/setup-java@v2 + with: + distribution: zulu + java-version: 11 + cache: gradle + + # Set environment variables + - name: Export Properties + id: properties + shell: bash + run: | + CHANGELOG="$(cat << 'EOM' | sed -e 's/^[[:space:]]*$//g' -e '/./,$!d' + ${{ github.event.release.body }} + EOM + )" + + CHANGELOG="${CHANGELOG//'%'/'%25'}" + CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" + CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" + + echo "::set-output name=changelog::$CHANGELOG" + + # Update Unreleased section with the current release note + - name: Patch Changelog + if: ${{ steps.properties.outputs.changelog != '' }} + env: + CHANGELOG: ${{ steps.properties.outputs.changelog }} + run: | + ./gradlew patchChangelog --release-note="$CHANGELOG" + + # Build the zip distribution + - name: Build Zip Plugin + run: ./gradlew buildPlugin + + # Upload artifact as a release asset + - name: Upload Release Asset + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/* + + # Create pull request + - name: Create Pull Request + if: ${{ steps.properties.outputs.changelog != '' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + VERSION="${{ github.event.release.tag_name }}" + BRANCH="changelog-update-$VERSION" + + git config user.email "action@github.com" + git config user.name "GitHub Action" + + git checkout -b $BRANCH + git commit -am "Changelog update - $VERSION" + git push --set-upstream origin $BRANCH + + gh pr create \ + --title "Changelog update - \`$VERSION\`" \ + --body "Current pull request contains patched \`CHANGELOG.md\` file for the \`$VERSION\` version." \ + --base main \ + --head $BRANCH \ No newline at end of file