Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/changeset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
node-version-file: .tool-versions
- name: Fetch pull request base ref
run: git fetch origin "${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}"
run: git fetch origin "refs/heads/$GITHUB_BASE_REF:refs/remotes/origin/$GITHUB_BASE_REF"
- name: Validate changeset summaries
run: |
node --test scripts/release/validate-changesets.test.mjs
Expand Down
143 changes: 78 additions & 65 deletions .github/workflows/prepare-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,38 @@ name: Prepare Release

on:
workflow_dispatch:
inputs:
source_branch:
description: Branch to prepare (defaults to the selected workflow branch)
type: string

permissions:
contents: write
pull-requests: write
contents: read
pull-requests: read

concurrency:
group: prepare-release-${{ github.ref_name }}
group: prepare-release-${{ inputs.source_branch || github.ref_name }}
cancel-in-progress: false

env:
SOURCE_BRANCH: ${{ inputs.source_branch || github.ref_name }}
HUSKY: "0"

jobs:
prepare-release:
runs-on: ubuntu-latest
timeout-minutes: 20
outputs:
source_sha: ${{ steps.checkout.outputs.commit }}
has_changes: ${{ steps.patch.outputs.has_changes }}
steps:
- name: Require main branch
run: |
if [ "${{ github.ref_name }}" != "main" ]; then
{
echo "## Prepare release"
echo
echo "This workflow must be run from \`main\`. Selected ref: \`${{ github.ref_name }}\`."
} >> "$GITHUB_STEP_SUMMARY"
exit 1
fi
- name: Validate source branch
run: git check-ref-format "refs/heads/$SOURCE_BRANCH"
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
id: checkout
with:
persist-credentials: false
ref: refs/heads/${{ env.SOURCE_BRANCH }}
fetch-depth: 0
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
Expand All @@ -41,76 +44,83 @@ jobs:
run: pnpm install --frozen-lockfile
- name: Validate publishable package metadata
run: node scripts/release/validate-publishable-packages.mjs
- name: Record source commit and prepare branch
id: source
run: |
main_sha="$(git rev-parse HEAD)"
short_main_sha="$(git rev-parse --short=12 HEAD)"
prepare_branch="prepare-release/${short_main_sha}"

{
echo "main_sha=$main_sha"
echo "short_main_sha=$short_main_sha"
echo "prepare_branch=$prepare_branch"
} >> "$GITHUB_OUTPUT"
- name: Run changeset version
env:
GITHUB_TOKEN: ${{ github.token }}
run: pnpm exec changeset version
- name: Read release version
id: release_version
- name: Save release changes
id: patch
run: |
release_version="$(node -p "require('./js/package.json').version")"
echo "version=$release_version" >> "$GITHUB_OUTPUT"
- name: Create release commit
id: release_commit
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -c "${{ steps.source.outputs.prepare_branch }}"
git add -A

if git diff --cached --quiet; then
echo "No release changes were generated by changeset version."
echo "No release changes were generated by changeset version." >> "$GITHUB_STEP_SUMMARY"
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi

git commit -m "chore: Prepare release"
release_sha="$(git rev-parse HEAD)"
git push origin HEAD:refs/heads/${{ steps.source.outputs.prepare_branch }}
git diff --cached --binary > "$RUNNER_TEMP/version.patch"
echo "has_changes=true" >> "$GITHUB_OUTPUT"
echo "release_sha=$release_sha" >> "$GITHUB_OUTPUT"
- name: Summarize empty release
if: steps.release_commit.outputs.has_changes == 'false'
run: |
{
echo "## Prepare release"
echo
echo "No release changes were generated by \`changeset version\`."
} >> "$GITHUB_STEP_SUMMARY"
- name: Create release PR
if: steps.release_commit.outputs.has_changes == 'true'
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: steps.patch.outputs.has_changes == 'true'
with:
name: release-changes
path: ${{ runner.temp }}/version.patch
retention-days: 1
if-no-files-found: error

