Skip to content

Commit cf45e93

Browse files
authored
Use split publishing workflow (#679)
* fix release line timing * Use split publishing workflow * remove release check, handle through publish plan * remove unused script * remove unused publish plan output * fmt * update a thing * fmt * simplify * update pre * update changesets cli
1 parent 7359107 commit cf45e93

8 files changed

Lines changed: 62 additions & 56 deletions

File tree

.changeset/config.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
2-
"$schema": "https://unpkg.com/@changesets/config@1.6.2/schema.json",
3-
"changelog": [
4-
"@changesets/changelog-github",
5-
{ "repo": "changesets/action" }
6-
],
2+
"$schema": "https://unpkg.com/@changesets/config@4.0.0-next.6/schema.json",
3+
"changelog": "@changesets/changelog-github",
74
"commit": false,
85
"linked": [],
96
"access": "restricted",
107
"baseBranch": "main",
118
"updateInternalDependencies": "patch",
12-
"ignore": []
9+
"ignore": [],
10+
"privatePackages": {
11+
"version": true,
12+
"tag": true
13+
}
1314
}

.changeset/pre.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"mode": "pre",
33
"tag": "next",
4-
"initialVersions": {
5-
"@changesets/action": "1.9.0"
6-
},
74
"changesets": [
85
"all-cars-grin",
96
"eight-clocks-pull",

.github/workflows/publish.yml

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,38 @@ concurrency:
1515
permissions: {} # each job should define its own permission explicitly
1616

1717
jobs:
18+
select-mode:
19+
name: Select mode
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 20
22+
outputs:
23+
mode: ${{ steps.select-mode.outputs.mode }}
24+
permissions:
25+
contents: read # to check out repo (actions/checkout)
26+
steps:
27+
- name: Check out repo
28+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
29+
with:
30+
persist-credentials: false
31+
32+
- uses: ./.github/actions/ci-setup
33+
with:
34+
skip-cache: true # avoid cache poisoning attacks
35+
36+
- name: Build
37+
run: pnpm build
38+
39+
- name: Select mode
40+
id: select-mode
41+
uses: ./select-mode
42+
1843
version:
1944
name: Version
45+
if: needs.select-mode.outputs.mode == 'version'
46+
needs: select-mode
2047
runs-on: ubuntu-latest
2148
environment: version
2249
timeout-minutes: 20
23-
outputs:
24-
hasChangesets: ${{ steps.changesets.outputs.hasChangesets }}
2550
permissions:
2651
contents: read # to check out repo (actions/checkout)
2752
steps:
@@ -47,15 +72,15 @@ jobs:
4772

4873
- name: Create or update release pull request
4974
id: changesets
50-
uses: ./
75+
uses: ./version
5176
with:
5277
github-token: ${{ steps.app-token.outputs.token }}
53-
version: pnpm bump
78+
script: pnpm bump
5479

5580
publish:
5681
name: Publish
57-
if: needs.version.outputs.hasChangesets == 'false'
58-
needs: version
82+
if: needs.select-mode.outputs.mode == 'publish'
83+
needs: select-mode
5984
runs-on: ubuntu-latest
6085
environment: marketplace
6186
timeout-minutes: 20
@@ -82,7 +107,7 @@ jobs:
82107
run: pnpm build
83108

84109
- name: Publish to marketplace
85-
uses: ./
110+
uses: ./publish
86111
with:
87112
github-token: ${{ steps.app-token.outputs.token }}
88-
publish: pnpm release
113+
script: pnpm release

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@changesets/action",
33
"version": "2.0.0-next.2",
4+
"private": true,
45
"license": "MIT",
56
"type": "module",
67
"main": "dist/index.js",
@@ -36,7 +37,7 @@
3637
},
3738
"devDependencies": {
3839
"@changesets/changelog-github": "^1.0.0-next.6",
39-
"@changesets/cli": "^3.0.0-next.7",
40+
"@changesets/cli": "^3.0.0-next.8",
4041
"@changesets/types": "^7.0.0-next.6",
4142
"@changesets/write": "^1.0.0-next.6",
4243
"@tsconfig/node24": "^24.0.4",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ minimumReleaseAgeExclude:
77
- "@changesets/assemble-release-plan@7.0.0-next.7"
88
- "@changesets/changelog-git@1.0.0-next.6"
99
- "@changesets/changelog-github@1.0.0-next.6"
10-
- "@changesets/cli@3.0.0-next.7"
10+
- "@changesets/cli@3.0.0-next.8"
1111
- "@changesets/config@4.0.0-next.6"
1212
- "@changesets/get-dependents-graph@3.0.0-next.6"
1313
- "@changesets/get-github-info@1.0.0-next.3"

scripts/bump.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import fs from "node:fs";
22
import path from "node:path";
33
import { exec } from "@actions/exec";
4-
import pkgJson from "../package.json" with { type: "json" };
54

65
process.chdir(path.join(import.meta.dirname, ".."));
76

87
await exec("changeset", ["version"]);
98

9+
// read after versioning to get the new version
10+
const pkgJson = (await import("../package.json", { with: { type: "json" } }))
11+
.default;
1012
const releaseLine = `v${pkgJson.version.split(".")[0]}`;
1113

1214
const readmePath = path.join(import.meta.dirname, "..", "README.md");

scripts/release.ts

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Buffer } from "node:buffer";
22
import path from "node:path";
3-
import { exec, getExecOutput } from "@actions/exec";
3+
import { exec } from "@actions/exec";
44
import pkgJson from "../package.json" with { type: "json" };
55

66
const tag = `v${pkgJson.version}`;
@@ -20,37 +20,17 @@ const gitEnv = {
2020

2121
process.chdir(path.join(import.meta.dirname, ".."));
2222

23-
(async () => {
24-
const { exitCode, stderr } = await getExecOutput(
25-
`git`,
26-
["ls-remote", "--exit-code", "origin", "--tags", `refs/tags/${tag}`],
27-
{
28-
ignoreReturnCode: true,
29-
},
30-
);
31-
if (exitCode === 0) {
32-
console.log(
33-
`Action is not being published because version ${tag} is already published`,
34-
);
35-
return;
36-
}
37-
if (exitCode !== 2) {
38-
throw new Error(`git ls-remote exited with ${exitCode}:\n${stderr}`);
39-
}
40-
41-
await exec("git", ["checkout", "--detach"]);
42-
await exec("git", ["add", "--force", "dist"]);
43-
await exec("git", ["commit", "-m", tag]);
23+
await exec("git", ["checkout", "--detach"]);
24+
await exec("git", ["add", "--force", "dist"]);
25+
await exec("git", ["commit", "-m", tag]);
4426

45-
await exec("changeset", ["git-tag"]);
46-
47-
if (isPrerelease) {
48-
await exec("git", ["push", "origin", `refs/tags/${tag}`], {
49-
env: gitEnv,
50-
});
51-
return;
52-
}
27+
await exec("changeset", ["git-tag"]);
5328

29+
if (isPrerelease) {
30+
await exec("git", ["push", "origin", `refs/tags/${tag}`], {
31+
env: gitEnv,
32+
});
33+
} else {
5434
await exec(
5535
"git",
5636
[
@@ -64,4 +44,4 @@ process.chdir(path.join(import.meta.dirname, ".."));
6444
env: gitEnv,
6545
},
6646
);
67-
})();
47+
}

0 commit comments

Comments
 (0)