-
Notifications
You must be signed in to change notification settings - Fork 24
70 lines (60 loc) · 2.28 KB
/
Copy pathpublish-npm.yml
File metadata and controls
70 lines (60 loc) · 2.28 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
name: Publish npm Package
on:
push:
tags:
# `*` matches any character except `/`, so `plugin-stitch@1.0.0` matches
# `*.*.*` too. The plugin publish workflow that used to claim those tags
# is gone, and both `plugin-checkpoint@1.0.0` and `plugin-stitch@1.0.0`
# still exist in this repository -- without the exclusion, re-pushing one
# starts this workflow, and it only stops at the tag/version check.
- "*.*.*"
- "!plugin-*"
permissions:
contents: read
id-token: write
jobs:
publish:
# Second layer, kept from the pre-2.0 workflow: a tag filter is easy to
# widen by accident, and this job holds `id-token: write`.
if: ${{ !startsWith(github.ref_name, 'plugin-') }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: 24
registry-url: https://registry.npmjs.org
cache: npm
- name: Install dependencies
run: npm ci
- name: Verify tag matches package version
shell: bash
run: |
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
if [ "${PACKAGE_VERSION}" != "${GITHUB_REF_NAME}" ]; then
echo "Tag ${GITHUB_REF_NAME} does not match package.json version ${PACKAGE_VERSION}"
exit 1
fi
- name: Smoke test release package
run: npm run release:smoke
- name: Verify package contents
run: npm run release:check
- name: Check whether version already exists on npm
id: npm_version
shell: bash
run: |
PACKAGE_NAME="$(node -p "require('./package.json').name")"
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" version >/dev/null 2>&1; then
echo "published=true" >> "$GITHUB_OUTPUT"
echo "Version ${PACKAGE_VERSION} is already published. Skipping npm publish."
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish package to npm
if: steps.npm_version.outputs.published != 'true'
run: npm publish --access public