-
Notifications
You must be signed in to change notification settings - Fork 679
73 lines (57 loc) · 2.09 KB
/
publish.yml
File metadata and controls
73 lines (57 loc) · 2.09 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
name: Publish to npm
on:
workflow_dispatch:
permissions:
contents: write
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: npm install --legacy-peer-deps --ignore-scripts
- name: Build
run: npm run build
- name: Typecheck
run: npm run typecheck
- name: Verify package is unpublished
id: package
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
PACKAGE_VERSION=$(node -p "require('./package.json').version")
TAG_NAME="v${PACKAGE_VERSION}"
echo "name=${PACKAGE_NAME}" >> "$GITHUB_OUTPUT"
echo "version=${PACKAGE_VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG_NAME}" >> "$GITHUB_OUTPUT"
if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" version >/dev/null 2>&1; then
echo "${PACKAGE_NAME}@${PACKAGE_VERSION} is already published"
exit 1
fi
if git ls-remote --exit-code --tags origin "refs/tags/${TAG_NAME}" >/dev/null 2>&1; then
echo "${TAG_NAME} already exists"
exit 1
fi
- name: Publish
run: npm publish --provenance
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
PACKAGE_NAME: ${{ steps.package.outputs.name }}
PACKAGE_VERSION: ${{ steps.package.outputs.version }}
TAG_NAME: ${{ steps.package.outputs.tag }}
run: |
awk "/^## v${PACKAGE_VERSION}$/{flag=1; next} /^## /{flag=0} flag" CHANGELOG.md > release-notes.md
if [ ! -s release-notes.md ]; then
echo "Published ${PACKAGE_NAME}@${PACKAGE_VERSION} to npm." > release-notes.md
fi
gh release create "${TAG_NAME}" \
--target "${GITHUB_SHA}" \
--title "${TAG_NAME}" \
--notes-file release-notes.md