forked from hsluv/hsluv-sass
-
Notifications
You must be signed in to change notification settings - Fork 0
46 lines (43 loc) · 1.46 KB
/
Copy pathnpm-publish.yml
File metadata and controls
46 lines (43 loc) · 1.46 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
name: Publish to npm
on:
release:
types: [published]
workflow_dispatch:
permissions:
contents: read
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
registry-url: "https://registry.npmjs.org"
- run: npm ci
- name: Check release tag matches package version
if: github.event_name == 'release'
run: |
package_version="$(node -p "require('./package.json').version")"
release_version="${GITHUB_REF_NAME#v}"
if [ "$package_version" != "$release_version" ]; then
echo "Release tag ${GITHUB_REF_NAME} does not match package.json version ${package_version}"
exit 1
fi
- name: Publish to npm
run: |
package_version="$(node -p "require('./package.json').version")"
if npm view "hsluv-sass@${package_version}" version 2>/dev/null; then
echo "hsluv-sass@${package_version} is already published, skipping"
exit 0
fi
if [[ "$package_version" =~ -([a-zA-Z]+) ]]; then
tag="${BASH_REMATCH[1]}"
echo "Publishing prerelease with dist-tag: $tag"
npm publish --provenance --access public --tag "$tag"
else
echo "Publishing stable release"
npm publish --provenance --access public
fi