From ef7186eba187b1c3f200eded76eb54e3a58cc385 Mon Sep 17 00:00:00 2001 From: Jan Buchar Date: Sun, 28 Apr 2024 23:09:34 +0200 Subject: [PATCH] ci: Set up release pipeline --- .github/workflows/release.yml | 71 +++++++++++++++++++++++++++++++++++ 1 file changed, 71 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 0000000..15e49d9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,71 @@ +name: Publish a release + +on: + workflow_dispatch: + inputs: + release_type: + required: true + type: choice + options: + - patch + - minor + - major + +env: + PR_BRANCH: release-ci-${{ github.sha }} + +jobs: + + prepare_metadata: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.bump_version.outputs.version }} + release_sha: ${{ steps.merge_pr.outputs.sha }} + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up git + run: | + git config --global user.email "ci@bucharjan.cz" + git config --global user.name "Jan Buchar" + - name: Create branch + run: | + git switch -c ${{ env.PR_BRANCH }} + - name: Bump version in package.json + id: bump_version + run: | + npm version ${{ github.event.inputs.release_type }} + echo version=$( node -p "require('./package.json').version" ) >> "$GITHUB_OUTPUT" + git push --set-upstream origin ${{ env.PR_BRANCH }} + - name: Create PR + run: | + gh pr create \ + --base master \ + --head ${{ env.PR_BRANCH }} \ + --title "chore: Release ${{ steps.bump_version.outputs.version }} [skip-ci]" \ + --body "Automated pull request - update to ${{ steps.bump_version.outputs.version }}" + env: + GH_TOKEN: ${{ github.token }} + - name: Approve and merge PR + id: merge_pr + run: | + gh pr review --approve ${{ env.PR_BRANCH }} + gh pr merge --squash --auto --delete-branch ${{ env.PR_BRANCH }} + echo sha=$( gh pr view --json mergeCommit ${{ env.PR_BRANCH }} | jq --raw-output .mergeCommit.oid ) >> "$GITHUB_OUTPUT" + env: + GH_TOKEN: ${{ secrets.PERSONAL_TOKEN }} + + gh_release: + runs-on: ubuntu-latest + needs: prepare_metadata + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Create release + uses: softprops/action-gh-release@v2 + with: + tag_name: release-${{ needs.prepare_metadata.outputs.version }} + name: Release ${{ needs.prepare_metadata.outputs.version }} + target_commitish: ${{ needs.prepare_metadata.outputs.release_sha }}