Skip to content

Commit 62ff5f5

Browse files
Publish: add workflow for dev publishing
1 parent bd0869d commit 62ff5f5

2 files changed

Lines changed: 91 additions & 4 deletions

File tree

.github/workflows/publish-dev.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Publish dev version to npm
2+
3+
# Publishes a package and everything it depends on at <version>-dev-<short SHA>, under
4+
# the 'dev' dist-tag, so a consumer can verify an unreleased change in a real application.
5+
#
6+
# workflow_dispatch is available to anyone with write access, and a dispatched run
7+
# executes the workflow file as it exists on the selected ref — so an in-workflow actor
8+
# check would be deletable by the very person it is meant to stop. The admin gate is
9+
# therefore the 'npm-dev-publish' environment's required reviewers, which are repository
10+
# settings and cannot be edited from a branch. That environment name is also registered
11+
# in each package's npm trusted publisher configuration, so a run that drops the
12+
# 'environment' key to dodge the reviewer produces an OIDC token npm will reject.
13+
on:
14+
workflow_dispatch:
15+
inputs:
16+
package:
17+
description: 'Package to publish. Everything it depends on is published with it.'
18+
required: true
19+
type: choice
20+
options:
21+
- core
22+
- designsystem
23+
- extensions-angular
24+
- stylelint-plugin
25+
26+
permissions:
27+
id-token: write # Required for OIDC (https://docs.github.com/en/actions/concepts/security/openid-connect)
28+
contents: read
29+
30+
jobs:
31+
publish_dev:
32+
name: Publish ${{ inputs.package }} (dev)
33+
runs-on: ubuntu-latest
34+
# Gates the whole job rather than a later step, so nothing from the dispatched ref
35+
# runs before an admin has approved.
36+
environment: npm-dev-publish
37+
steps:
38+
- name: Checkout repo
39+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
40+
- name: Kirby setup
41+
uses: ./.github/actions/kirby-setup
42+
- name: Build and publish dev version to npm
43+
run: npm run publish -- --dev ${{ inputs.package }}

scripts/publish.js

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,43 @@ function applyDevVersions(packageNames, shortSha) {
280280
});
281281
}
282282

283+
// Reports what a dev publish produced. A consumer must install the whole closure,
284+
// because each package's peer dependency range is pinned to the exact dev version of
285+
// the package below it. Written to the workflow run summary when running in Actions.
286+
function reportDevPublish(publishedPackages, shortSha) {
287+
const installCommand = `npm install ${publishedPackages
288+
.map(({ name, version }) => `${name}@${version}`)
289+
.join(' ')}`;
290+
291+
console.log(`--- Dev publish of ${shortSha} complete ---`);
292+
console.log(installCommand);
293+
294+
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
295+
if (!summaryPath) {
296+
return;
297+
}
298+
299+
const summary = [
300+
`## Dev publish of \`${shortSha}\``,
301+
'',
302+
'| Package | Version |',
303+
'| --- | --- |',
304+
...publishedPackages.map(({ name, version }) => `| \`${name}\` | \`${version}\` |`),
305+
'',
306+
'Install the whole set — the peer dependency ranges are pinned to these exact versions:',
307+
'',
308+
'```sh',
309+
installCommand,
310+
'```',
311+
'',
312+
'Dev versions are permanent, unsupported and never removed. Do not reference one from',
313+
'a production dependency.',
314+
'',
315+
].join('\n');
316+
317+
fs.appendFileSync(summaryPath, summary);
318+
}
319+
283320
// Resolves as true only when the registry positively reports the version. A network
284321
// failure resolves as false, so we attempt the publish and let it fail loudly rather
285322
// than silently skipping a package that was never published.
@@ -422,15 +459,22 @@ async function main() {
422459

423460
const packagesToPublish = resolvePackagesToPublish();
424461

425-
if (isDevPublish) {
426-
const shortSha = shortCommitSha();
427-
console.log(`--- Dev publish of [${packagesToPublish.join(', ')}] at ${shortSha} ---`);
428-
applyDevVersions(packagesToPublish, shortSha);
462+
if (!isDevPublish) {
463+
for (const packageName of packagesToPublish) {
464+
await publishPipelines[packageName]();
465+
}
466+
return;
429467
}
430468

469+
const shortSha = shortCommitSha();
470+
console.log(`--- Dev publish of [${packagesToPublish.join(', ')}] at ${shortSha} ---`);
471+
const publishedPackages = applyDevVersions(packagesToPublish, shortSha);
472+
431473
for (const packageName of packagesToPublish) {
432474
await publishPipelines[packageName]();
433475
}
476+
477+
reportDevPublish(publishedPackages, shortSha);
434478
}
435479

436480
main().catch((error) => {

0 commit comments

Comments
 (0)