From ec058e0f1ae083d746e1da0e86bc5b3d313a207a Mon Sep 17 00:00:00 2001 From: warrensbox Date: Tue, 2 Apr 2024 02:05:29 -0700 Subject: [PATCH 1/3] Refactor release process --- .github/workflows/release.yml | 60 ++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1f5ff280..46248203 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,14 +1,11 @@ -# Trigger when MR to `release` is closed - -name: Build-Test-Release Code +name: Release (Manual Step) on: - pull_request: - types: - - closed - branches: - - release - + workflow_dispatch: + inputs: + name: + description: "Enter - major, minor, patch" + default: "patch" jobs: tfswitch-release: @@ -16,10 +13,19 @@ jobs: runs-on: ubuntu-20.04 steps: + - name: Check if provided input is valid + run: | + echo "Semantic Version: ${{ github.event.inputs.name }}" + VERSION=${{ github.event.inputs.name }} + if [ "$VERSION" != "major" ] || [ "$VERSION" != "minor" ] || [ "$VERSION" != "patch" ]; then + echo "Error: Provided input string must be 'major', 'minor', or 'patch'" + exit 1 + fi + # Checkout code from repo - uses: actions/checkout@v4 with: - ref: ${{ github.ref_name }} # required for better experience using pre-releases + ref: ${{ github.head_ref }} # required for better experience using pre-releases #fetch-depth: '0' # Install go @@ -42,10 +48,40 @@ jobs: run: mkdir -p build && go build -v -o build/tfswitch && build/tfswitch --help continue-on-error: false + - name: Create dry tag + uses: anothrNick/github-tag-action@1.67.0 + id: semver-tag-dry + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: false + INITIAL_VERSION: 1.0.0 + RELEASE_BRANCHES: master + DEFAULT_BUMP: ${{ github.event.inputs.name }} + PRERELEASE: false + DRY_RUN: true #only get the tag + VERBOSE: true + + # Write new version into version file + - name: Write new version tag to version file + run: | + echo ${{ steps.semver-tag-dry.outputs.tag }} > version + + - name: Commit version into repo + run: | + git config --global user.email "release-bot@users.noreply.github.com" + git config --global user.name "release-bot" + git commit -a -m "#{{ github.event.inputs.name }} - Setting semantic version" + + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} + # Introduce new tag - name: Bump version and push tag uses: anothrNick/github-tag-action@1.67.0 - id: tagging + id: semver-tag env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} WITH_V: false @@ -66,7 +102,7 @@ jobs: args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RELEASE_VERSION: ${{ steps.tagging.outputs.tag }} + RELEASE_VERSION: ${{ steps.semver-tag.outputs.tag }} PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - name: Install Python From d8e5f6a3a2b7d4ce619efb068b115cc052270d1b Mon Sep 17 00:00:00 2001 From: warrensbox Date: Tue, 2 Apr 2024 02:34:53 -0700 Subject: [PATCH 2/3] fix condition --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 46248203..26bf2b53 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: run: | echo "Semantic Version: ${{ github.event.inputs.name }}" VERSION=${{ github.event.inputs.name }} - if [ "$VERSION" != "major" ] || [ "$VERSION" != "minor" ] || [ "$VERSION" != "patch" ]; then + if [ "$VERSION" != "major" ] && [ "$VERSION" != "minor" ] && [ "$VERSION" != "patch" ]; then echo "Error: Provided input string must be 'major', 'minor', or 'patch'" exit 1 fi From 185f5727e6d9ca25082a2838b385aec391b975c5 Mon Sep 17 00:00:00 2001 From: warrensbox Date: Tue, 2 Apr 2024 02:43:39 -0700 Subject: [PATCH 3/3] update syntax --- .github/workflows/release.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 26bf2b53..49c6dc98 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,7 +26,7 @@ jobs: - uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} # required for better experience using pre-releases - #fetch-depth: '0' + fetch-depth: '0' # Install go - name: Checkout go @@ -58,7 +58,7 @@ jobs: RELEASE_BRANCHES: master DEFAULT_BUMP: ${{ github.event.inputs.name }} PRERELEASE: false - DRY_RUN: true #only get the tag + DRY_RUN: true #only get the tag - dry VERBOSE: true # Write new version into version file @@ -66,19 +66,21 @@ jobs: run: | echo ${{ steps.semver-tag-dry.outputs.tag }} > version + # Commit the changes in the previous step - name: Commit version into repo run: | git config --global user.email "release-bot@users.noreply.github.com" git config --global user.name "release-bot" git commit -a -m "#{{ github.event.inputs.name }} - Setting semantic version" + # Push the changes to remote - name: Push changes uses: ad-m/github-push-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} branch: ${{ github.ref }} - # Introduce new tag + # Introduce new tag (for real) - name: Bump version and push tag uses: anothrNick/github-tag-action@1.67.0 id: semver-tag @@ -86,13 +88,11 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} WITH_V: false INITIAL_VERSION: 1.0.0 - RELEASE_BRANCHES: release - DEFAULT_BUMP: patch + RELEASE_BRANCHES: master + DEFAULT_BUMP: ${{ github.event.inputs.name }} PRERELEASE: false - DRY_RUN: false + DRY_RUN: false #not dry VERBOSE: true - BRANCH_HISTORY: last - TAG_CONTEXT: branch # Run goreleaser to create new binaries - name: Run GoReleaser