From 45af06f2cbbdf6b9d431de76ab030e26b5fbb455 Mon Sep 17 00:00:00 2001 From: Nick Le Large Date: Mon, 11 Nov 2024 13:06:16 +0100 Subject: [PATCH] Add workflow to create a new version and release on merge to main --- .../bump-version-and-create-release.yaml | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 .github/workflows/bump-version-and-create-release.yaml diff --git a/.github/workflows/bump-version-and-create-release.yaml b/.github/workflows/bump-version-and-create-release.yaml new file mode 100644 index 00000000..bde8e31c --- /dev/null +++ b/.github/workflows/bump-version-and-create-release.yaml @@ -0,0 +1,85 @@ +name: Bump version and create release +on: + pull_request: + types: + - closed + branches: + - main + - github_actions # TODO: Remove before merge + +jobs: + bump-version: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + permissions: + contents: write + outputs: + new_tag: ${{ steps.bump_version.outputs.new_tag }} + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Read version from file + run: | + # Read the version from the version file, only store the number (without the 'v') + INITIAL_VERSION=$(source version && echo ${VERSION#v}) + echo "Current version: $INITIAL_VERSION" + echo "INITIAL_VERSION=${INITIAL_VERSION}" >> $GITHUB_ENV + + - name: Bump version and push tag + id: bump_version + uses: anothrNick/github-tag-action@v1 + env: + DEFAULT_BUMP: minor + DRY_RUN: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + INITIAL_VERSION: ${{ env.INITIAL_VERSION }} + WITH_V: true + + - name: Update version file with new version + run: | + echo "New version: ${{ steps.bump_version.outputs.new_tag }}" + echo "VERSION=${{ steps.bump_version.outputs.new_tag }}" > version + git config --local user.name "github-actions[bot]" + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git add version + git commit -m "chore: update version file to ${{ steps.bump_version.outputs.new_tag }}" + git push + + - name: Push new tag + run: | + git tag ${{ steps.bump_version.outputs.new_tag }} + git push origin ${{ steps.bump_version.outputs.new_tag }} + + create-release: + needs: bump-version + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Check out the repository and pull the new tag + uses: actions/checkout@v4 + with: + ref: ${{ needs.bump-version.outputs.new_tag }} + + - name: Build release packages + uses: docker/build-push-action@v6 + with: + context: . + push: false + tags: | + arbitration_graphs_release + target: release + + - name: Copy release packages + run: | + mkdir -p /tmp/artifacts/ + docker run --rm -v /tmp/artifacts:/tmp/artifacts arbitration_graphs_release cp -r /release /tmp/artifacts/ + + - name: Create Release + uses: ncipollo/release-action@v1 + with: + artifacts: "/tmp/artifacts/release/*" + tag: ${{ needs.bump-version.outputs.new_tag }} + body: ${{ github.event.pull_request.body }} +