From aa87c70b99b7c2dc26c5946463353315a1ba64eb Mon Sep 17 00:00:00 2001 From: Michael Henderson Date: Thu, 4 Jan 2024 10:29:27 -0800 Subject: [PATCH 1/6] Add step to write the release_version property to pkg/version/version.go AB#53302 --- .github/workflows/go-build-and-release.yml | 4 ++++ .github/workflows/starter.yml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go-build-and-release.yml b/.github/workflows/go-build-and-release.yml index 84041a6..d750055 100644 --- a/.github/workflows/go-build-and-release.yml +++ b/.github/workflows/go-build-and-release.yml @@ -40,6 +40,10 @@ jobs: echo "GO_ARGS=build --snapshot" | tee -a "$GITHUB_ENV" echo "VERSION=0.0.0" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_STEP_SUMMARY" fi + - name: Update version.go + if: github.event_name == 'pull_request' && fileExists('pkg/version/version.go') # Make this file a property in the manifest + run: | + sed -i "s/const VERSION = .*/const VERSION = \"${{ inputs.release_version }}\"/" pkg/version/version.go - name: Import GPG key uses: crazy-max/ghaction-import-gpg@v6 id: import_gpg diff --git a/.github/workflows/starter.yml b/.github/workflows/starter.yml index 7a3f61d..8b7524c 100644 --- a/.github/workflows/starter.yml +++ b/.github/workflows/starter.yml @@ -57,8 +57,8 @@ jobs: call-go-build-and-release-workflow: needs: [call-get-primary-language, call-assign-from-json-workflow, call-create-github-release-workflow] - if: needs.call-get-primary-language.outputs.primary_language == 'Go' - uses: keyfactor/actions/.github/workflows/go-build-and-release.yml@v2 + if: needs.call-get-primary-language.outputs.primary_language == 'Go' && fileExists('.goreleaser.yaml') + uses: keyfactor/actions/.github/workflows/go-build-and-release.yml@ab#53262-check-pkg-ver with: release_version: ${{ needs.call-create-github-release-workflow.outputs.release_version }} secrets: From d1755135e63619a1a7fc1d8c7d3a3ff9494a90b7 Mon Sep 17 00:00:00 2001 From: Michael Henderson Date: Fri, 5 Jan 2024 15:16:24 -0800 Subject: [PATCH 2/6] Add check for .goreleaser.yaml file using andstor/file-existence-action --- .github/workflows/starter.yml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/starter.yml b/.github/workflows/starter.yml index 8b7524c..ccdf152 100644 --- a/.github/workflows/starter.yml +++ b/.github/workflows/starter.yml @@ -40,6 +40,23 @@ jobs: run: | echo "primary_language=${{ steps.read.outputs.primary_language}}" | tee -a "$GITHUB_OUTPUT" | tee -a $GITHUB_STEP_SUMMARY + + call-goreleaser-exists: + outputs: + goreleaser-exists: ${{ steps.check_files.outputs.files_exists }} + runs-on: ubuntu-latest + name: Check for .goreleaser file + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Check file existence + id: check_files + uses: andstor/file-existence-action@v2 + with: + files: ".goreleaser.yaml" + call-create-github-release-workflow: uses: Keyfactor/actions/.github/workflows/github-release.yml@v2 @@ -56,8 +73,8 @@ jobs: token: ${{ secrets.token }} call-go-build-and-release-workflow: - needs: [call-get-primary-language, call-assign-from-json-workflow, call-create-github-release-workflow] - if: needs.call-get-primary-language.outputs.primary_language == 'Go' && fileExists('.goreleaser.yaml') + needs: [call-get-primary-language, call-assign-from-json-workflow, call-create-github-release-workflow,call-goreleaser-exists] + if: needs.call-get-primary-language.outputs.primary_language == 'Go' && needs.call-goreleaser-exists.outputs.goreleaser-exists == 'true' uses: keyfactor/actions/.github/workflows/go-build-and-release.yml@ab#53262-check-pkg-ver with: release_version: ${{ needs.call-create-github-release-workflow.outputs.release_version }} From 3e0c2b506640570122a05747632790f2b757b072 Mon Sep 17 00:00:00 2001 From: Michael Henderson Date: Fri, 5 Jan 2024 15:35:21 -0800 Subject: [PATCH 3/6] Check for version.go file using andstor/file-existence-action --- .github/workflows/go-build-and-release.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go-build-and-release.yml b/.github/workflows/go-build-and-release.yml index d750055..6008f9f 100644 --- a/.github/workflows/go-build-and-release.yml +++ b/.github/workflows/go-build-and-release.yml @@ -20,7 +20,24 @@ on: required: true jobs: + call-version-file-exists: + outputs: + version-file-exists: ${{ steps.check_files.outputs.files_exists }} + runs-on: ubuntu-latest + name: Check for version.go file + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Check file existence + id: check_files + uses: andstor/file-existence-action@v2 + with: + files: "pkg/version/version.go" # Make this file a property in the manifest and input to the workflow + run-goreleaser: + needs: call-version-file-exists runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -41,7 +58,7 @@ jobs: echo "VERSION=0.0.0" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_STEP_SUMMARY" fi - name: Update version.go - if: github.event_name == 'pull_request' && fileExists('pkg/version/version.go') # Make this file a property in the manifest + if: github.event_name == 'pull_request' && needs.call-goreleaser-exists.outputs.version-file-exists == 'true' run: | sed -i "s/const VERSION = .*/const VERSION = \"${{ inputs.release_version }}\"/" pkg/version/version.go - name: Import GPG key From c9579707b4c1412ad07e33c35a1cffed966604fe Mon Sep 17 00:00:00 2001 From: Michael Henderson Date: Fri, 5 Jan 2024 16:18:32 -0800 Subject: [PATCH 4/6] use wildcard match for y*ml --- .github/workflows/starter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/starter.yml b/.github/workflows/starter.yml index ccdf152..028b904 100644 --- a/.github/workflows/starter.yml +++ b/.github/workflows/starter.yml @@ -55,7 +55,7 @@ jobs: id: check_files uses: andstor/file-existence-action@v2 with: - files: ".goreleaser.yaml" + files: ".goreleaser.y*ml" call-create-github-release-workflow: uses: Keyfactor/actions/.github/workflows/github-release.yml@v2 From 4b5ea22fcdadee5ab8aed4a9119348c983dae851 Mon Sep 17 00:00:00 2001 From: Michael Henderson Date: Fri, 5 Jan 2024 16:31:18 -0800 Subject: [PATCH 5/6] move check_files step to existing run-goreleaser job --- .github/workflows/go-build-and-release.yml | 23 ++++++---------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/.github/workflows/go-build-and-release.yml b/.github/workflows/go-build-and-release.yml index 6008f9f..14b0d77 100644 --- a/.github/workflows/go-build-and-release.yml +++ b/.github/workflows/go-build-and-release.yml @@ -20,22 +20,6 @@ on: required: true jobs: - call-version-file-exists: - outputs: - version-file-exists: ${{ steps.check_files.outputs.files_exists }} - runs-on: ubuntu-latest - name: Check for version.go file - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - name: Check file existence - id: check_files - uses: andstor/file-existence-action@v2 - with: - files: "pkg/version/version.go" # Make this file a property in the manifest and input to the workflow - run-goreleaser: needs: call-version-file-exists runs-on: ubuntu-latest @@ -44,6 +28,11 @@ jobs: with: # Allow goreleaser to access older tag information. fetch-depth: 0 + - name: Check file existence + id: check_files + uses: andstor/file-existence-action@v2 + with: + files: "pkg/version/version.go" # Make this file a property in the manifest and input to the workflow - uses: actions/setup-go@v4 with: go-version-file: 'go.mod' @@ -58,7 +47,7 @@ jobs: echo "VERSION=0.0.0" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_STEP_SUMMARY" fi - name: Update version.go - if: github.event_name == 'pull_request' && needs.call-goreleaser-exists.outputs.version-file-exists == 'true' + if: github.event_name == 'pull_request' && steps.check_files.outputs.files_exists == 'true' run: | sed -i "s/const VERSION = .*/const VERSION = \"${{ inputs.release_version }}\"/" pkg/version/version.go - name: Import GPG key From 2e85781d4ef62ff215476880d1213d0464b4fea0 Mon Sep 17 00:00:00 2001 From: Michael Henderson Date: Fri, 5 Jan 2024 16:33:54 -0800 Subject: [PATCH 6/6] remove needs --- .github/workflows/go-build-and-release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/go-build-and-release.yml b/.github/workflows/go-build-and-release.yml index 14b0d77..adb297e 100644 --- a/.github/workflows/go-build-and-release.yml +++ b/.github/workflows/go-build-and-release.yml @@ -21,7 +21,6 @@ on: jobs: run-goreleaser: - needs: call-version-file-exists runs-on: ubuntu-latest steps: - uses: actions/checkout@v3