Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(goreleaser): use latest tag from GitHub action #4094

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
rootulp marked this conversation as resolved.
Show resolved Hide resolved
- 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 @@ -220,7 +204,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 @@ -238,7 +222,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 @@ -331,10 +315,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
Loading