Skip to content

Commit 21b8175

Browse files
committed
cleaning up
1 parent 64517a4 commit 21b8175

4 files changed

Lines changed: 80 additions & 32 deletions

File tree

.changeset/early-lions-create.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openfn/cli': patch
3+
---
4+
5+
jam

.github/workflows/changeset.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@ jobs:
1212
name: Changeset present
1313
runs-on: ubuntu-latest
1414
steps:
15-
# Full history so the merge-base with the target branch can be found
1615
- uses: actions/checkout@v6
1716
with:
17+
# Full history so the merge-base with the target branch can be found
1818
fetch-depth: 0
1919
- uses: actions/setup-node@v6
2020
with:
2121
node-version: '24.14'
22+
- uses: pnpm/action-setup@v4
23+
# Install only the root package's dev-deps (which include @changesets/cli),
24+
# not the whole workspace, so the script can run `changeset`
25+
- run: pnpm install --filter @openfn/kit --frozen-lockfile --ignore-scripts
2226
# The condition sits on the step, not the job, so the check still reports
2327
# green when skipped - a required job skipped via `if` blocks the PR forever
24-
# No install needed - the check only uses git and Node built-ins
2528
- name: Check for a changeset
2629
if: ${{ !contains(github.event.pull_request.labels.*.name, 'No changeset needed') }}
2730
run: node scripts/check-changesets.js "${{ github.event.pull_request.base.ref }}"

changeset.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"changesets": [
3+
{
4+
"releases": [
5+
{
6+
"name": "@openfn/cli",
7+
"type": "patch"
8+
}
9+
],
10+
"summary": "jam",
11+
"id": "early-lions-create"
12+
},
13+
{
14+
"releases": [
15+
{
16+
"name": "@openfn/deploy",
17+
"type": "minor"
18+
}
19+
],
20+
"summary": "jam",
21+
"id": "sixty-canyons-occur"
22+
}
23+
],
24+
"releases": [
25+
{
26+
"name": "@openfn/cli",
27+
"type": "patch",
28+
"oldVersion": "1.38.4",
29+
"changesets": [
30+
"early-lions-create"
31+
],
32+
"newVersion": "1.38.5"
33+
},
34+
{
35+
"name": "@openfn/deploy",
36+
"type": "minor",
37+
"oldVersion": "0.13.1",
38+
"changesets": [
39+
"sixty-canyons-occur"
40+
],
41+
"newVersion": "0.14.0"
42+
}
43+
]
44+
}

scripts/check-changesets.js

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
*/
66

77
const { execFileSync } = require('node:child_process');
8-
const { readFileSync, readdirSync, appendFileSync } = require('node:fs');
8+
const {
9+
readFileSync,
10+
existsSync,
11+
unlinkSync,
12+
appendFileSync,
13+
} = require('node:fs');
914
const path = require('node:path');
1015

1116
// Top-level dirs whose packages must carry a changeset when changed
@@ -83,18 +88,28 @@ for (const dir of changedDirs) {
8388
}
8489
}
8590

86-
// Packages named across the frontmatter of every changeset file (the "covered"
87-
// set) - read straight from disk so pending and uncommitted changesets count
88-
const changesetDir = path.join(process.cwd(), '.changeset');
91+
// Ask changesets which packages are marked for release (the "covered" set).
92+
// Going through the CLI means we never parse the changeset file format ourselves
8993
const covered = new Set();
90-
for (const file of readdirSync(changesetDir)) {
91-
if (!file.endsWith('.md') || file.toLowerCase() === 'readme.md') {
92-
continue;
93-
}
94-
const contents = readFileSync(path.join(changesetDir, file), 'utf8');
95-
for (const name of changesetPackages(contents)) {
96-
covered.add(name);
94+
const planFile = path.join(process.cwd(), '.changeset-status.json');
95+
try {
96+
execFileSync('pnpm', ['exec', 'changeset', 'status', '--output', planFile], {
97+
stdio: ['ignore', 'pipe', 'pipe'],
98+
});
99+
} catch {
100+
// status exits non-zero and writes nothing when packages changed but no
101+
// changesets exist yet - nothing is marked for release, covered stays empty
102+
}
103+
if (existsSync(planFile)) {
104+
const plan = JSON.parse(readFileSync(planFile, 'utf8'));
105+
// changesets[] = packages a changeset explicitly names. Not releases[], which
106+
// also includes transitive dependency bumps we don't want to treat as covered
107+
for (const changeset of plan.changesets) {
108+
for (const release of changeset.releases) {
109+
covered.add(release.name);
110+
}
97111
}
112+
unlinkSync(planFile);
98113
}
99114

100115
// Any changed package that no changeset accounts for
@@ -140,22 +155,3 @@ if (process.env.GITHUB_STEP_SUMMARY) {
140155
}
141156

142157
process.exit(1);
143-
144-
// Package names listed in a changeset's frontmatter block
145-
function changesetPackages(contents) {
146-
const frontmatter = contents.match(/^---\r?\n([\s\S]*?)\r?\n---/);
147-
if (!frontmatter) {
148-
return [];
149-
}
150-
const names = [];
151-
for (const line of frontmatter[1].split('\n')) {
152-
// e.g. '@openfn/cli': minor or "@openfn/cli": patch
153-
const entry = line.match(
154-
/^\s*['"]?(@?[\w./-]+)['"]?\s*:\s*(patch|minor|major)\s*$/
155-
);
156-
if (entry) {
157-
names.push(entry[1]);
158-
}
159-
}
160-
return names;
161-
}

0 commit comments

Comments
 (0)