-
-
Notifications
You must be signed in to change notification settings - Fork 2
104 lines (90 loc) · 3.25 KB
/
Copy pathrelease-npm-packages.yml
File metadata and controls
104 lines (90 loc) · 3.25 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
name: Publish subpackages to npm
on:
release:
types: [published]
workflow_dispatch:
inputs:
publish_all:
description: 'Publish all packages (ignore change detection)'
type: boolean
default: false
version:
description: 'Version to publish (e.g. 1.2.3). Required for manual runs.'
type: string
required: true
jobs:
publish:
runs-on: ubuntu-latest
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
permissions:
contents: read
id-token: write
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
- name: Get release version
id: release
run: |
if [ -n "${{ inputs.version }}" ]; then
echo "version=${{ inputs.version }}" >> "$GITHUB_OUTPUT"
else
echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
fi
- name: Get previous release tag
id: prev_tag
run: |
CURRENT_TAG="${GITHUB_REF_NAME}"
PREV_TAG=$(git tag --sort=-version:refname | grep -v "^${CURRENT_TAG}$" | head -1)
if [ -z "$PREV_TAG" ]; then
# No previous tag: diff against the very first commit
PREV_TAG=$(git rev-list --max-parents=0 HEAD)
fi
echo "tag=$PREV_TAG" >> "$GITHUB_OUTPUT"
- name: Detect changed packages
id: changes
run: |
CHANGED=""
for dir in templates/*; do
# skip if folder does not contain a package.json
if [ ! -f "$dir/package.json" ]; then
echo "Skipping $dir (no package.json)"
continue
fi
# skip storybook as it's not meant to be published
if [ "$(basename "$dir")" = "storybook" ]; then
echo "Skipping storybook (development tool, not for publishing)"
continue
fi
if [ "${{ github.event_name }}" != "workflow_dispatch" ] \
&& [ "${{ inputs.publish_all }}" != "true" ] \
&& git diff --quiet "${{ steps.prev_tag.outputs.tag }}" HEAD -- "$dir"; then
continue
fi
CHANGED="$CHANGED $dir"
done
echo "dirs=$CHANGED" >> "$GITHUB_OUTPUT"
- name: Publish changed packages
# Requires npm Trusted Publishing configured on npmjs.com for each package:
# Package Settings → Publishing → Trusted Publishers → Add GitHub Actions publisher
# (owner: vardumper, repo: extended-htmldocument, workflow: release-npm-packages.yml)
if: steps.changes.outputs.dirs != ''
run: |
VERSION="${{ steps.release.outputs.version }}"
for dir in ${{ steps.changes.outputs.dirs }}; do
echo "Publishing $dir"
# update version number
jq --arg v "$VERSION" '.version=$v' "$dir/package.json" \
> "$dir/package.json.tmp"
mv "$dir/package.json.tmp" "$dir/package.json"
cd "$dir"
npm publish --access public --provenance
cd -
done