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
25 changes: 14 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,34 @@ jobs:
with:
node-version: lts/*
cache: "npm"
registry-url: "https://registry.npmjs.org"

- name: Install dependencies
run: npm ci

- name: 🚀 Create/Update Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
uses: changesets/action@v2.1.2
with:
version: npm run version
publish: npm run release
title: "chore(new-release)"
commit: "chore(new-release)"
branch: main
createGithubReleases: true
github-token: ${{ secrets.STACKS_TOOLING_GH_RW_PAT }}
version-script: npm run version
publish-script: npm run release
pr-title: "chore(new-release)"
commit-message: "chore(new-release)"
pr-base-branch: main
create-github-releases: true
push-git-tags: true
push-with-git-cli: true
env:
GITHUB_TOKEN: ${{ secrets.STACKS_TOOLING_GH_RW_PAT }}
NPM_TOKEN: ${{ secrets.NPM_API_KEY }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_API_KEY }}

- name: Docs on Release Pull Request
# run only if there is a release pull request open
if: steps.changesets.outputs.pullRequestNumber
if: steps.changesets.outputs.pr-number
uses: thollander/actions-comment-pull-request@v3
with:
comment-tag: "pr-release-docs"
pr-number: ${{ steps.changesets.outputs.pullRequestNumber }}
pr-number: ${{ steps.changesets.outputs.pr-number }}
message: |
To trigger the build for this PR, **close and re-open it**.
This is necessary because the PR is updated by github-actions[bot].
Expand Down
54 changes: 51 additions & 3 deletions scripts/stable-release-config.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ describe("stable release configuration", () => {

assert.equal(workflow.match(/branches: \[main\]/g)?.length, 2);
assert.match(workflow, /if: github\.ref == 'refs\/heads\/main'/);
assert.match(workflow, /publish: npm run release/);
assert.match(workflow, /branch: main/);
assert.match(workflow, /createGithubReleases: true/);
assert.match(workflow, /publish-script: npm run release/);
assert.match(workflow, /pr-base-branch: main/);
assert.match(workflow, /create-github-releases: true/);
assert.match(workflow, /^permissions:\n contents: read$/m);
assert.match(
workflow,
Expand All @@ -83,6 +83,54 @@ describe("stable release configuration", () => {
assert.match(codeowners, /^\* @StackExchange\/stacks$/m);
});

test("uses Changesets v3-compatible release automation", async () => {
const workflow = await readRepositoryFile(".github/workflows/main.yml");
const releaseJob = workflow.slice(workflow.indexOf(" release:\n"));
const packageJson = JSON.parse(
await readRepositoryFile("package.json")
);
const cliVersion = semver.minVersion(
packageJson.devDependencies["@changesets/cli"]
);

assert.equal(cliVersion?.major, 3);
assert.match(releaseJob, /uses: changesets\/action@v2\.1\.2\s/);
assert.match(releaseJob, /version-script: npm run version/);
assert.match(releaseJob, /publish-script: npm run release/);
assert.match(releaseJob, /pr-title: "chore\(new-release\)"/);
assert.match(releaseJob, /commit-message: "chore\(new-release\)"/);
assert.match(releaseJob, /push-git-tags: true/);
assert.match(releaseJob, /push-with-git-cli: true/);
assert.match(releaseJob, /if: steps\.changesets\.outputs\.pr-number/);
assert.match(
releaseJob,
/pr-number: \$\{\{ steps\.changesets\.outputs\.pr-number \}\}/
);
assert.doesNotMatch(
releaseJob,
/pullRequestNumber|createGithubReleases|^\s+(version|publish|title|commit|branch):/m
);
});

test("configures release authentication without Changesets v1 npmrc handling", async () => {
const workflow = await readRepositoryFile(".github/workflows/main.yml");
const releaseJob = workflow.slice(workflow.indexOf(" release:\n"));

assert.match(
releaseJob,
/uses: actions\/setup-node@v4\n\s+with:\n\s+node-version: lts\/\*\n\s+cache: "npm"\n\s+registry-url: "https:\/\/registry\.npmjs\.org"/
);
assert.match(
releaseJob,
/github-token: \$\{\{ secrets\.STACKS_TOOLING_GH_RW_PAT \}\}/
);
assert.match(
releaseJob,
/env:\n\s+NODE_AUTH_TOKEN: \$\{\{ secrets\.NPM_API_KEY \}\}/
);
assert.doesNotMatch(releaseJob, /^\s+(GITHUB_TOKEN|NPM_TOKEN):/m);
});

test("has exited prerelease mode when prerelease state exists", async () => {
const preJsonPath = new URL("../.changeset/pre.json", import.meta.url);
const packageJson = JSON.parse(
Expand Down
Loading