-
Notifications
You must be signed in to change notification settings - Fork 554
130 lines (110 loc) · 3.56 KB
/
Copy pathrelease.yml
File metadata and controls
130 lines (110 loc) · 3.56 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
name: Publish package to npm
run-name: npm - publish ${{ inputs.version }} to ${{ inputs.npmDistTag }}
on:
workflow_dispatch:
inputs:
version:
required: true
description: 'SemVer version for npm. (i.e. 1.3.5)'
npmDistTag:
required: true
default: 'latest'
type: choice
options:
- latest
- next
- beta
dryRun:
description: 'Do a dry run (does not publish packages)'
type: boolean
default: true
concurrency:
group: npm-publish
cancel-in-progress: false
jobs:
publish:
timeout-minutes: 25
runs-on: ubuntu-latest
environment: npm-publish
permissions:
contents: write
# required for publishing to npm with --provenance
# see https://docs.npmjs.com/generating-provenance-statements
id-token: write
steps:
- name: Print input
env:
THE_INPUT: '${{ toJson(inputs) }}'
run: |
echo $THE_INPUT
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: actions/setup-node@v5
with:
node-version: 24
registry-url: 'https://registry.npmjs.org'
- name: Upgrade npm for trusted publishing
run: npm install -g npm@latest
- name: Preflight checks
env:
VERSION: ${{ inputs.version }}
NPM_DIST_TAG: ${{ inputs.npmDistTag }}
DRY_RUN: ${{ inputs.dryRun }}
REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
if ! node -e "const v = process.env.VERSION; if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(v)) process.exit(1);"; then
echo "::error::Version '$VERSION' is not valid SemVer."
exit 1
fi
case "$NPM_DIST_TAG" in
latest|next|beta) ;;
*)
echo "::error::npmDistTag '$NPM_DIST_TAG' is not allowed."
exit 1
;;
esac
git fetch --tags --force
if git rev-parse --verify --quiet "refs/tags/$VERSION"; then
echo "::error::Git tag '$VERSION' already exists."
exit 1
fi
if npm view "opentype.js@$VERSION" version >/dev/null 2>&1; then
echo "::error::npm version '$VERSION' already exists."
exit 1
fi
if [ "$DRY_RUN" != "true" ] && [ "$REF_NAME" != "master" ]; then
echo "::error::Real releases must run from the master branch."
exit 1
fi
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Make dist files
run: npm run dist
- name: Run tests
run: npm run test
- name: Set version in package*.json
run: npm pkg set version=${{ inputs.version }}
- name: Publish package to npm
run: npm publish --access public --tag ${{ inputs.npmDistTag }} ${{ env.DRY_RUN }}
env:
DRY_RUN: ${{ inputs.dryRun && '--dry-run' || '' }}
- name: Create git tag
if: ${{ !inputs.dryRun }}
env:
VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag "$VERSION"
git push origin "$VERSION"
- name: Create GitHub release
if: ${{ !inputs.dryRun }}
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ inputs.version }}
run: gh release create "$VERSION" --title "$VERSION" --generate-notes