From 0176a6cdfbf6f10144d5d93db1310b8ffbd430aa Mon Sep 17 00:00:00 2001 From: Moritz Wiesinger Date: Thu, 14 Oct 2021 10:22:52 +0200 Subject: [PATCH] chore: Add config files for release-automation (#2) --- .github/workflows/release.yml | 79 ++++++++++++++++++++ .gitignore | 2 + .versionrc.json | 51 +++++++++++++ gh-actions-scripts/post-changelog-actions.sh | 13 ++++ 4 files changed, 145 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 .versionrc.json create mode 100755 gh-actions-scripts/post-changelog-actions.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2a1aa43 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,79 @@ +name: Release +on: + workflow_dispatch: +env: + NODE_VERSION: 14 + KEPTN_BOT_NAME: "Keptn Bot" + KEPTN_BOT_EMAIL: "keptn-bot <86361500+keptn-bot@users.noreply.github.com>" + RELEASE_NOTES_FILE: "RELEASE-BODY.md" +defaults: + run: + shell: bash +jobs: + release: + name: "Release" + runs-on: ubuntu-20.04 + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Configure Git + env: + KEPTN_BOT_NAME: ${{ env.KEPTN_BOT_NAME }} + KEPTN_BOT_EMAIL: ${{ env.KEPTN_BOT_EMAIL }} + run: | + git config user.name "$KEPTN_BOT_NAME" + git config user.email "$KEPTN_BOT_EMAIL" + + - name: Prepare GitHub Release Notes + run: | + # Delete pre-release tags to be able to generate a changelog from last 'real' release + # This is a workaround for a known limitation of standard-version + # Reference: https://github.com/conventional-changelog/standard-version/issues/203#issuecomment-872415140 + git tag -l | grep -vE '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$' | xargs git tag -d + + npx standard-version@^9.3.1 -i "${{ env.RELEASE_NOTES_FILE }}" --skip.commit --skip.tag --header "" + + - name: Temporarily disable "include administrators" branch protection + uses: benjefferies/branch-protection-bot@6d0ac2b2d9bfd39794b017f8241adb7da7f0ab98 # pin@1.0.7 + with: + access_token: ${{ secrets.KEPTN_BOT_TOKEN }} + branch: ${{ github.event.repository.default_branch }} + enforce_admins: false + + - name: Create release package + id: create-release-package + env: + GITHUB_TOKEN: ${{ secrets.KEPTN_BOT_TOKEN }} + run: | + echo "🚀 Creating release package now..." + npx standard-version@^9.3.1 + + echo "::set-output name=tag-name::$(git describe --tags --abbrev=0)" + + echo "Fetching previously deleted old tags..." + git fetch origin --tags -f + echo "⚡️ Pushing changes to remote repository..." + git push --follow-tags + + - name: Enable "include administrators" branch protection + uses: benjefferies/branch-protection-bot@6d0ac2b2d9bfd39794b017f8241adb7da7f0ab98 # pin@1.0.7 + if: always() # Force to always run this step to ensure "include administrators" is always turned back on + with: + access_token: ${{ secrets.KEPTN_BOT_TOKEN }} + branch: ${{ github.event.repository.default_branch }} + enforce_admins: true + + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ secrets.KEPTN_BOT_TOKEN }} + RELEASE_TAG: ${{ steps.create-release-package.outputs.tag-name }} + run: | + gh release create "$RELEASE_TAG" --draft --notes-file "${{ env.RELEASE_NOTES_FILE }}" --title "$RELEASE_TAG" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66f8fb5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +.vscode/ diff --git a/.versionrc.json b/.versionrc.json new file mode 100644 index 0000000..1fc3d23 --- /dev/null +++ b/.versionrc.json @@ -0,0 +1,51 @@ +{ + "scripts": { + "postchangelog": "./gh-actions-scripts/post-changelog-actions.sh" + }, + "types": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "chore", + "section": "Other" + }, + { + "type": "docs", + "section": "Docs" + }, + { + "type": "perf", + "section": "Performance" + }, + { + "type": "build", + "hidden": true + }, + { + "type": "ci", + "hidden": true + }, + { + "type": "refactor", + "section": "Refactoring" + }, + { + "type": "revert", + "hidden": true + }, + { + "type": "style", + "hidden": true + }, + { + "type": "test", + "hidden": true + } + ] +} diff --git a/gh-actions-scripts/post-changelog-actions.sh b/gh-actions-scripts/post-changelog-actions.sh new file mode 100755 index 0000000..6ed872b --- /dev/null +++ b/gh-actions-scripts/post-changelog-actions.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +echo "Removing sign-off messages from changelog..." +for file in {CHANGELOG,RELEASE-BODY}.md; do + if [ -f "$file" ]; then + echo "Replacing content in $file" + # Reference: https://stackoverflow.com/a/1252191 + sed -e ':a' -e 'N' -e '$!ba' -e 's/\nSigned-off-by: .* <.*@.*>\n/ /g' "$file" > tmp + mv tmp "$file" + else + echo "Not replacing anything since $file does not exist." + fi +done