-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update release workflow with version file ⚓
- Loading branch information
Showing
6 changed files
with
171 additions
and
74 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,18 +42,48 @@ jobs: | |
git config user.name 'githooks-bot' | ||
git config user.email '[email protected]' | ||
# 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 "$RELEASE_TAG" -a -m "$(deref contents)" | ||
git tag "githooks/$RELEASE_TAG" | ||
- name: Safety Check | ||
- name: Define Release Branch | ||
id: releaseBranch | ||
env: | ||
RELEASE_TAG: ${{ steps.getTag.outputs.releaseTag }} | ||
run: | | ||
git fetch --depth 50 origin main | ||
[ -n "$(git rev-list --first-parent --ancestry-path "$RELEASE_TAG^..origin/main")" ] || { | ||
echo "Tag is not reachable from main (--first-parent) !" >&2 | ||
# If we specify another branch we are checking this one, | ||
RELEASE_BRANCH="main" | ||
RELEASE_VERSION="${RELEASE_TAG##v}" | ||
regex="^Release-Branch:\s+(.*)$" | ||
# Gets the message on the annotated commit: | ||
deref() { | ||
git for-each-ref "refs/tags/$RELEASE_TAG" --format="%($1)" ; | ||
}; | ||
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 | ||
} | ||
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: | ||
|
@@ -72,4 +102,5 @@ jobs: | |
run: | | ||
# go releaser already pushed release tag | ||
git push origin "githooks/$RELEASE_TAG" | ||
git push -f origin ":$TRIGGER_TAG" |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "version": "3.0.0" } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
/nix/store/195rgxnkqvq8lk03rq8nibz53zpzsx4f-githooks-cli-3.0.0 | ||
/nix/store/mis2msnw1jd2pchad5j23jmzpzihi4kx-githooks-3.0.0+nix.96c86715a221cb2238981c05661f07dfeccb6b90-dirty |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,90 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Creating a prepare tag to trigger the release process on the | ||
# Github workflow. | ||
# You can set the following meaning full | ||
# Git trailers on the annotated tag: | ||
# `Update-Info: ...` : One line of update info to be given to the user when updating. | ||
# `Update-NoSkip: true` : Specifying that this version update cannot be skipped. | ||
# `Release-Branch: .*`: Specifying another branch than main. | ||
# Useful for testing stuff which does not affect the user, since | ||
# it must be on this branch to get this update. | ||
# This branch will be checked to contain the tag. | ||
|
||
set -euo pipefail | ||
|
||
readarray -t prepareTag < <(git tag --list "prepare-*") | ||
ROOT_DIR=$(git rev-parse --show-toplevel) | ||
cd "$ROOT_DIR" | ||
|
||
for tag in "${prepareTag[@]}"; do | ||
echo "Deleting prepare tag '$tag'." | ||
git push -f origin ":${tag}" || true | ||
git tag -d "$tag" | ||
done | ||
function delete_prepare_tags() { | ||
readarray -t prepareTag < <(git tag --list "prepare-*") | ||
|
||
version="$1" | ||
tag="v$version" | ||
if git tag --list "v*" | grep -q "$tag"; then | ||
echo "Git tag '$tag' already exists." | ||
fi | ||
for tag in "${prepareTag[@]}"; do | ||
echo "Deleting prepare tag '$tag'." | ||
git push -f origin ":${tag}" || true | ||
git tag -d "$tag" | ||
done | ||
} | ||
|
||
function commit_version_file() { | ||
local version="$1" | ||
echo "Writing new version file..." | ||
|
||
temp=$(mktemp) | ||
jq ".version |= \"$version\"" nix/pkgs/version.json >"$temp" | ||
mv "$temp" nix/pkgs/version.json | ||
|
||
if git diff --quiet --exit-code; then | ||
git add nix/pkgs/version.json | ||
git commit -m "np: Update version to '$version'" | ||
fi | ||
} | ||
|
||
function create_tag() { | ||
tag="v$version" | ||
if git tag --list "v*" | grep -q "$tag"; then | ||
echo "Git tag '$tag' already exists." | ||
exit 1 | ||
fi | ||
|
||
add_message=() | ||
if [ -n "$update_info" ]; then | ||
add_message+=(-m "Update-Info: $update_info") | ||
fi | ||
|
||
if [ "$branch" != "main" ]; then | ||
add_message+=(-m "Release-Branch: $branch") | ||
fi | ||
|
||
echo "Tagging..." | ||
git tag -a -m "Version $tag" "${add_message[@]}" "prepare-$tag" | ||
|
||
echo "Tag contains:" | ||
git cat-file -p "prepare-$tag" | ||
} | ||
|
||
function trigger_build() { | ||
printf "Do you want to trigger the build? [y|n]: " | ||
read -r answer | ||
if [ "$answer" != "y" ]; then | ||
echo "Do not trigger build -> abort." | ||
exit 0 | ||
fi | ||
|
||
echo "Pushing tag 'prepare-$tag'." | ||
git push -f origin --no-follow-tags "$branch" "prepare-$tag" | ||
} | ||
|
||
version="$1" | ||
update_info="${2:-}" | ||
branch=$(git branch --show-current) | ||
|
||
if [ -z "$update_info" ]; then | ||
git tag "prepare-$tag" | ||
else | ||
git tag -a -m "Version $tag" -m "Update-Info: $update_info" "prepare-$tag" | ||
if ! git diff --quiet --exit-code; then | ||
echo "You have changes on this branch." | ||
exit 1 | ||
fi | ||
|
||
echo "Pushing tag 'prepare-$tag'." | ||
git push -f origin "prepare-$tag" | ||
delete_prepare_tags | ||
commit_version_file "$version" | ||
create_tag | ||
trigger_build |