-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (73 loc) · 2.47 KB
/
release.yml
File metadata and controls
87 lines (73 loc) · 2.47 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
87
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: Existing semver tag to publish, for example v1.2.3
required: true
permissions:
contents: write
id-token: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- name: Resolve release tag
id: tag
env:
INPUT_TAG: ${{ github.event.inputs.tag }}
run: |
if [ "${GITHUB_EVENT_NAME}" = "push" ]; then
TAG="${GITHUB_REF_NAME}"
else
TAG="${INPUT_TAG}"
fi
if ! printf '%s\n' "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Release tags must match vX.Y.Z"
exit 1
fi
git rev-parse "$TAG" >/dev/null 2>&1
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- name: Check out tagged release commit
run: git checkout "${{ steps.tag.outputs.tag }}"
- name: Set up Node.js for npm publish
uses: actions/setup-node@v6
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Validate package version matches release tag
id: package
run: |
PACKAGE_NAME="$(node -p "require('./package.json').name")"
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
TAG_VERSION="${{ steps.tag.outputs.tag }}"
TAG_VERSION="${TAG_VERSION#v}"
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
echo "package.json version $PACKAGE_VERSION does not match tag ${{ steps.tag.outputs.tag }}"
exit 1
fi
echo "name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
echo "version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
- name: Check whether npm version already exists
id: npm
run: |
if npm view "${{ steps.package.outputs.name }}@${{ steps.package.outputs.version }}" version >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish package to npm
if: steps.npm.outputs.exists != 'true'
run: npm publish --access public
- name: Create GitHub Release
uses: softprops/action-gh-release@v3.0.0
with:
tag_name: ${{ steps.tag.outputs.tag }}
generate_release_notes: true
make_latest: true