From ea72aa1534306bd365c5850529ccbc99efa115c7 Mon Sep 17 00:00:00 2001 From: Andrii Klymiuk Date: Tue, 30 May 2023 12:51:19 +0300 Subject: [PATCH] Refactor release step --- .github/workflows/release.yml | 41 ++++++++++++++++++++++---- .github/workflows/tag.yml | 54 ----------------------------------- cmd/root.go | 2 +- 3 files changed, 37 insertions(+), 60 deletions(-) delete mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3ce70d3..c7f8f60 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,10 +1,9 @@ -name: goreleaser +name: Create release on: push: - tags: - - "*" - workflow_dispatch: + branches: + - "main" jobs: goreleaser: @@ -14,11 +13,43 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 0 + - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.19 + go-version: 1.20.3 + + - name: Get version and add it to GITHUB_ENV + run: make getActionVersion + + - name: Extract APP_VERSION and Create Tag + id: create-tag + run: | + TAG="v${VERSION}" + + echo "VERSION: ${VERSION}" + echo "TAG: $TAG" + + # Check if the tag exists + HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${GITHUB_TOKEN}" https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/$TAG) + + if [ "$HTTP_STATUS" -ne 200 ] + then + echo "Tag does not exist, creating new tag" + git config --global user.email "action@github.com" + git config --global user.name "GitHub Action" + git tag $TAG + git push origin $TAG + echo "TAG_EXISTS=false" >> $GITHUB_ENV + else + echo "Tag already exists" + echo "TAG_EXISTS=true" >> $GITHUB_ENV + fi + env: + GITHUB_TOKEN: ${{ secrets.GH_PAT }} + - name: Run GoReleaser + if: env.TAG_EXISTS == 'false' uses: goreleaser/goreleaser-action@v3 with: # either 'goreleaser' (default) or 'goreleaser-pro' diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml deleted file mode 100644 index d0dd531..0000000 --- a/.github/workflows/tag.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Create Tag - -on: - push: - branches: - - "main" - -jobs: - create-tag: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Run make getActionVersion - run: make getActionVersion - - - name: Extract APP_VERSION and Create Tag - id: create-tag - run: | - TAG="v${VERSION}" - - echo "VERSION: ${VERSION}" - echo "TAG: $TAG" - - # Check if the tag exists - HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${GITHUB_TOKEN}" https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/$TAG) - - if [ "$HTTP_STATUS" -ne 200 ] - then - echo "Tag does not exist, creating new tag" - git config --global user.email "action@github.com" - git config --global user.name "GitHub Action" - git tag $TAG - git push origin $TAG - echo "TAG_EXISTS=false" >> $GITHUB_ENV - else - echo "Tag already exists" - echo "TAG_EXISTS=true" >> $GITHUB_ENV - fi - env: - GITHUB_TOKEN: ${{ secrets.GH_PAT }} - - - name: Trigger Release workflow - if: env.TAG_EXISTS == 'false' - run: | - curl \ - -X POST \ - -H "Authorization: token ${{ secrets.GH_PAT }}" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/${{ github.repository }}/actions/workflows/release.yml/dispatches \ - -d '{"ref":"refs/tags/'"$TAG"'"}' diff --git a/cmd/root.go b/cmd/root.go index 6c5c866..8c38ff2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -var APP_VERSION = "1.1.62" +var APP_VERSION = "1.1.63" // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{