-
-
Notifications
You must be signed in to change notification settings - Fork 8
155 lines (130 loc) · 4.36 KB
/
Copy pathrelease.yml
File metadata and controls
155 lines (130 loc) · 4.36 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Release
on:
push:
tags:
- '*.*.*'
workflow_dispatch:
inputs:
release_tag:
description: 'Release tag to publish, for example 2026.05.09'
required: true
type: string
permissions:
contents: read
concurrency:
group: release-${{ github.event_name == 'workflow_dispatch' && inputs.release_tag || github.ref }}
cancel-in-progress: false
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.release_tag || github.ref_name }}
jobs:
validate:
name: Validate package
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
- name: Normalize release version
run: node .github/scripts/normalize-release-version.js
- name: Install dependencies
run: |
if [ -f package-lock.json ]; then
npm ci
else
npm install
fi
- name: Run tests
run: npm run test --if-present
- name: Run lint
run: npm run lint --if-present
- name: Preview package contents
run: npm pack --dry-run
publish-npm:
name: Publish to npm
runs-on: ubuntu-latest
needs: validate
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Node.js for npm
uses: actions/setup-node@v6
with:
node-version: 24
registry-url: 'https://registry.npmjs.org'
package-manager-cache: false
- name: Normalize release version
run: node .github/scripts/normalize-release-version.js
- name: Install dependencies
run: |
if [ -f package-lock.json ]; then
npm ci
else
npm install
fi
- name: Check npm package version
id: npm-package
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" version --registry=https://registry.npmjs.org >/dev/null 2>&1; then
echo "${PACKAGE_NAME}@${PACKAGE_VERSION} already exists on npm. Skipping publish."
echo "exists=true" >> "${GITHUB_OUTPUT}"
else
echo "${PACKAGE_NAME}@${PACKAGE_VERSION} does not exist on npm. Publishing."
echo "exists=false" >> "${GITHUB_OUTPUT}"
fi
- name: Publish to npm
if: steps.npm-package.outputs.exists != 'true'
run: npm publish --access public
publish-github-packages:
name: Publish to GitHub Packages
runs-on: ubuntu-latest
needs: validate
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Node.js for GitHub Packages
uses: actions/setup-node@v6
with:
node-version: 22
registry-url: 'https://npm.pkg.github.com/'
scope: '@markbattistella'
cache: npm
- name: Normalize release version
run: node .github/scripts/normalize-release-version.js
- name: Install dependencies
run: |
if [ -f package-lock.json ]; then
npm ci
else
npm install
fi
- name: Check GitHub Packages version
id: github-package
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" version --registry=https://npm.pkg.github.com/ >/dev/null 2>&1; then
echo "${PACKAGE_NAME}@${PACKAGE_VERSION} already exists on GitHub Packages. Skipping publish."
echo "exists=true" >> "${GITHUB_OUTPUT}"
else
echo "${PACKAGE_NAME}@${PACKAGE_VERSION} does not exist on GitHub Packages. Publishing."
echo "exists=false" >> "${GITHUB_OUTPUT}"
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to GitHub Packages
if: steps.github-package.outputs.exists != 'true'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}