open-release-pr:
needs: prepare-release
if: needs.prepare-release.outputs.has_changes == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: release-changes
path: ${{ runner.temp }}/release
- name: Create release commit and pull request
env:
GH_TOKEN: ${{ github.token }}
SOURCE_MAIN_SHA: ${{ steps.source.outputs.main_sha }}
SOURCE_SHA: ${{ needs.prepare-release.outputs.source_sha }}
run: |
node <<'NODE' > release-packages.md
git check-ref-format "refs/heads/$SOURCE_BRANCH"
[[ "$SOURCE_SHA" =~ ^[0-9a-f]{40}$ ]]
git merge-base --is-ancestor "$SOURCE_SHA" "refs/remotes/origin/$SOURCE_BRANCH"
short_sha="$(git rev-parse --short=12 "$SOURCE_SHA")"
prepare_branch="prepare-release/$SOURCE_BRANCH-$short_sha"

# Build the release tree in the index without checking out source-branch files.
git read-tree "$SOURCE_SHA"
git apply --cached "$RUNNER_TEMP/release/version.patch"
release_version="$(git show :js/package.json | jq -er .version)"
if [[ "$SOURCE_BRANCH" =~ ^v([0-9]+)$ && "${release_version%%.*}" != "${BASH_REMATCH[1]}" ]]; then
echo "SDK version $release_version does not match maintenance branch $SOURCE_BRANCH." >&2
exit 1
fi

git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
release_sha="$(git commit-tree "$(git write-tree)" -p "$SOURCE_SHA" -m "chore: Prepare release")"
node <<'NODE' > "$RUNNER_TEMP/release-packages.md"
const { execFileSync } = require("node:child_process");
const fs = require("node:fs");
const paths = execFileSync(
"git",
["diff", "--name-only", process.env.SOURCE_MAIN_SHA, "HEAD", "--", "**/package.json", "package.json"],
["diff", "--name-only", "--cached", process.env.SOURCE_SHA, "--", "**/package.json", "package.json"],
{ encoding: "utf8" },
)
.trim()
.split("\n")
.filter(Boolean);
const packages = paths
.map((path) => ({ path, manifest: JSON.parse(fs.readFileSync(path, "utf8")) }))
.map((path) => ({ path, manifest: JSON.parse(execFileSync("git", ["show", `:${path}`], { encoding: "utf8" })) }))
.filter(({ path, manifest }) => {
const previous = JSON.parse(
execFileSync("git", ["show", `${process.env.SOURCE_MAIN_SHA}:${path}`], { encoding: "utf8" }),
execFileSync("git", ["show", `${process.env.SOURCE_SHA}:${path}`], { encoding: "utf8" }),
);
return manifest.version !== previous.version;
})
Expand All @@ -129,16 +139,18 @@ jobs:
echo
echo "## Packages"
echo
cat release-packages.md
cat "$RUNNER_TEMP/release-packages.md"
echo
echo "Source-main-sha: ${{ steps.source.outputs.main_sha }}"
} > release-pr-body.md
echo "Source-sha: $SOURCE_SHA"
} > "$RUNNER_TEMP/release/body.md"

git push origin "$release_sha:refs/heads/$prepare_branch"

pr_url="$(gh pr create \
--base main \
--head "${{ steps.source.outputs.prepare_branch }}" \
--title "chore: Prepare release v${{ steps.release_version.outputs.version }} (${{ steps.source.outputs.short_main_sha }})" \
--body-file release-pr-body.md)"
--base "$SOURCE_BRANCH" \
--head "$prepare_branch" \
--title "chore: Prepare release v$release_version ($short_sha)" \
--body-file "$RUNNER_TEMP/release/body.md")"

{
echo "## Prepare release"
Expand All @@ -148,6 +160,7 @@ jobs:
echo "To publish this release, run the \`Publish Release\` workflow with:"
echo
echo "\`\`\`text"
echo "release_sha: ${{ steps.release_commit.outputs.release_sha }}"
echo "source_branch: $SOURCE_BRANCH"
echo "release_sha: $release_sha"
echo "\`\`\`"
} >> "$GITHUB_STEP_SUMMARY"
Loading