-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (69 loc) · 2.4 KB
/
release.yaml
File metadata and controls
86 lines (69 loc) · 2.4 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
name: Release
on:
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js 24.x
uses: actions/setup-node@v4
with:
node-version: 24.x
registry-url: "https://registry.npmjs.org"
cache: "npm"
- name: Use npm 11+
run: npm install -g npm@^11.10.0
- name: Print Node and npm versions
run: |
node -v
npm -v
- name: Read version from package.json
id: package_meta
run: |
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
echo "version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Ensure npm version is not already published
run: |
PKG_NAME="$(node -p "require('./package.json').name")"
VERSION="${{ steps.package_meta.outputs.version }}"
if npm view "${PKG_NAME}@${VERSION}" version >/dev/null 2>&1; then
echo "${PKG_NAME}@${VERSION} is already published on npm."
exit 1
fi
- name: Fail if release tag already exists
run: |
TAG="${{ steps.package_meta.outputs.tag }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists locally."
exit 1
fi
if [ -n "$(git ls-remote --tags origin "refs/tags/$TAG")" ]; then
echo "Tag $TAG already exists on origin."
exit 1
fi
- name: Create and push Git tag
run: |
TAG="${{ steps.package_meta.outputs.tag }}"
git tag "$TAG" "$GITHUB_SHA"
git push origin "refs/tags/$TAG"
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
TAG="${{ steps.package_meta.outputs.tag }}"
NOTES="$(gh api "repos/${GITHUB_REPOSITORY}/releases/generate-notes" -f tag_name="$TAG" -f target_commitish="$GITHUB_SHA" --jq .body)"
gh release create "$TAG" --title "$TAG" --notes "$NOTES" --target "$GITHUB_SHA"
- name: Publish package to npm
run: npm publish --access public