mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-18 11:32:15 -05:00
Bumps the github-actions group with 14 updates in the / directory: | Package | From | To | | --- | --- | --- | | [actions/checkout](https://github.com/actions/checkout) | `6.0.3` | `7.0.1` | | [pnpm/action-setup](https://github.com/pnpm/action-setup) | `6.0.8` | `6.1.0` | | [actions/setup-node](https://github.com/actions/setup-node) | `6.4.0` | `7.1.0` | | [actions/labeler](https://github.com/actions/labeler) | `6.1.0` | `7.0.0` | | [korthout/backport-action](https://github.com/korthout/backport-action) | `4.5.2` | `4.7.0` | | [actions/cache](https://github.com/actions/cache) | `5.0.5` | `6.1.0` | | [re-actors/alls-green](https://github.com/re-actors/alls-green) | `1.2.2` | `1.3.0` | | [anthropics/claude-code-action](https://github.com/anthropics/claude-code-action) | `1.0.142` | `1.0.248` | | [denoland/setup-deno](https://github.com/denoland/setup-deno) | `2.0.4` | `2.0.5` | | [actions/upload-artifact](https://github.com/actions/upload-artifact) | `4.6.2` | `7.0.2` | | [actions/download-artifact](https://github.com/actions/download-artifact) | `8.0.1` | `8.0.2` | | [changesets/action](https://github.com/changesets/action) | `1.9.0` | `2.1.2` | | [marocchino/sticky-pull-request-comment](https://github.com/marocchino/sticky-pull-request-comment) | `3.0.4` | `3.0.5` | | [zizmorcore/zizmor-action](https://github.com/zizmorcore/zizmor-action) | `0.5.6` | `0.6.4` | Updates `actions/checkout` from 6.0.3 to 7.0.1 - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/df4cb1c069e1874edd31b4311f1884172cec0e10...3d3c42e5aac5ba805825da76410c181273ba90b1) Updates `pnpm/action-setup` from 6.0.8 to 6.1.0 - [Release notes](https://github.com/pnpm/action-setup/releases) - [Commits](https://github.com/pnpm/action-setup/compare/0e279bb959325dab635dd2c09392533439d90093...ea17c68df8912ef543352723c149a84f56e3d413) Updates `actions/setup-node` from 6.4.0 to 7.1.0 - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e...949feb2413d6458794dcd2491c4babbbce0c15c1) Updates `actions/labeler` from 6.1.0 to 7.0.0 - [Release notes](https://github.com/actions/labeler/releases) - [Commits](https://github.com/actions/labeler/compare/f27b608878404679385c85cfa523b85ccb86e213...bf12e9b00b37c5c0ca2b87b79b2daf7891dbda13) Updates `korthout/backport-action` from 4.5.2 to 4.7.0 - [Release notes](https://github.com/korthout/backport-action/releases) - [Commits](https://github.com/korthout/backport-action/compare/66065406958f46e82238fd59546f5a99e69e22aa...8560fb503c275d433c56f05a2f64850093baa9f7) Updates `actions/cache` from 5.0.5 to 6.1.0 - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/27d5ce7f107fe9357f9df03efb73ab90386fccae...55cc8345863c7cc4c66a329aec7e433d2d1c52a9) Updates `re-actors/alls-green` from 1.2.2 to 1.3.0 - [Release notes](https://github.com/re-actors/alls-green/releases) - [Commits](https://github.com/re-actors/alls-green/compare/05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe...b5b5b37504aa4183270bd3d855c52a67f212be35) Updates `anthropics/claude-code-action` from 1.0.142 to 1.0.248 - [Release notes](https://github.com/anthropics/claude-code-action/releases) - [Commits](https://github.com/anthropics/claude-code-action/compare/11ba60486e4aec9ddfeafcf4bb3f00b028ac2c16...1d6de8cb0c237e7c15e9e1bdf973826ebae490cc) Updates `denoland/setup-deno` from 2.0.4 to 2.0.5 - [Release notes](https://github.com/denoland/setup-deno/releases) - [Commits](https://github.com/denoland/setup-deno/compare/667a34cdef165d8d2b2e98dde39547c9daac7282...22d081ff2d3a40755e97629de92e3bcbfa7cf2ed) Updates `actions/upload-artifact` from 4.6.2 to 7.0.2 - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4.6.2...cf430e030ddbb5b0abf93d22962f4752f3646cd9) Updates `actions/download-artifact` from 8.0.1 to 8.0.2 - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c...9000827ccba6bdab643e8b6fd33ac0654aef8333) Updates `changesets/action` from 1.9.0 to 2.1.2 - [Release notes](https://github.com/changesets/action/releases) - [Changelog](https://github.com/changesets/action/blob/main/CHANGELOG.md) - [Commits](https://github.com/changesets/action/compare/a45c4d594aa4e2c509dc14a9f2b3b67ba3780d0d...ae32849d5ba541f9ae29e40e22a623bc13562f51) Updates `marocchino/sticky-pull-request-comment` from 3.0.4 to 3.0.5 - [Release notes](https://github.com/marocchino/sticky-pull-request-comment/releases) - [Commits](https://github.com/marocchino/sticky-pull-request-comment/compare/0ea0beb66eb9baf113663a64ec522f60e49231c0...5770ad5eb8f42dd2c4f34da00c94c5381e49af88) Updates `zizmorcore/zizmor-action` from 0.5.6 to 0.6.4 - [Release notes](https://github.com/zizmorcore/zizmor-action/releases) - [Commits](https://github.com/zizmorcore/zizmor-action/compare/5f14fd08f7cf1cb1609c1e344975f152c7ee938d...cc914d7f3750a2d13d75c7f184a1060aa0e9d482) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: 7.0.1 dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: pnpm/action-setup dependency-version: 6.1.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions - dependency-name: actions/setup-node dependency-version: 7.1.0 dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: actions/labeler dependency-version: 7.0.0 dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: korthout/backport-action dependency-version: 4.7.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions - dependency-name: actions/cache dependency-version: 6.1.0 dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: re-actors/alls-green dependency-version: 1.3.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions - dependency-name: anthropics/claude-code-action dependency-version: 1.0.248 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-actions - dependency-name: denoland/setup-deno dependency-version: 2.0.5 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-actions - dependency-name: actions/upload-artifact dependency-version: 7.0.2 dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: actions/download-artifact dependency-version: 8.0.2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-actions - dependency-name: changesets/action dependency-version: 2.1.2 dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: marocchino/sticky-pull-request-comment dependency-version: 3.0.5 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-actions - dependency-name: zizmorcore/zizmor-action dependency-version: 0.6.4 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions ... Signed-off-by: dependabot[bot] <support@github.com>
335 lines
15 KiB
YAML
335 lines
15 KiB
YAML
name: Auto Changeset
|
|
|
|
on:
|
|
issue_comment:
|
|
types: [created, edited]
|
|
|
|
permissions: {}
|
|
|
|
concurrency:
|
|
group: auto-changeset-${{ github.event.issue.number }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
# /changeset slash command — maintainers only.
|
|
# Uses issue_comment which runs base-branch YAML with full secrets,
|
|
# making it safe for both team and fork PRs.
|
|
changeset:
|
|
if: >
|
|
github.event.action == 'created' &&
|
|
github.event.issue.pull_request &&
|
|
startsWith(github.event.comment.body, '/changeset') &&
|
|
github.repository_owner == 'better-auth' &&
|
|
contains(fromJSON('["MEMBER", "OWNER", "COLLABORATOR"]'), github.event.comment.author_association)
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
permissions:
|
|
contents: read
|
|
issues: write
|
|
pull-requests: read
|
|
steps:
|
|
- name: Generate App Token
|
|
id: app-token
|
|
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
|
|
if: vars.RELEASE_APP_ID != ''
|
|
with:
|
|
app-id: ${{ vars.RELEASE_APP_ID }}
|
|
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
|
|
permission-contents: read
|
|
permission-issues: write
|
|
permission-pull-requests: read
|
|
|
|
- name: React to comment
|
|
env:
|
|
GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
|
|
COMMENT_ID: ${{ github.event.comment.id }}
|
|
run: |
|
|
gh api "repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}/reactions" \
|
|
-f content='+1' --silent || true
|
|
|
|
# issue_comment resolves to the default branch SHA. Never execute PR or
|
|
# fork code with secrets.
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
ref: ${{ github.sha }}
|
|
fetch-depth: 0
|
|
persist-credentials: false
|
|
token: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
|
|
|
|
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
|
|
|
|
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
|
with:
|
|
node-version-file: '.nvmrc'
|
|
cache: pnpm
|
|
|
|
- name: Install release tooling
|
|
run: pnpm install --frozen-lockfile --filter @better-auth/release-tooling
|
|
|
|
- name: Analyze PR
|
|
id: analyze
|
|
env:
|
|
GITHUB_TOKEN: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
|
|
AI_GATEWAY_API_KEY: ${{ secrets.AI_GATEWAY_API_KEY }}
|
|
PR_NUMBER: ${{ github.event.issue.number }}
|
|
FORCE: 'true'
|
|
run: pnpm --filter @better-auth/release-tooling auto-changeset
|
|
|
|
- name: Clean up previous bot comments
|
|
env:
|
|
GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.issue.number }}
|
|
run: |
|
|
MARKER="<!-- auto-changeset -->"
|
|
gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --paginate \
|
|
--jq ".[] | select((.body | startswith(\"${MARKER}\")) and (.user.login == \"better-release[bot]\" or .user.login == \"github-actions[bot]\")) | .id" \
|
|
| xargs -r -I{} gh api -X DELETE "repos/${GITHUB_REPOSITORY}/issues/comments/{}" 2>/dev/null || true
|
|
|
|
- name: Post skip explanation
|
|
if: steps.analyze.outputs.skip == 'true'
|
|
env:
|
|
GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.issue.number }}
|
|
SKIP_REASON: ${{ steps.analyze.outputs.skip_reason }}
|
|
run: |
|
|
gh api --method POST "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
|
|
-f body="<!-- auto-changeset -->
|
|
**No changeset generated:** ${SKIP_REASON}" >/dev/null
|
|
|
|
- name: Post changeset comment
|
|
if: steps.analyze.outputs.skip != 'true'
|
|
env:
|
|
GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.issue.number }}
|
|
FRONTMATTER: ${{ steps.analyze.outputs.frontmatter }}
|
|
DESCRIPTION: ${{ steps.analyze.outputs.description }}
|
|
HAS_EXISTING: ${{ steps.analyze.outputs.has_existing }}
|
|
run: |
|
|
CHANGESET=$(printf '%s\n' "---" "$FRONTMATTER" "---" "" "$DESCRIPTION")
|
|
|
|
EXISTING_NOTE=""
|
|
if [ "$HAS_EXISTING" = "true" ]; then
|
|
EXISTING_NOTE="
|
|
> **Note:** This PR already has a changeset. The recommendation below is an alternative you can use to replace it.
|
|
"
|
|
fi
|
|
|
|
TMPFILE=$(mktemp)
|
|
printf '%s\n' "<!-- auto-changeset -->" \
|
|
"### Changeset recommendation" "" \
|
|
"${EXISTING_NOTE}" \
|
|
"Copy into \`.changeset/pr-${PR_NUMBER}.md\`:" "" \
|
|
'```md' "$CHANGESET" '```' "" \
|
|
"---" "" \
|
|
"- [ ] **Commit this changeset** to the PR" > "$TMPFILE"
|
|
|
|
gh api --method POST "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
|
|
-f body="$(cat "$TMPFILE")" >/dev/null
|
|
rm -f "$TMPFILE"
|
|
echo "Posted changeset recommendation on PR #${PR_NUMBER}"
|
|
|
|
# Apply changeset — triggered when someone checks the commit checkbox
|
|
# on a bot-posted changeset recommendation comment.
|
|
apply:
|
|
if: >
|
|
github.event.action == 'edited' &&
|
|
github.event.issue.pull_request &&
|
|
contains(github.event.comment.body, '<!-- auto-changeset -->') &&
|
|
contains(github.event.comment.body, '- [x] **Commit this changeset**') &&
|
|
(github.event.comment.user.login == 'better-release[bot]' || github.event.comment.user.login == 'github-actions[bot]') &&
|
|
github.repository_owner == 'better-auth'
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 5
|
|
permissions:
|
|
contents: write
|
|
issues: write
|
|
pull-requests: read
|
|
steps:
|
|
- name: Generate App Token
|
|
id: app-token
|
|
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
|
|
if: vars.RELEASE_APP_ID != ''
|
|
with:
|
|
app-id: ${{ vars.RELEASE_APP_ID }}
|
|
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
|
|
permission-contents: write
|
|
permission-issues: write
|
|
permission-pull-requests: read
|
|
|
|
- name: Verify sender authorization
|
|
id: auth
|
|
env:
|
|
GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
|
|
SENDER: ${{ github.event.sender.login }}
|
|
PR_NUMBER: ${{ github.event.issue.number }}
|
|
run: |
|
|
# Match the /changeset command's MEMBER/OWNER/COLLABORATOR gate.
|
|
# author_association is role-based (not permission-based), so we
|
|
# check repo collaborator status and org membership separately.
|
|
if gh api "repos/${GITHUB_REPOSITORY}/collaborators/${SENDER}" --silent 2>/dev/null; then
|
|
echo "authorized=true" >> "$GITHUB_OUTPUT"
|
|
elif gh api "orgs/${GITHUB_REPOSITORY_OWNER}/members/${SENDER}" --silent 2>/dev/null; then
|
|
echo "authorized=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
PR_AUTHOR=$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" \
|
|
--json author --jq '.author.login' 2>/dev/null || echo "")
|
|
if [[ -n "$PR_AUTHOR" && "$SENDER" == "$PR_AUTHOR" ]]; then
|
|
echo "authorized=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "::warning::${SENDER} is not authorized"
|
|
echo "authorized=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
fi
|
|
|
|
- name: Get PR details
|
|
if: steps.auth.outputs.authorized == 'true'
|
|
id: pr
|
|
env:
|
|
GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.issue.number }}
|
|
run: |
|
|
PR_JSON=$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" \
|
|
--json headRefName,isCrossRepository)
|
|
HEAD_REF=$(echo "$PR_JSON" | jq -r '.headRefName')
|
|
IS_FORK=$(echo "$PR_JSON" | jq -r '.isCrossRepository')
|
|
echo "head_ref=$HEAD_REF" >> "$GITHUB_OUTPUT"
|
|
|
|
# The ref is later interpolated into REST API paths
|
|
# (git/ref/heads/${HEAD_REF}). URI-reserved characters such as '#' or
|
|
# '%' can pass the protected-branch string checks below but resolve to
|
|
# a DIFFERENT ref once placed in a URL ('#' truncates as a fragment,
|
|
# '%2F' decodes to '/'). Reject anything outside a conservative
|
|
# branch-name allowlist so the guards operate on the literal ref.
|
|
if [[ ! "$HEAD_REF" =~ ^[A-Za-z0-9._/-]+$ ]]; then
|
|
echo "blocked=true" >> "$GITHUB_OUTPUT"
|
|
echo "blocked_reason=Refusing to commit to branch with unsupported characters (${HEAD_REF}) — only letters, digits, '.', '_', '/', and '-' are allowed." >> "$GITHUB_OUTPUT"
|
|
elif [[ "$HEAD_REF" == "main" || "$HEAD_REF" == "next" || "$HEAD_REF" == v*.*.x ]]; then
|
|
echo "blocked=true" >> "$GITHUB_OUTPUT"
|
|
echo "blocked_reason=Cannot commit to protected branch (${HEAD_REF}) — this would trigger release automation." >> "$GITHUB_OUTPUT"
|
|
elif [[ "$IS_FORK" == "true" ]]; then
|
|
echo "blocked=true" >> "$GITHUB_OUTPUT"
|
|
echo "blocked_reason=Cannot auto-commit to fork PRs — please copy the changeset manually." >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "blocked=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Abort if blocked
|
|
if: steps.auth.outputs.authorized == 'true' && steps.pr.outputs.blocked == 'true'
|
|
env:
|
|
GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
|
|
COMMENT_ID: ${{ github.event.comment.id }}
|
|
BLOCKED_REASON: ${{ steps.pr.outputs.blocked_reason }}
|
|
run: |
|
|
BODY=$(gh api "repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" --jq '.body')
|
|
TMPFILE=$(mktemp)
|
|
awk -v reason="$BLOCKED_REASON" '{
|
|
sub(/- \[x\] \*\*Commit this changeset\*\* to the PR/,
|
|
"- [ ] **Commit this changeset** to the PR\n\n> ⚠️ " reason)
|
|
print
|
|
}' <<< "$BODY" > "$TMPFILE"
|
|
gh api "repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" \
|
|
-X PATCH --input <(jq -n --rawfile body "$TMPFILE" '{body: $body}')
|
|
rm -f "$TMPFILE"
|
|
echo "::warning::${BLOCKED_REASON}"
|
|
|
|
- name: Commit changeset
|
|
if: steps.auth.outputs.authorized == 'true' && steps.pr.outputs.blocked != 'true'
|
|
env:
|
|
GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.issue.number }}
|
|
COMMENT_ID: ${{ github.event.comment.id }}
|
|
HEAD_REF: ${{ steps.pr.outputs.head_ref }}
|
|
SENDER: ${{ github.event.sender.login }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
# Fetch comment body via API (safer than env var for special characters)
|
|
BODY=$(gh api "repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" --jq '.body')
|
|
|
|
# Extract changeset from the ```md code block
|
|
CHANGESET=$(awk '/^```md$/{found=1;next} found && /^```$/{exit} found{print}' <<< "$BODY")
|
|
|
|
if [ -z "$CHANGESET" ]; then
|
|
echo "::error::Could not extract changeset content from comment"
|
|
exit 1
|
|
fi
|
|
|
|
FILE_PATH=".changeset/pr-${PR_NUMBER}.md"
|
|
|
|
# ── Use Git Data API for an atomic single commit ──
|
|
# This adds pr-N.md and deletes any superseded changeset files
|
|
# in one commit, preventing duplicate changesets on the branch.
|
|
|
|
# Get branch head. Verify the API resolved the EXACT ref we asked for:
|
|
# if URL semantics caused the path to resolve to a different branch
|
|
# (e.g. a fragment or decoded slash), `.ref` won't match and we abort
|
|
# before mutating anything. This is an additional check on top of the
|
|
# branch-name allowlist enforced in the "Get PR details" step.
|
|
REF_JSON=$(gh api "repos/${GITHUB_REPOSITORY}/git/ref/heads/${HEAD_REF}")
|
|
RESOLVED_REF=$(echo "$REF_JSON" | jq -r '.ref')
|
|
if [ "$RESOLVED_REF" != "refs/heads/${HEAD_REF}" ]; then
|
|
echo "::error::Ref mismatch: requested 'refs/heads/${HEAD_REF}' but API resolved '${RESOLVED_REF}'. Aborting."
|
|
exit 1
|
|
fi
|
|
COMMIT_SHA=$(echo "$REF_JSON" | jq -r '.object.sha')
|
|
TREE_SHA=$(gh api "repos/${GITHUB_REPOSITORY}/git/commits/${COMMIT_SHA}" --jq '.tree.sha')
|
|
|
|
# Create blob for the new changeset
|
|
BLOB_SHA=$(jq -n --arg content "$(printf '%s\n' "$CHANGESET" | base64 -w 0)" \
|
|
'{content: $content, encoding: "base64"}' | \
|
|
gh api "repos/${GITHUB_REPOSITORY}/git/blobs" --input - --jq '.sha')
|
|
|
|
# Start tree with the new changeset entry
|
|
TREE_FILE=$(mktemp)
|
|
jq -n --arg path "$FILE_PATH" --arg sha "$BLOB_SHA" \
|
|
'[{path: $path, mode: "100644", type: "blob", sha: $sha}]' > "$TREE_FILE"
|
|
|
|
# Only supersede changeset files that THIS PR introduced —
|
|
# never touch files inherited from parent branches (stacked PRs).
|
|
SUPERSEDED=$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files" \
|
|
--paginate --jq '.[] | select(.filename | startswith(".changeset/")) |
|
|
select(.filename | endswith(".md")) |
|
|
select(.filename | endswith("README.md") | not) |
|
|
.filename' 2>/dev/null \
|
|
| grep -v "^${FILE_PATH}$" || true)
|
|
|
|
if [ -n "$SUPERSEDED" ]; then
|
|
while IFS= read -r old_path; do
|
|
[ -z "$old_path" ] && continue
|
|
# Setting sha to null tells the Git tree API to delete the file
|
|
jq --arg path "$old_path" \
|
|
'. + [{path: $path, mode: "100644", type: "blob", sha: null}]' \
|
|
"$TREE_FILE" > "${TREE_FILE}.tmp" && mv "${TREE_FILE}.tmp" "$TREE_FILE"
|
|
echo "Superseding: ${old_path}"
|
|
done <<< "$SUPERSEDED"
|
|
fi
|
|
|
|
# Create tree, commit, and update ref
|
|
NEW_TREE_SHA=$(jq -n --arg base "$TREE_SHA" --argjson tree "$(cat "$TREE_FILE")" \
|
|
'{base_tree: $base, tree: $tree}' | \
|
|
gh api "repos/${GITHUB_REPOSITORY}/git/trees" --input - --jq '.sha')
|
|
rm -f "$TREE_FILE"
|
|
|
|
NEW_COMMIT_SHA=$(jq -n \
|
|
--arg message "chore: add changeset for PR #${PR_NUMBER}" \
|
|
--arg tree "$NEW_TREE_SHA" \
|
|
--arg parent "$COMMIT_SHA" \
|
|
'{message: $message, tree: $tree, parents: [$parent]}' | \
|
|
gh api "repos/${GITHUB_REPOSITORY}/git/commits" --input - --jq '.sha')
|
|
|
|
gh api "repos/${GITHUB_REPOSITORY}/git/refs/heads/${HEAD_REF}" \
|
|
-X PATCH -f sha="$NEW_COMMIT_SHA"
|
|
|
|
# Update comment: replace checkbox with committed confirmation
|
|
TMPFILE=$(mktemp)
|
|
awk -v sender="$SENDER" '{
|
|
sub(/- \[x\] \*\*Commit this changeset\*\* to the PR/,
|
|
"✅ Committed by @" sender)
|
|
print
|
|
}' <<< "$BODY" > "$TMPFILE"
|
|
gh api "repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" \
|
|
-X PATCH --input <(jq -n --rawfile body "$TMPFILE" '{body: $body}')
|
|
rm -f "$TMPFILE"
|
|
|
|
echo "Committed ${FILE_PATH} to ${HEAD_REF}"
|