Skip to content

Commit d18f4dd

Browse files
committed
lockdown publish branch
1 parent 1a9cfc7 commit d18f4dd

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
run: npm ci
4444
- name: Build
4545
run: npm run build
46-
- name: 'Upload Artifact'
46+
- name: "Upload Artifact"
4747
uses: actions/upload-artifact@v3
4848
with:
4949
path: |
@@ -57,7 +57,7 @@ jobs:
5757
needs: build
5858
strategy:
5959
matrix:
60-
node: [ 16, 18, 20 ]
60+
node: [16, 18, 20]
6161
fail-fast: false
6262
name: Test Node ${{ matrix.node }}
6363
steps:
@@ -124,28 +124,28 @@ jobs:
124124
test_and_contribute:
125125
runs-on: ubuntu-latest
126126
name: Branch protection
127-
needs: ['test', 'lint']
127+
needs: ["test", "lint"]
128128
steps:
129129
- run: true
130130

131131
publish:
132132
runs-on: ubuntu-latest
133133
name: Publish (NPM)
134-
needs: ['build', 'test']
134+
needs: ["build", "test"]
135135
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
136136
permissions:
137137
id-token: write
138138
steps:
139139
- uses: actions/checkout@v4
140140
with:
141-
fetch-depth: 2
141+
fetch-depth: 2
142142
- name: Setup node
143143
uses: actions/setup-node@v3
144144
with:
145145
node-version: 20
146146
check-latest: false
147-
registry-url: 'https://registry.npmjs.org'
148-
- name: 'Download Artifacts'
147+
registry-url: "https://registry.npmjs.org"
148+
- name: "Download Artifacts"
149149
uses: actions/download-artifact@v3
150150
- name: Rsync Artifacts
151151
run: rsync -a artifact/ packages
@@ -155,3 +155,4 @@ jobs:
155155
# ADAPTER_NEXTJS_NPM_TOKEN: ${{ secrets.ADAPTER_NEXTJS_NPM_TOKEN }}
156156
# FIREBASE_FRAMEWORKS_NPM_TOKEN: ${{ secrets.FIREBASE_FRAMEWORKS_NPM_TOKEN }}
157157
NODE_AUTH_TOKEN: ${{ secrets.PERSONAL_NPM_TOKEN }}
158+
BRANCH_NAME: ${{ github.event.base_ref }}

scripts/github.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const { basename } = require("path");
55
const [, packageFromRef, versionFromRef, , prerelease] =
66
/^refs\/tags\/(.+)-v(\d\d*\.\d\d*(\.\d\d*)?(-.+)?)$/.exec(process.env.GITHUB_REF ?? "") ?? [];
77

8+
const [, packageFromBranch, versionFromBranch] =
9+
/^refs\/heads\/(.+)-v(\d\d*\.\d\d*)$/.exec(process.env.BRANCH_NAME ?? "") ?? [];
10+
811
const since = process.env.GITHUB_ACTION
912
? `--since ${
1013
(process.env.GITHUB_BASE_REF && `origin/${process.env.GITHUB_BASE_REF}`) || "HEAD^1"
@@ -39,4 +42,6 @@ module.exports = {
3942
filteredLernaList,
4043
shortSHA,
4144
lernaScopeArgs,
45+
packageFromBranch,
46+
versionFromBranch,
4247
};

scripts/publish.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
#! /usr/bin/env node
22
const { execSync } = require("child_process");
3+
const { minor, major } = require("semver");
34
const { writeFileSync, readFileSync } = require("fs");
45
const { join } = require("path");
5-
const { filteredLernaList, versionFromRef, shortSHA, prerelease } = require("./github.js");
6+
const {
7+
filteredLernaList,
8+
versionFromRef,
9+
shortSHA,
10+
prerelease,
11+
packageFromBranch,
12+
versionFromBranch,
13+
packageFromRef,
14+
} = require("./github.js");
615

716
const wombatDressingRoomTokens = new Map([
817
// Disabling this until I can get wombat access to this org
@@ -22,6 +31,20 @@ for (const lerna of filteredLernaList) {
2231
`Cowardly refusing to publish ${lerna.name}@${versionFromRef} from ${lerna.version}, version needs to be bumped in source.`,
2332
);
2433
}
34+
if (
35+
versionFromRef &&
36+
packageFromRef &&
37+
(packageFromRef !== packageFromBranch ||
38+
`${major(versionFromRef)}.${minor(versionFromRef)}` !== versionFromBranch)
39+
) {
40+
throw new Error(
41+
`Refusing to publish ${lerna.name}@${versionFromRef}, ${
42+
lerna.name
43+
}@${versionFromRef} needs to be published from the branch: ${packageFromRef}-v${major(
44+
versionFromRef,
45+
)}.${minor(versionFromRef)}`,
46+
);
47+
}
2548
const version = versionFromRef || `${lerna.version}-canary.${shortSHA}`;
2649
const cwd = lerna.location;
2750
const tag = versionFromRef ? (prerelease ? "next" : "latest") : "canary";

0 commit comments

Comments
 (0)