fix: Release workflow ⚓ #137
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: goreleaser | |
on: | |
push: | |
tags: | |
# This is not a real version tag, its just used to trigger | |
# the release build. Glob pattern: | |
- "prepare-v[0-9]+.[0-9]+.[0-9]+*" | |
jobs: | |
goreleaser: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: "1.20" | |
- name: Import GPG Key | |
id: import_gpg | |
uses: crazy-max/ghaction-import-gpg@v3 | |
with: | |
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
- name: Store Git Tag | |
id: "getTag" | |
run: | | |
echo ::set-output name=releaseTag::$(echo "${GITHUB_REF##*prepare-}") | |
echo ::set-output name=triggerTag::$(echo "${GITHUB_REF##*/}") | |
- name: "Tag release commit" | |
env: | |
RELEASE_TAG: ${{ steps.getTag.outputs.releaseTag }} | |
TRIGGER_TAG: ${{ steps.getTag.outputs.triggerTag }} | |
run: | | |
git config user.name 'githooks-bot' | |
git config user.email '[email protected]' | |
[ "$(git cat-file -t "$TRIGGER_TAG")" = "tag" ] || { | |
echo "Tag '$TRIGGER_TAG' is not an annotated tag." | |
git cat-file -t "$TRIGGER_TAG" | |
git --version | |
exit 1 | |
} | |
# Gets the message on the annotated commit: | |
deref() { git for-each-ref "refs/tags/$TRIGGER_TAG" --format="%($1)" ; }; | |
# Creates a new tag with the same message, including trailing headers. | |
git tag -a -m "$(deref contents)" "$RELEASE_TAG" | |
git tag "githooks/$RELEASE_TAG" | |
- name: Define Release Branch | |
id: releaseBranch | |
env: | |
RELEASE_TAG: ${{ steps.getTag.outputs.releaseTag }} | |
run: | | |
# If we specify another branch we are checking this one, | |
RELEASE_BRANCH="main" | |
RELEASE_VERSION="${RELEASE_TAG##v}" | |
echo "Get release branch on tag '$RELEASE_TAG'." | |
# Gets the message on the annotated commit: | |
deref() { | |
git for-each-ref "refs/tags/$RELEASE_TAG" --format="%($1)" ; | |
}; | |
git show -s --format="" $RELEASE_TAG | |
deref contents | |
regex="^Release-Branch:\s+(.*)$" | |
if deref contents | grep -qE "$regex"; then | |
RELEASE_BRANCH=$(deref contents | grep -E "$regex" | | |
sed -E "s/$regex/\1/") || { | |
echo "Release-Branch trailer is wrong." | |
exit 1 | |
} | |
[ -n "$RELEASE_BRANCH" ] || { | |
echo "Release-Branch trailer is empty." | |
exit 1 | |
} | |
fi | |
# Fetch the branch. | |
git fetch --depth 50 origin "$RELEASE_BRANCH" | |
# Check if its reachable. | |
[ -n "$(git rev-list --first-parent \ | |
--ancestry-path \ | |
"$RELEASE_TAG^..origin/$RELEASE_BRANCH")" ] || { | |
echo "Tag is not reachable from '$RELEASE_BRANCH' (--first-parent) !" >&2 | |
exit 1 | |
} | |
echo ::set-output name=releaseVersion ::$RELEASE_VERSION | |
echo ::set-output name=releaseBranch ::$RELEASE_BRANCH | |
- name: Run GoReleaser | |
uses: goreleaser/goreleaser-action@v2 | |
with: | |
version: latest | |
workdir: githooks | |
args: release --clean | |
env: | |
GORELEASER_CURRENT_TAG: ${{ steps.getTag.outputs.releaseTag }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} | |
- name: "Push release tags and delete trigger tag" | |
env: | |
RELEASE_TAG: ${{ steps.getTag.outputs.releaseTag }} | |
TRIGGER_TAG: ${{ steps.getTag.outputs.triggerTag }} | |
run: | | |
# go releaser already pushed release tag | |
git push origin "githooks/$RELEASE_TAG" | |
git push -f origin ":$TRIGGER_TAG" |