From 9c331e16372086937ea8a523b98f59a99fa50b7c Mon Sep 17 00:00:00 2001 From: Rootul P Date: Thu, 12 Dec 2024 09:40:30 -0500 Subject: [PATCH] ci(goreleaser): use latest tag from GitHub action (#4094) Closes https://github.com/celestiaorg/celestia-app/issues/4081 ## Testing On my fork all of [these releases](https://github.com/rootulp/celestia-app/actions/workflows/ci-release.yml?query=event%3Arelease) used the correct tag and uploaded prebuilt binaries. --- .github/workflows/ci-release.yml | 3 +++ .github/workflows/goreleaser.yml | 12 ++++++++++-- Makefile | 29 +++-------------------------- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index 5fe828d636..65b50b48b2 100644 --- a/.github/workflows/ci-release.yml +++ b/.github/workflows/ci-release.yml @@ -9,6 +9,8 @@ on: - "v*" tags: - "v*" + release: + types: [published] pull_request: jobs: @@ -22,6 +24,7 @@ jobs: uses: ./.github/workflows/test.yml goreleaser: + if: github.event_name == 'release' uses: ./.github/workflows/goreleaser.yml permissions: write-all secrets: diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index dd265479e9..61a9161918 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -7,12 +7,15 @@ on: jobs: goreleaser-check: + if: github.event_name == 'release' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - run: git fetch --force --tags + - name: Set GORELEASER_CURRENT_TAG in GitHub env + run: echo "GORELEASER_CURRENT_TAG=${{ github.event.release.tag_name }}" >> $GITHUB_ENV - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' @@ -21,18 +24,21 @@ jobs: echo 'GITHUB_TOKEN=${{secrets.GORELEASER_ACCESS_TOKEN}}' >> .release-env - name: Check the .goreleaser.yaml config file run: make goreleaser-check + env: + GORELEASER_CURRENT_TAG: ${{ env.GORELEASER_CURRENT_TAG }} goreleaser: + if: github.event_name == 'release' needs: goreleaser-check runs-on: ubuntu-latest - if: | - (github.event_name == 'push' && contains(github.ref, 'refs/tags/')) permissions: write-all steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - run: git fetch --force --tags + - name: Set GORELEASER_CURRENT_TAG in GitHub env + run: echo "GORELEASER_CURRENT_TAG=${{ github.event.release.tag_name }}" >> $GITHUB_ENV - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' @@ -41,3 +47,5 @@ jobs: echo 'GITHUB_TOKEN=${{secrets.GORELEASER_ACCESS_TOKEN}}' >> .release-env - name: Create prebuilt binaries and attach them to the GitHub release run: make prebuilt-binary + env: + GORELEASER_CURRENT_TAG: ${{ env.GORELEASER_CURRENT_TAG }} diff --git a/Makefile b/Makefile index 3ebfec9bc8..7e7a511f45 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,4 @@ -# GIT_TAG is an environment variable that is set to the latest git tag on the -# current commit with the following example priority: v2.2.0, v2.2.0-mocha, -# v2.2.0-arabica, v2.2.0-rc0, v2.2.0-beta, v2.2.0-alpha. If no tag points to the -# current commit, git describe is used. The priority in this command is -# necessary because `git tag --sort=-creatordate` only works for annotated tags -# with metadata. Git tags created via GitHub releases are not annotated and do -# not have metadata like creatordate. Therefore, this command is a hacky attempt -# to get the most recent tag on the current commit according to Celestia's -# testnet versioning scheme + SemVer. -GIT_TAG := $(shell git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' \ - || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-mocha$$' \ - || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-arabica$$' \ - || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]*$$' \ - || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(beta)$$' \ - || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(alpha)$$' \ - || git describe --tags) -VERSION := $(shell echo $(GIT_TAG) | sed 's/^v//') +VERSION := $(shell echo $(shell git describe --tags 2>/dev/null || git log -1 --format='%h') | sed 's/^v//') COMMIT := $(shell git rev-parse --short HEAD) DOCKER := $(shell which docker) DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf @@ -236,7 +220,7 @@ goreleaser-check: docker run \ --rm \ --env CGO_ENABLED=1 \ - --env GORELEASER_CURRENT_TAG=${GIT_TAG} \ + --env GORELEASER_CURRENT_TAG=${GORELEASER_CURRENT_TAG} \ --env-file .release-env \ -v /var/run/docker.sock:/var/run/docker.sock \ -v `pwd`:/go/src/$(PACKAGE_NAME) \ @@ -253,7 +237,7 @@ prebuilt-binary: docker run \ --rm \ --env CGO_ENABLED=1 \ - --env GORELEASER_CURRENT_TAG=${GIT_TAG} \ + --env GORELEASER_CURRENT_TAG=${GORELEASER_CURRENT_TAG} \ --env-file .release-env \ -v /var/run/docker.sock:/var/run/docker.sock \ -v `pwd`:/go/src/$(PACKAGE_NAME) \ @@ -362,10 +346,3 @@ configure-v3: sed -i "s/ttl-num-blocks = .*/ttl-num-blocks = 12/" $(CONFIG_FILE); \ fi .PHONY: configure-v3 - - -## debug-version: Print the git tag and version. -debug-version: - @echo "GIT_TAG: $(GIT_TAG)" - @echo "VERSION: $(VERSION)" -.PHONY: debug-version