GoonCord/.github/workflows/release.yml
kmmiio99o 65ed2c7d62 Support dev prerelease tags and bump build version
Run release workflow on dev and compute numeric prerelease suffix for
tags, push annotated tags, and set prerelease output for the GH release
action. Update build metadata to include the prerelease suffix in the
version.
2025-10-18 12:36:04 +02:00

104 lines
3.2 KiB
YAML

name: Automatic Release
on:
push:
branches:
- main
- dev
workflow_dispatch:
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Extract base version
id: extract
run: |
# Extract the base (non-prerelease) version from the build-info module
version=$(grep 'const version:' src/modules.d.ts | head -n1 | sed 's/[^0-9.]//g')
echo "version=$version" >> $GITHUB_OUTPUT
shell: bash
- name: Prepare tag (detect dev branch and compute prerelease numeric suffix)
id: prepare
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
ref="${GITHUB_REF#refs/heads/}"
version="${{ steps.extract.outputs.version }}"
prerelease="false"
tag="$version"
if [ "$ref" = "dev" ]; then
prerelease="true"
# Fetch remote tags to compute the next numeric prerelease suffix
git fetch --tags --prune origin
# Get remote tags (both with and without leading 'v'), extract numeric suffixes for the current base version
max=0
while read -r remote_ref _; do
# remote_ref examples: refs/tags/1.1.4-1 or refs/tags/v1.1.4-2
remote_tag="${remote_ref#refs/tags/}"
if [[ $remote_tag =~ ^v?${version}-([0-9]+)$ ]]; then
num="${BASH_REMATCH[1]}"
if (( num > max )); then
max=$num
fi
fi
done < <(git ls-remote --tags origin)
next=$((max + 1))
tag="${version}-${next}"
fi
# Expose outputs for downstream steps
echo "tag=$tag" >> $GITHUB_OUTPUT
echo "prerelease=$prerelease" >> $GITHUB_OUTPUT
# Create an annotated tag locally and push it if it does not already exist on the remote.
# Use the token-authenticated push so this runs inside the workflow.
if ! git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then
git tag -a "${tag}" -m "Release ${tag}"
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "refs/tags/${tag}"
else
echo "Tag ${tag} already exists locally."
fi
shell: bash
- name: Build (if needed)
run: bun run build
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.prepare.outputs.tag }}
name: Release ${{ steps.prepare.outputs.tag }}
# treat pushes to dev as prereleases
prerelease: ${{ steps.prepare.outputs.prerelease }}
files: |
dist/shiggycord.js
dist/shiggycord.min.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}