Repository navigation
60 lines (51 loc) · 1.94 KB
/
Copy pathpublish.yml
File metadata and controls
60 lines (51 loc) · 1.94 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
name: Publish to npm
on:
push:
tags:
- 'v*'
permissions:
contents: read
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
environment: npm-publish
steps:
- uses: actions/checkout@v6
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v6
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
cache: pnpm
# The tag decides what gets published. package.json is aligned to it here so
# a forgotten version bump cannot publish the wrong number, or fail on a
# version that is already on the registry.
- name: Read the version from the tag
id: version
run: |
version="${GITHUB_REF_NAME#v}"
if ! printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then
echo "::error::Tag $GITHUB_REF_NAME is not a semver version."
exit 1
fi
if npm view "@nexploy/shared@$version" version --silent >/dev/null 2>&1; then
echo "::error::@nexploy/shared@$version is already published. Tag a new version."
exit 1
fi
declared=$(node -p "require('./package.json').version")
if [ "$declared" != "$version" ]; then
echo "::notice::package.json says $declared, publishing $version from the tag."
fi
case "$version" in
*-*) echo "npm_tag=next" >>"$GITHUB_OUTPUT" ;;
*) echo "npm_tag=latest" >>"$GITHUB_OUTPUT" ;;
esac
echo "version=$version" >>"$GITHUB_OUTPUT"
- run: npm install -g npm@latest
- run: pnpm install --frozen-lockfile
- run: pnpm run typecheck
- run: pnpm run build
- name: Align package.json with the tag
run: npm version "${{ steps.version.outputs.version }}" --no-git-tag-version --allow-same-version
- run: npm publish --provenance --tag ${{ steps.version.outputs.npm_tag }}