-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (116 loc) · 4.67 KB
/
Copy pathnpm-publish.yml
File metadata and controls
137 lines (116 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: npm publish
# Packages are intentionally not published by this workflow yet. Once the
# generated package contents have been verified, remove --dry-run from the
# publish command and update the workflow name.
on:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: npm-publish
cancel-in-progress: false
jobs:
publish-dry-run:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v7
with:
submodules: recursive
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: 22
registry-url: https://registry.npmjs.org
# cache: npm
# Internal packages may not exist in the npm registry yet. Normalize
# their dependency specs temporarily so npm links every dependency from
# the checked-out workspaces instead of trying to download it.
- name: Link local workspace packages
run: node scripts/link-local-workspaces.mjs
- name: Install dependencies
run: npm install --no-audit --no-fund
- name: Build publishable packages
run: npm run build:packages
# link-local-workspaces.mjs changes internal dependency specs to "*".
# Restore the committed manifests after the build so those temporary
# specs are never included in a published package.
- name: Restore package manifests for publishing
run: git submodule foreach --recursive 'git restore --source=HEAD -- package.json'
- name: Preview npm packages
shell: bash
run: |
set -euo pipefail
mapfile -t packages < <(
npm query .workspace --json | node -e '
let input = "";
process.stdin.on("data", chunk => input += chunk);
process.stdin.on("end", () => {
for (const workspace of JSON.parse(input)) {
if (!workspace.private) console.log(workspace.name);
}
});
'
)
for package in "${packages[@]}"; do
echo "::group::${package}"
# Skip previewing when the local version is already on the registry.
local_version="$(npm pkg get version --workspace "${package}" | node -e '
let input = "";
process.stdin.on("data", chunk => input += chunk);
process.stdin.on("end", () => {
const parsed = JSON.parse(input);
const version = typeof parsed === "string" ? parsed : Object.values(parsed)[0];
process.stdout.write(version);
});
')"
if npm view "${package}@${local_version}" version >/dev/null 2>&1; then
echo "Skipping ${package}@${local_version}: already published."
echo "::endgroup::"
continue
fi
npm publish --workspace "${package}" --access public --dry-run
echo "::endgroup::"
done
env:
# npm checks authentication even for a publish dry run.
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish npm packages
shell: bash
run: |
set -euo pipefail
mapfile -t packages < <(
npm query .workspace --json | node -e '
let input = "";
process.stdin.on("data", chunk => input += chunk);
process.stdin.on("end", () => {
for (const workspace of JSON.parse(input)) {
if (!workspace.private) console.log(workspace.name);
}
});
'
)
for package in "${packages[@]}"; do
echo "::group::${package}"
# Skip publishing when the local version is already on the registry.
local_version="$(npm pkg get version --workspace "${package}" | node -e '
let input = "";
process.stdin.on("data", chunk => input += chunk);
process.stdin.on("end", () => {
const parsed = JSON.parse(input);
const version = typeof parsed === "string" ? parsed : Object.values(parsed)[0];
process.stdout.write(version);
});
')"
if npm view "${package}@${local_version}" version >/dev/null 2>&1; then
echo "Skipping ${package}@${local_version}: already published."
echo "::endgroup::"
continue
fi
npm publish --workspace "${package}" --access public
echo "::endgroup::"
done
env:
# npm checks authentication even for a publish.
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}