Skip to content

Release

Release #8

Workflow file for this run

name: Release
on:
workflow_run:
workflows: ["Check"]
branches: [main]
types: [completed]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
permissions: {}
jobs:
release:
name: Release
runs-on: ubuntu-latest
timeout-minutes: 10
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'main'
permissions:
contents: write
id-token: write
pull-requests: write
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.workflow_run.head_sha }}
- name: Install dependencies
uses: ./.github/actions/setup
- name: Auto changeset (patch if no changeset exists)
id: auto_changeset
if: github.actor != 'github-actions[bot]'
shell: bash
run: |
set -euo pipefail
if ls .changeset/*.md >/dev/null 2>&1; then
echo "has_changeset=true" >> "$GITHUB_OUTPUT"
exit 0
fi
CHANGESET_FILE=".changeset/auto-${{ github.sha }}.md"
printf '%s\n' \
'---' \
'"@prover-coder-ai/context-doc": patch' \
'---' \
'' \
'chore: automated version bump' \
> "$CHANGESET_FILE"
echo "has_changeset=true" >> "$GITHUB_OUTPUT"
- name: Detect npm token
id: npm_token
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]'
shell: bash
run: |
set -euo pipefail
if [ -n "${NPM_TOKEN:-}" ]; then
echo "available=true" >> "$GITHUB_OUTPUT"
else
echo "available=false" >> "$GITHUB_OUTPUT"
fi
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Version packages
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]'
run: pnpm changeset version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Read version
id: release_version
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]'
shell: bash
run: |
set -euo pipefail
VERSION="$(node -p "require('./packages/app/package.json').version")"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Commit version changes
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]'
shell: bash
run: |
set -euo pipefail
if git diff --quiet; then
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore(release): version packages"
BRANCH="${{ github.event.workflow_run.head_branch }}"
if [ -z "${BRANCH}" ]; then
BRANCH="main"
fi
git push origin "HEAD:${BRANCH}"
- name: Tag release
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]'
shell: bash
run: |
set -euo pipefail
VERSION="${{ steps.release_version.outputs.version }}"
TAG="v${VERSION}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists"
exit 0
fi
git tag -a "$TAG" -m "$TAG"
git push origin "$TAG"
- name: Configure npm auth
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]' && steps.npm_token.outputs.available == 'true'
shell: bash
run: |
set -euo pipefail
printf '%s\n' "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > "$HOME/.npmrc"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]' && steps.npm_token.outputs.available == 'true'
shell: bash
run: |
set -euo pipefail
VERSION="$(node -p "require('./packages/app/package.json').version")"
if npm view @prover-coder-ai/context-doc@"${VERSION}" version >/dev/null 2>&1; then
echo "Version ${VERSION} already published; skipping npm publish."
exit 0
fi
pnpm changeset-publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
if: steps.auto_changeset.outputs.has_changeset == 'true' && github.actor != 'github-actions[bot]'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.release_version.outputs.version }}
generate_release_notes: true