This repository was archived by the owner on Feb 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
205 lines (204 loc) · 9.07 KB
/
javascript-library.yml
File metadata and controls
205 lines (204 loc) · 9.07 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
###############################################################################
# Javascript Library Workflow
# Build, test and publish a JavaScript Library
###############################################################################
# Assumptions made in this workflow:
# - The branch you create releases from is called 'main'
# - The branch you create canary releases from is called 'develop'
# - You have a GitHub App that allows content changes to the repository
on:
workflow_call:
inputs:
node-versions:
description: 'Node versions to use'
required: false
default: '[20,22,24]'
type: string
publish-node-version:
description: 'Node version to use for publish'
required: false
default: '24'
type: string
pnpm-version:
description: 'PNPM version to use'
required: false
type: string
github-email:
description: 'GitHub email for pushing'
required: false
default: '41898282+github-actions[bot]@users.noreply.github.co'
type: string
github-name:
description: 'GitHub name for pushing'
required: false
default: 'github-actions[bot]'
type: string
site-branch:
description: 'Branch used to publish site to GitHub pages'
type: string
required: false
default: ''
version-dir:
description: 'Directory to change to before running version commands'
type: string
required: false
default: '.'
publish-dir:
description: 'Directory to change to before running publish commands'
type: string
required: false
default: '.'
develop-preid:
description: 'Preid for develop releases'
type: string
required: false
default: 'alpha'
develop-use-timestamp:
description: 'Use timestamps for develop releases'
type: boolean
required: false
default: true
branch-preid:
description: 'Preid for branch releases'
type: string
required: false
default: ''
secrets:
private-key:
description: "GitHub App Key"
required: true
app-id:
description: "GitHub App ID"
required: true
permissions:
contents: write
pages: write
id-token: write
jobs:
javascript-library:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ${{ fromJson(inputs.node-versions) }}
steps:
- name: Generate token
id: app-token
uses: getsentry/action-github-app-token@v3
with:
app_id: ${{ secrets.app-id }}
private_key: ${{ secrets.private-key }}
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ inputs.pnpm-version }}
run_install: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
- name: Get pnpm store directory
run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: "${{ runner.os }}-${{ matrix.node-version }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}"
restore-keys: |
${{ runner.os }}-${{ matrix.node-version }}-pnpm-store-
- name: Install dependencies
run: pnpm i --frozen-lockfile --prefer-offline
- name: Increment main branch version
if: matrix.node-version == inputs.publish-node-version && github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
run: echo VERSION="$(cd ${{ inputs.version-dir }} && pnpm version patch --no-git-tag-version)" >> $GITHUB_ENV
- name: Increment develop branch version
if: matrix.node-version == inputs.publish-node-version && github.ref == 'refs/heads/develop' && github.event_name != 'pull_request' && inputs.develop-use-timestamp == false
run: echo VERSION="$(cd ${{ inputs.version-dir }} && pnpm version prerelease --preid ${{ inputs.develop-preid }} --no-git-tag-version)" >> $GITHUB_ENV
- name: Set develop branch version with timestamp
if: matrix.node-version == inputs.publish-node-version && github.ref == 'refs/heads/develop' && github.event_name != 'pull_request' && inputs.develop-use-timestamp == true
run: |
cd ${{ inputs.version-dir }}
TEMP_VERSION="$(pnpm version prerelease --preid ${{ inputs.develop-preid }} --no-git-tag-version | sed 's/v//')"
echo "TEMP_VERSION=${TEMP_VERSION}" >> $GITHUB_ENV
VERSION="$(echo ${TEMP_VERSION} | sed -E "s/[0-9]+$/$(date +%s)/")"
echo "VERSION=${VERSION}" >> $GITHUB_ENV
sed -i -E "s/${TEMP_VERSION}/${VERSION}/" package.json
- name: Set other branch version with timestamp
if: matrix.node-version == inputs.publish-node-version && github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' && github.event_name != 'pull_request' && inputs.branch-preid != ''
run: |
cd ${{ inputs.version-dir }}
TEMP_VERSION="$(pnpm version prerelease --preid ${{ inputs.branch-preid }} --no-git-tag-version | sed 's/v//')"
echo "TEMP_VERSION=${TEMP_VERSION}" >> $GITHUB_ENV
VERSION="$(echo ${TEMP_VERSION} | sed -E "s/[0-9]+$/$(date +%s)/")"
echo "VERSION=${VERSION}" >> $GITHUB_ENV
sed -i -E "s/${TEMP_VERSION}/${VERSION}/" package.json
- run: pnpm build
- run: pnpm test
- name: Setup git config
if: matrix.node-version == inputs.publish-node-version && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/develop' && inputs.develop-use-timestamp == false))
run: |
git config user.email "${{ inputs.github-email }}"
git config user.name "${{ inputs.github-name }}"
- name: Commit and push version bump
if: matrix.node-version == inputs.publish-node-version && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/develop' && inputs.develop-use-timestamp == false))
run: |
git commit -a -m "$VERSION" -m "GitHub Run Number ${{ github.run_number }}" -m "[skip ci]"
git push
- name: Create tag ${{ env.VERSION }}
if: matrix.node-version == inputs.publish-node-version && github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
run: |
git tag -a "$VERSION" -m "$VERSION"
git push origin "$VERSION"
- name: Create Release
if: matrix.node-version == inputs.publish-node-version && github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: comnoco/create-release-action@v2
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
with:
tag_name: ${{ env.VERSION }}
release_name: Release ${{ env.VERSION }}
draft: false
prerelease: false
- name: Publish canary ${{ env.VERSION }} to registry
if: matrix.node-version == inputs.publish-node-version && (github.ref == 'refs/heads/develop' || (inputs.branch-preid != '' && github.ref != 'refs/heads/main')) && github.event_name != 'pull_request'
run: |
cd ${{ inputs.publish-dir }}
pnpm publish --publish-branch ${GITHUB_REF#refs/heads/} --tag canary --no-git-checks
cd ${{ github.workspace }}
- name: Publish release ${{ env.VERSION }} to registry
if: matrix.node-version == inputs.publish-node-version && github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
run: |
cd ${{ inputs.publish-dir }}
pnpm publish --publish-branch ${GITHUB_REF#refs/heads/}
cd ${{ github.workspace }}
- name: Setup site env
run: echo "SITE_BRANCH_REF=refs/heads/${{ inputs.site-branch }}" >> $GITHUB_ENV
- name: Build Site
if: matrix.node-version == inputs.publish-node-version && github.ref == env.SITE_BRANCH_REF
run: pnpm run site
- name: Setup GitHub Pages
if: matrix.node-version == inputs.publish-node-version && github.ref == env.SITE_BRANCH_REF
uses: actions/configure-pages@v5
- name: Upload Site
if: matrix.node-version == inputs.publish-node-version && github.ref == env.SITE_BRANCH_REF
uses: actions/upload-pages-artifact@v3
with:
path: 'site/'
- name: Deploy to GitHub Pages
if: matrix.node-version == inputs.publish-node-version && github.ref == env.SITE_BRANCH_REF
id: deployment
uses: actions/deploy-pages@v4
- name: Upload artifacts
if: matrix.node-version == inputs.publish-node-version
uses: actions/upload-artifact@v4
with:
name: build-artifact
path: |
*
!node_modules
!**/node_modules