Skip to content

Commit

Permalink
ci(goreleaser): use latest tag from GitHub action (#4094)
Browse files Browse the repository at this point in the history
Closes #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.
  • Loading branch information
rootulp authored Dec 12, 2024
1 parent d20916c commit 9c331e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- "v*"
tags:
- "v*"
release:
types: [published]
pull_request:

jobs:
Expand All @@ -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:
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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 }}
29 changes: 3 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) \
Expand All @@ -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) \
Expand Down Expand Up @@ -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

0 comments on commit 9c331e1

Please sign in to comment.