-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (128 loc) · 3.99 KB
/
publish.yml
File metadata and controls
144 lines (128 loc) · 3.99 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
name: Publish Package
on:
workflow_dispatch:
inputs:
version:
description: 'Version bump type'
required: true
type: choice
options: [patch, minor, major, prepatch, preminor, premajor, prerelease]
custom_version:
description: 'Custom version (optional, overrides version type)'
required: false
type: string
preid:
description: 'Prerelease identifier'
required: false
type: choice
options: [beta, alpha, rc, next]
default: 'beta'
dry_run:
description: 'Dry run (do not actually publish)'
required: false
type: boolean
default: false
tag:
description: 'NPM dist-tag'
required: false
type: choice
options: [latest, next, beta, alpha]
default: 'latest'
concurrency:
group: publish-package
cancel-in-progress: false
permissions:
contents: write
id-token: write
env:
NPM_CONFIG_FUND: false
jobs:
build:
name: Build & Version
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.bump.outputs.new_version }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v4
with:
node-version: '22.14.0'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- name: Version package
id: bump
run: |
CUSTOM="${{ github.event.inputs.custom_version }}"
if [ -n "$CUSTOM" ]; then
npm version "$CUSTOM" --no-git-tag-version --allow-same-version
else
npm version "${{ github.event.inputs.version }}" --no-git-tag-version --preid="${{ github.event.inputs.preid }}"
fi
NEW_VERSION=$(node -p "require('./package.json').version")
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
- run: npm run build
- uses: actions/upload-artifact@v4
with:
name: build-output
path: |
package.json
package-lock.json
dist/
retention-days: 1
publish:
name: Publish to NPM
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22.14.0'
registry-url: 'https://registry.npmjs.org'
- run: npm install -g npm@latest
- uses: actions/download-artifact@v4
with:
name: build-output
path: .
- name: Dry run
if: github.event.inputs.dry_run == 'true'
run: npm publish --dry-run --access public --tag ${{ github.event.inputs.tag }} --ignore-scripts
- name: Publish
if: github.event.inputs.dry_run != 'true'
run: npm publish --access public --provenance --tag ${{ github.event.inputs.tag }} --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
release:
name: Create Release
needs: [build, publish]
runs-on: ubuntu-latest
if: github.event.inputs.dry_run != 'true'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@v4
with:
name: build-output
path: .
- name: Tag and push
env:
NEW_VERSION: ${{ needs.build.outputs.new_version }}
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add package.json package-lock.json
git diff --staged --quiet || git commit -m "chore(release): v${NEW_VERSION}"
git push
git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}"
git push origin "v${NEW_VERSION}"
- uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.build.outputs.new_version }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}