-
Notifications
You must be signed in to change notification settings - Fork 0
191 lines (157 loc) · 6.69 KB
/
publish.yml
File metadata and controls
191 lines (157 loc) · 6.69 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: Publish package
on:
push:
tags:
- 'v*'
schedule:
- cron: '23 6 * * *'
workflow_dispatch:
inputs:
mode:
description: Release mode
required: true
default: publish
type: choice
options:
- publish
- track-transformers
concurrency:
group: publish-${{ github.workflow }}-${{ github.event_name }}-${{ github.ref_name || github.run_id }}
cancel-in-progress: false
jobs:
publish:
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.mode == 'publish')
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: npm ci
- name: Verify tag matches package version
if: startsWith(github.ref, 'refs/tags/v')
run: |
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
echo "Tag version $TAG_VERSION does not match package.json version $PACKAGE_VERSION"
exit 1
fi
- name: Validate package sources
run: npm run check
- name: Inspect package contents
run: npm pack --dry-run
- name: Publish to npm
run: npm publish --provenance --access public
track-transformers:
if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.mode == 'track-transformers')
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: npm ci
- name: Check upstream Transformers.js version
id: sync
run: node ./scripts/sync-transformers-peer.mjs
- name: Check whether current package version is already published
id: current_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 >/dev/null 2>&1; then
PUBLISHED=true
else
PUBLISHED=false
fi
echo "package_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
echo "version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
echo "published=$PUBLISHED" >> "$GITHUB_OUTPUT"
- name: Check whether current release tag exists on origin
id: current_tag
run: |
TAG="v${{ steps.current_package.outputs.version }}"
if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Nothing to release
if: steps.sync.outputs.changed != 'true' && steps.current_package.outputs.published == 'true' && steps.current_tag.outputs.exists == 'true'
run: |
echo "Peer dependency already tracks @huggingface/transformers ${{ steps.sync.outputs.latest_version }}."
echo "Package version ${{ steps.current_package.outputs.version }} is already published and tagged."
- name: Configure git author
if: steps.sync.outputs.changed == 'true' || steps.current_tag.outputs.exists != 'true'
run: |
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
- name: Sync Transformers.js peer dependency
if: steps.sync.outputs.changed == 'true'
run: node ./scripts/sync-transformers-peer.mjs --write
- name: Bump package version
if: steps.sync.outputs.changed == 'true'
run: npm version patch --no-git-tag-version
- name: Refresh lockfiles
if: steps.sync.outputs.changed == 'true'
run: |
npm install --package-lock-only
npm --prefix example install --package-lock-only
- name: Validate package sources
if: steps.sync.outputs.changed == 'true' || steps.current_package.outputs.published != 'true'
run: |
npm run check
npm pack --dry-run
- name: Capture release version
if: steps.sync.outputs.changed == 'true' || steps.current_package.outputs.published != 'true' || steps.current_tag.outputs.exists != 'true'
id: release
run: |
echo "package_name=$(node -p "require('./package.json').name")" >> "$GITHUB_OUTPUT"
echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
- name: Commit release changes
if: steps.sync.outputs.changed == 'true'
run: |
git add package.json package-lock.json example/package.json example/package-lock.json
git commit -m "chore: track @huggingface/transformers ${{ steps.sync.outputs.latest_version }}"
- name: Push release commit
if: steps.sync.outputs.changed == 'true'
run: git push origin HEAD:${GITHUB_REF_NAME}
- name: Check whether release version is already published
if: steps.sync.outputs.changed == 'true' || steps.current_package.outputs.published != 'true'
id: release_published
run: |
if npm view "${{ steps.release.outputs.package_name }}@${{ steps.release.outputs.version }}" version >/dev/null 2>&1; then
echo "published=true" >> "$GITHUB_OUTPUT"
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish to npm
if: (steps.sync.outputs.changed == 'true' || steps.current_package.outputs.published != 'true') && steps.release_published.outputs.published != 'true'
run: npm publish --provenance --access public
- name: Ensure release tag exists on origin
if: steps.sync.outputs.changed == 'true' || steps.current_package.outputs.published != 'true' || steps.current_tag.outputs.exists != 'true'
run: |
TAG="v${{ steps.release.outputs.version }}"
if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then
echo "${TAG} already exists on origin."
exit 0
fi
git tag "$TAG"
git push origin "$TAG"