Skip to content

feat: implement phase 4 optional ORM features (#28) #11

feat: implement phase 4 optional ORM features (#28)

feat: implement phase 4 optional ORM features (#28) #11

Workflow file for this run

name: Release
on:
push:
branches:
- main
permissions:
contents: write
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Check out pushed commit
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
fetch-depth: 0
- name: Fetch tags
run: git fetch --force --tags origin
- name: Determine CalVer tag
id: calver
env:
RELEASE_COMMIT_SHA: ${{ github.sha }}
run: |
set -euo pipefail
existing_tag="$(
git tag --points-at "$RELEASE_COMMIT_SHA" |
grep -E '^v[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]+$' |
sort -V |
tail -n 1 || true
)"
if [ -n "$existing_tag" ]; then
tag="$existing_tag"
else
commit_timestamp="$(git show -s --format=%cI "$RELEASE_COMMIT_SHA")"
base="$(date -u -d "$commit_timestamp" +'%y.%m.%d')"
max_suffix=0
while IFS= read -r existing; do
suffix="${existing#v$base.}"
if ! printf '%s' "$suffix" | grep -Eq '^[0-9]+$'; then
continue
fi
if [ "$suffix" -gt "$max_suffix" ]; then
max_suffix="$suffix"
fi
done < <(git tag -l "v$base.*" | sort -V)
tag="v$base.$((max_suffix + 1))"
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
- name: Create and push tag
env:
RELEASE_COMMIT_SHA: ${{ github.sha }}
TAG: ${{ steps.calver.outputs.tag }}
run: |
set -euo pipefail
if git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null 2>&1; then
remote_refs="$(git ls-remote --tags origin "refs/tags/$TAG" "refs/tags/$TAG^{}")"
remote_sha="$(printf '%s\n' "$remote_refs" | awk '$2 ~ /\^\{\}$/ { print $1; exit }')"
if [ -z "$remote_sha" ]; then
remote_sha="$(printf '%s\n' "$remote_refs" | awk 'NF { print $1; exit }')"
fi
if [ "$remote_sha" = "$RELEASE_COMMIT_SHA" ]; then
echo "Tag $TAG already exists on origin and points to the expected commit"
exit 0
fi
echo "Error: Tag $TAG already exists on origin but points to $remote_sha instead of $RELEASE_COMMIT_SHA"
exit 1
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" "$RELEASE_COMMIT_SHA" -m "Release $TAG"
git push origin "refs/tags/$TAG"
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_COMMIT_SHA: ${{ github.sha }}
TAG: ${{ steps.calver.outputs.tag }}
run: |
set -euo pipefail
if gh release view "$TAG" >/dev/null 2>&1; then
echo "Release $TAG already exists"
exit 0
fi
gh release create "$TAG" \
--target "$RELEASE_COMMIT_SHA" \
--generate-notes \
--title "$TAG"