Skip to content

Release v7.2.1

Release v7.2.1 #27

Workflow file for this run

name: Release
on:
workflow_dispatch:
push:
branches:
- main
paths:
- package.json
permissions:
contents: write
jobs:
tag:
name: Build declaration snapshot and tag
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Resolve version tag
id: version
run: |
set -euo pipefail
VERSION="$(bun -e 'const pkg = await Bun.file("package.json").json(); console.log(pkg.version)')"
TAG="v$VERSION"
export VERSION
if ! bun -e 'import { semver } from "bun"; process.exit(semver.satisfies(Bun.env.VERSION!, Bun.env.VERSION!) ? 0 : 1)' ; then
echo "Invalid package.json version: $VERSION"
exit 1
fi
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag already exists: $TAG"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "released=false" >> "$GITHUB_OUTPUT"
exit 0
fi
LATEST_TAG="$(
git tag --list 'v[0-9]*.[0-9]*.[0-9]*' |
bun -e 'import { semver } from "bun"; const tags = await Bun.stdin.text(); const versions = tags.trim().split(/\s+/).filter(Boolean).map((tag) => tag.slice(1)); versions.sort(semver.order); console.log(versions.at(-1) ?? "")'
)"
export LATEST_TAG
if [[ -n "$LATEST_TAG" ]] && ! bun -e 'import { semver } from "bun"; process.exit(semver.order(Bun.env.VERSION!, Bun.env.LATEST_TAG!) === 1 ? 0 : 1)' ; then
echo "package.json version $VERSION must be greater than latest tag v$LATEST_TAG"
exit 1
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "released=true" >> "$GITHUB_OUTPUT"
- name: Install dependencies
if: steps.version.outputs.released == 'true'
run: bun install --frozen-lockfile
- name: Check source
if: steps.version.outputs.released == 'true'
run: bun run check
- name: Build declarations
if: steps.version.outputs.released == 'true'
run: |
rm -rf dist
bun run build
test -f dist/index.d.ts
test -f dist/terminal.d.ts
- name: Prune release snapshot
if: steps.version.outputs.released == 'true'
run: |
set -euo pipefail
RELEASE_DIST="$RUNNER_TEMP/argc-release-dist"
rm -rf "$RELEASE_DIST"
cp -R dist "$RELEASE_DIST"
git rm -r -- .
rm -rf dist
# package.json exports runtime TS sources; the release tag only drops tests/tooling/docs.
git checkout HEAD -- package.json README.md src
find src -name '*.test.ts' -delete
cp -R "$RELEASE_DIST" dist
- name: Create release snapshot tag
if: steps.version.outputs.released == 'true'
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A package.json README.md src
git add -f dist
git commit -m "release: $TAG declarations"
git tag -a "$TAG" -m "$TAG"
git push origin "refs/tags/$TAG"
env:
TAG: ${{ steps.version.outputs.tag }}