From 8c7e883ddcd5508b9a1e9656a2a787f475de72dc Mon Sep 17 00:00:00 2001 From: Robert Galluccio Date: Wed, 2 Oct 2024 23:49:15 -0400 Subject: [PATCH] Adding actions for generating and publishing a release The generate-release action is a manual dispatch action that takes the version number as an input, and depending on the major version, will checkout either main or main_1.x, then merge either develop or develop_1.x into it, bump all the version strings in the repo, and raise a PR against main or main_1.x. The publish-release action runs on merge to main or main_1.x and reads the version from the version.txt file to determine the release tag it should publish, then publishes that release. NOTE: both of these actions are broken in v2 of the repo until we bring it up to date with the Swift Package Manager support changes, as the version.txt file does not exist in develop currently. --- .github/workflows/generate-release.yml | 87 ++++++++++++++++++++++++++ .github/workflows/publish-release.yml | 34 ++++++++++ 2 files changed, 121 insertions(+) create mode 100644 .github/workflows/generate-release.yml create mode 100644 .github/workflows/publish-release.yml diff --git a/.github/workflows/generate-release.yml b/.github/workflows/generate-release.yml new file mode 100644 index 0000000..9a921e2 --- /dev/null +++ b/.github/workflows/generate-release.yml @@ -0,0 +1,87 @@ +name: Generate Release +run-name: Generate Release ${{ fromJSON(inputs.major) }}.${{ fromJSON(inputs.minor) }}.${{ fromJSON(inputs.patch) }} + +on: + workflow_dispatch: + inputs: + major: + description: 'Major version' + required: true + default: '1' + type: choice + options: + - '1' + - '2' + minor: + description: 'Minor version' + required: true + type: number + patch: + description: 'Patch version' + required: true + type: number + +jobs: + bump-version-and-raise-pr: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + env: + version: ${{ fromJSON(inputs.major) }}.${{ fromJSON(inputs.minor) }}.${{ fromJSON(inputs.patch) }} + branch: ${{ inputs.major == 2 && 'develop' || 'develop_1.x' }} + target: ${{ inputs.major == 2 && 'main' || 'main_1.x' }} + steps: + - name: Check minor has no decimals + run: ${{ !contains(fromJSON(inputs.minor), '.') }} + + - name: Check patch has no decimals + run: ${{ !contains(fromJSON(inputs.patch), '.') }} + + - name: Checkout ${{ env.target }} + uses: actions/checkout@v4 + with: + ref: ${{ env.target }} + fetch-depth: 0 + + - name: Ensure tag does not exist + run: | + if git show-ref --tags --verify --quiet "refs/tags/$version"; then + echo "::error::Tag $version exists" && exit 1 + else + echo "Tag $version does not exist" + fi + + - name: Ensure branch does not exist + run: | + if git show-ref --verify --quiet "refs/remotes/origin/release/$version"; then + echo "::error::Release branch release/$version exists" && exit 1 + else + echo "Release branch release/$version does not exist" + fi + + - name: Merge in ${{ env.branch }} + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git merge origin/${{ env.branch }} + + - name: Update version in txt file + run: sed -i "s/[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}/$version/" ./mambaSharedFramework/Resources/version.txt + + - name: Update version in xcodeproj file + run: sed -i "s/MARKETING_VERSION = [0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\};/MARKETING_VERSION = $version;/" ./mamba.xcodeproj/project.pbxproj + + - name: Update version in podspec file + run: sed -i "s/= \"[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\"/= \"$version\"/" ./mamba.podspec + + - name: Create pull request + uses: peter-evans/create-pull-request@v7 + with: + title: Release ${{ env.version }} + commit-message: Bump version to ${{ env.version }} + branch: release/${{ env.version }} + body: | + Automated version bump to ${{ env.version }} generated by [create-pull-request][1]. + + [1]: https://github.com/peter-evans/create-pull-request diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 0000000..6bb9530 --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,34 @@ +name: Publish Release +on: + push: + branches: + - 'main' + - 'main_1.x' + +jobs: + get-version: + name: Get version for release + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - id: version + run: echo "version=`cat ./mambaSharedFramework/Resources/version.txt`" >> "$GITHUB_OUTPUT" + + publish-release: + name: Publish release ${{ needs.get-version.outputs.version }} + runs-on: ubuntu-latest + needs: get-version + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - name: Create release + uses: elgohr/Github-Release-Action@v5 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + title: ${{ needs.get-version.outputs.version }} + tag: ${{ needs.get-version.outputs.version }}