Skip to content

Release

Release #165

Workflow file for this run

name: Release
on:
repository_dispatch:
types: [openapi-updated]
schedule:
- cron: '0 6 * * *'
workflow_dispatch:
inputs:
version_bump:
description: 'patch | minor | major'
required: false
default: 'patch'
version:
description: 'Exact X.Y.Z to release instead of a bump; must be greater than the last release'
required: false
default: ''
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
# An exact version is a deliberate jump the bump cannot express (0.1.x to 1.1.1).
# Refused before any build when malformed or not above the last release tag.
- name: Validate the requested version
if: inputs.version != ''
env:
EXACT_VERSION: ${{ inputs.version }}
run: |
LAST=$(git tag --list 'v*' --sort=-v:refname | head -1)
LAST=${LAST#v}
if ! [[ "$EXACT_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::version must be MAJOR.MINOR.PATCH, got $EXACT_VERSION"
exit 1
fi
if [ "$EXACT_VERSION" = "$LAST" ] || [ "$(printf '%s\n' "$LAST" "$EXACT_VERSION" | sort -V | tail -1)" != "$EXACT_VERSION" ]; then
echo "::error::version $EXACT_VERSION must be greater than the last release $LAST"
exit 1
fi
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none
- uses: actions/setup-node@v7
with:
node-version: '24'
- run: composer install --prefer-dist --no-interaction
# Also runs sync-docs.mjs, so README.md and AGENTS.md follow the spec in the same step.
- name: Regenerate from live OpenAPI
run: node scripts/generate.mjs
# Compare against the last RELEASED tag, never against the working tree.
# "Did anything change since the last commit" is the wrong question: commit a
# regeneration by hand and the next run sees a clean tree, reports success and
# silently skips every publish step below, leaving the registry behind forever.
# The tag cannot lie, because whatever is published is what that tag built.
# The spec is the only generator input, so it is the only thing worth diffing;
# a generator version bump changes the output without touching the spec and is
# released deliberately through workflow_dispatch.
- name: Is the published release built from the current spec?
id: diff
run: |
LAST=$(git describe --tags --abbrev=0 --match 'v*' 2>/dev/null || true)
if [ -z "$LAST" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
exit 0
fi
git show "$LAST:specs/openapi.json" | jq -cS . > "$RUNNER_TEMP/released-spec.json"
jq -cS . specs/openapi.json > "$RUNNER_TEMP/current-spec.json"
if cmp -s "$RUNNER_TEMP/released-spec.json" "$RUNNER_TEMP/current-spec.json"; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Lint
if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
run: vendor/bin/pint --test
- name: Static analysis
if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
run: vendor/bin/phpstan analyse --no-progress --memory-limit=512M
- name: Test
if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
run: vendor/bin/pest --no-coverage
# Packagist reads the version from the tag, so composer.json carries none. Version.php is
# regenerated from the bumped package.json, hermetically: the spec was fetched once above.
- name: Bump version
if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
id: bump
env:
ROXYAPI_SPEC_FILE: specs/openapi.json
EXACT_VERSION: ${{ inputs.version }}
run: |
BUMP="${{ github.event.inputs.version_bump || 'patch' }}"
npm version "${EXACT_VERSION:-$BUMP}" --no-git-tag-version
VERSION=$(node -p "require('./package.json').version")
node scripts/generate.mjs
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Commit, tag, push
if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
VERSION="${{ steps.bump.outputs.version }}"
git add package.json src/Version.php specs/openapi.json src/Roxy.php src/Generated README.md AGENTS.md
git commit -m "release: v$VERSION"
git tag "v$VERSION"
git push --follow-tags
- name: Create GitHub release
if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
uses: softprops/action-gh-release@v3
with:
tag_name: v${{ steps.bump.outputs.version }}
generate_release_notes: true
make_latest: 'true'
- name: No changes
if: steps.diff.outputs.changed == 'false' && github.event_name != 'workflow_dispatch'
run: echo "OpenAPI spec unchanged. Nothing to release."