Skip to content

Update oxc (#123)

Update oxc (#123) #23

name: Publish Release
on:
push:
branches:
- master
paths:
- 'package.json'
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: read
jobs:
prepare:
if: github.event.repository.fork == false
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.version.outputs.should_release }}
tag: ${{ steps.version.outputs.tag }}
version: ${{ steps.version.outputs.version }}
major_tag: ${{ steps.version.outputs.major_tag }}
previous_tag: ${{ steps.version.outputs.previous_tag }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
ref: ${{ github.sha }}
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24.14.0
- name: Resolve release version
id: version
run: |
VERSION="$(node --print "require('./package.json').version")"
if ! printf '%s' "${VERSION}" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "package.json version must use x.y.z semver; received ${VERSION}."
exit 1
fi
TAG="v${VERSION}"
MAJOR_TAG="${TAG%%.*}"
PREVIOUS_TAG="$(git describe --tags --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*')"
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
echo "major_tag=${MAJOR_TAG}" >> "${GITHUB_OUTPUT}"
echo "previous_tag=${PREVIOUS_TAG}" >> "${GITHUB_OUTPUT}"
if git rev-parse "${TAG}" >/dev/null 2>&1; then
echo 'Release tag already exists. Skipping release.'
echo "should_release=false" >> "${GITHUB_OUTPUT}"
exit 0
fi
if [ -z "${PREVIOUS_TAG}" ]; then
echo 'Expected an existing previous release tag.'
exit 1
fi
PREVIOUS_VERSION="${PREVIOUS_TAG#v}"
if [ "$(printf '%s\n%s\n' "${PREVIOUS_VERSION}" "${VERSION}" | sort -V | sed -n '$p')" != "${VERSION}" ]; then
echo "package.json version ${VERSION} must be greater than the latest release tag ${PREVIOUS_TAG}."
exit 1
fi
echo "should_release=true" >> "${GITHUB_OUTPUT}"
test:
if: ${{ needs.prepare.outputs.should_release == 'true' }}
needs: prepare
uses: ./.github/workflows/test.yml
with:
ref: ${{ github.sha }}
permissions:
contents: read
build:
if: ${{ needs.prepare.outputs.should_release == 'true' }}
needs: prepare
uses: ./.github/workflows/build.yml
with:
ref: ${{ github.sha }}
verify_dist: true
permissions:
contents: read
release:
if: ${{ needs.prepare.outputs.should_release == 'true' }}
needs: [prepare, test, build]
runs-on: ubuntu-latest
permissions:
contents: write
env:
GIT_AUTHOR_NAME: github-actions[bot]
GIT_AUTHOR_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
GIT_COMMITTER_NAME: github-actions[bot]
GIT_COMMITTER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
ref: ${{ github.sha }}
- name: Create and push release tag
env:
TAG: ${{ needs.prepare.outputs.tag }}
run: |
git tag -a "${TAG}" -m "Release ${TAG}" "${GITHUB_SHA}"
git push origin "refs/tags/${TAG}"
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
PREVIOUS_TAG: ${{ needs.prepare.outputs.previous_tag }}
TAG: ${{ needs.prepare.outputs.tag }}
run: |
gh release create "${TAG}" --verify-tag --generate-notes --notes-start-tag "${PREVIOUS_TAG}"
- name: Update floating major tag
env:
MAJOR_TAG: ${{ needs.prepare.outputs.major_tag }}
RELEASE_SHA: ${{ github.sha }}
run: |
git tag -fa "${MAJOR_TAG}" -m "Release ${MAJOR_TAG}" "${RELEASE_SHA}"
git push origin "refs/tags/${MAJOR_TAG}" --force