diff --git a/.github/workflows/cavimg-package.yaml b/.github/workflows/cavimg-package.yaml index 846c961..8733da3 100644 --- a/.github/workflows/cavimg-package.yaml +++ b/.github/workflows/cavimg-package.yaml @@ -18,7 +18,7 @@ on: type: string default: latest dry_run: - description: "Pack/manifest check only. Does NOT test OIDC auth or contact the registry." + description: "Pack/manifest check. Does NOT test OIDC auth, and fails if the version is already published." type: boolean default: false @@ -106,7 +106,7 @@ jobs: args="--tag ${DIST_TAG} --provenance" if [ "${DRY_RUN}" = "true" ]; then args="${args} --dry-run" - echo "::warning::--dry-run only packs the tarball; it does NOT validate OIDC or trusted publisher config." + echo "::warning::--dry-run does NOT validate OIDC or trusted publisher config, and it still queries the registry — it exits 1 if this version is already published." fi case "${MODE}" in diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 84d4978..a9e4784 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,6 +8,12 @@ on: branches: - main workflow_call: + inputs: + ref: + description: "Git ref or SHA to check out. Empty means the ref that triggered the run." + type: string + required: false + default: "" permissions: contents: read @@ -26,6 +32,8 @@ jobs: steps: - uses: actions/checkout@v6 + with: + ref: ${{ inputs.ref }} - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4 with: @@ -57,6 +65,8 @@ jobs: steps: - uses: actions/checkout@v6 + with: + ref: ${{ inputs.ref }} - uses: actions/setup-go@v6 with: diff --git a/.github/workflows/dev-check.yaml b/.github/workflows/dev-check.yaml index 9460089..402a9fd 100644 --- a/.github/workflows/dev-check.yaml +++ b/.github/workflows/dev-check.yaml @@ -51,5 +51,11 @@ jobs: - name: Pack and inspect manifest working-directory: packages/cavimg run: | - echo "::notice::--dry-run packs the tarball only. It does NOT contact the registry, validate OIDC, or publish." - npm publish --dry-run --tag latest + npm pack --dry-run + + version="$(node -p "require('./package.json').version")" + if npm view "cavimg@${version}" version >/dev/null 2>&1; then + echo "::notice::cavimg@${version} is already on npmjs. Bump packages/cavimg/package.json or merging to main cuts no release." + else + echo "::notice::cavimg@${version} is not on npmjs yet — merging to main will tag and release it." + fi diff --git a/.github/workflows/release-tag.yaml b/.github/workflows/release-tag.yaml new file mode 100644 index 0000000..115ec0d --- /dev/null +++ b/.github/workflows/release-tag.yaml @@ -0,0 +1,83 @@ +name: release-tag + +on: + pull_request: + types: + - closed + branches: + - main + +permissions: + contents: read + +concurrency: + group: release-tag-${{ github.ref }} + cancel-in-progress: false + +jobs: + verify: + name: verify merged main + if: >- + github.event.pull_request.merged == true + && github.event.pull_request.head.ref == 'dev' + && github.event.pull_request.head.repo.full_name == github.repository + uses: ./.github/workflows/ci.yaml + permissions: + contents: read + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + + tag: + name: tag release + needs: verify + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - uses: actions/checkout@v6 + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + fetch-depth: 0 + + - uses: actions/setup-node@v6 + with: + node-version: "24" + package-manager-cache: false + + - name: Create tag from package version + env: + MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + version="$(node -p "require('./packages/cavimg/package.json').version")" + tag="v${version}" + + if git ls-remote --exit-code --tags origin "refs/tags/${tag}" >/dev/null 2>&1; then + echo "::notice::Tag ${tag} already exists — no release cut." + { + echo "### No release cut" + echo "" + echo "\`packages/cavimg/package.json\` is still at **${version}** and \`${tag}\` already exists." + echo "Bump the version in a PR to \`dev\` to cut the next release." + } >> "$GITHUB_STEP_SUMMARY" + exit 0 + fi + + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git tag -a "${tag}" -m "cavimg ${version} (PR #${PR_NUMBER})" "${MERGE_SHA}" + git push origin "refs/tags/${tag}" + + echo "::notice::Created tag ${tag} at ${MERGE_SHA}" + { + echo "### Tagged ${tag}" + echo "" + echo "Commit: \`${MERGE_SHA}\`" + echo "" + echo "**Publishing is not automatic.** Tags pushed by \`GITHUB_TOKEN\` do not trigger" + echo "other workflows, so \`cavimg-package.yaml\` did not fire." + echo "" + echo "To release: Actions → **cavimg-package** → Run workflow → \`mode: stage\`." + } >> "$GITHUB_STEP_SUMMARY"