Guard against mistakes when running the release action (#6138)

Releases are run from stefanhaller's fork, but if that fork is not up to
date with jesseduffield's, bad things can happen. Guard against this by
checking that the release.yml file in both is identical.

Also take the go version to build with from the go.mod file in the
branch that is being released from, rather than hard-code it in
release.yml; this could be relevant when making a release from a 0.66.3
branch when the go version has already been bumped on master.
This commit is contained in:
Stefan Haller
2026-10-16 14:58:11 +02:00
committed by GitHub
+31 -1
View File
@@ -58,6 +58,18 @@ jobs:
token: ${{ secrets.LAZYGIT_RELEASE_PAT }}
fetch-depth: 0
- name: Check that release.yml is up to date
run: |
# This workflow runs in a fork, but releases jesseduffield/lazygit, so
# its release.yml must match the one on jesseduffield/lazygit's master.
git fetch --quiet "https://github.com/$GITHUB_REPOSITORY" "$GITHUB_WORKFLOW_SHA"
if ! git diff --quiet "$GITHUB_WORKFLOW_SHA" origin/master -- .github/workflows/release.yml; then
echo "Error: release.yml differs from the one on jesseduffield/lazygit's master."
echo "Update $GITHUB_REPOSITORY from there and run the workflow again."
exit 1
fi
- name: Get Latest Tag
run: |
latest_tag=$(git describe --tags --abbrev=0 || echo "v0.0.0")
@@ -149,6 +161,24 @@ jobs:
echo "New tag: $new_tag"
echo "new_tag=$new_tag" >> $GITHUB_ENV
- name: Get Go version
run: |
# Take the Go version from the go.mod of the code being released, so
# that a patch release from a branch off an older tag is built with
# that branch's Go version, not with master's.
#
# Turn "go 1.26.0" into "1.26.x" so that setup-go installs the latest
# patch release. With go-version-file, it would install exactly 1.26.0.
go_version=$(sed -n 's/^go \([0-9]*\.[0-9]*\).*/\1.x/p' go.mod)
if ! [[ $go_version =~ ^[0-9]+\.[0-9]+\.x$ ]]; then
echo "Error: Could not read the go version from go.mod"
exit 1
fi
echo "Go version: $go_version"
echo "go_version=$go_version" >> $GITHUB_ENV
- name: Create and Push Tag
env:
NEW_TAG: ${{ env.new_tag }}
@@ -162,7 +192,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version: 1.26.x
go-version: ${{ env.go_version }}
- name: Run goreleaser
uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7.2.3