Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
275 lines (254 loc) · 11.4 KB
/
Copy pathaction.yml
File metadata and controls
275 lines (254 loc) · 11.4 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
name: "Update Manifest and Commit Changes"
description: "Checks out the repository, sets up Node, installs dependencies, updates manifest.json, formats, and commits/pushes changes signing the commit."
inputs:
action:
description: "Action to perform: publish or delete the artifact branch."
required: false
default: "publish"
manifestPath:
description: "The path to the manifest.json file."
required: false
default: "${{ github.workspace }}/manifest.json"
schemaPath:
description: "The path to the plugin settings schema."
required: false
default: "${{ github.workspace }}/src/types/plugin-input.ts"
pluginEntry:
description: "The path to the plugin entry file."
required: false
default: "${{ github.workspace }}/src/index.ts"
commitMessage:
description: "The commit message."
required: false
default: "chore: [skip ci] updated manifest.json and dist build"
sourceRef:
description: "Source branch ref used for short_name and artifact branch mapping."
required: false
default: "${{ github.event_name == 'delete' && github.event.ref || github.event.workflow_run.head_branch || github.ref_name }}"
artifactPrefix:
description: "Prefix used for artifact branches."
required: false
default: "dist/"
nodeVersion:
description: "The version of Node.js to use."
default: "24.11.0"
treatAsEsm:
description: "If the package is set to be treated as ESM, it will replace __dirname occurrences."
default: "false"
bundleSingleFile:
description: "Bundle plugin entry into a single file (disables code splitting)."
default: "false"
sourcemap:
description: "Generates the sourcemap for the compiled files"
required: false
default: "false"
skipBotEvents:
description: "Sets manifest.skipBotEvents (true/false)."
required: false
default: "true"
excludeSupportedEvents:
description: "Comma-separated supported events to remove from generated manifest listeners."
required: false
default: ""
outputs: {}
runs:
using: "composite"
steps:
- name: Validate action input
shell: bash
run: |
if [[ "${{ inputs.action }}" != "publish" && "${{ inputs.action }}" != "delete" ]]; then
echo "::error::Invalid action '${{ inputs.action }}'. Must be 'publish' or 'delete'."
exit 1
fi
- name: Resolve source and artifact refs
id: resolve_refs
shell: bash
env:
SOURCE_REF_INPUT: ${{ inputs.sourceRef }}
ARTIFACT_PREFIX_INPUT: ${{ inputs.artifactPrefix }}
EVENT_REF_TYPE: ${{ github.event.ref_type || '' }}
run: |
source_ref="$SOURCE_REF_INPUT"
source_ref="${source_ref#refs/heads/}"
source_ref="${source_ref#refs/tags/}"
if [ -z "$source_ref" ]; then
source_ref="${GITHUB_REF_NAME}"
fi
artifact_prefix="$ARTIFACT_PREFIX_INPUT"
if [ -z "$artifact_prefix" ]; then
artifact_prefix="dist/"
fi
artifact_prefix="${artifact_prefix#refs/heads/}"
if [[ "$artifact_prefix" != */ ]]; then
artifact_prefix="${artifact_prefix}/"
fi
is_tag_ref="false"
if [[ "$EVENT_REF_TYPE" == "tag" ]] || [[ "${GITHUB_REF:-}" == refs/tags/* ]]; then
is_tag_ref="true"
fi
is_artifact_ref="false"
if [[ "$source_ref" == "$artifact_prefix"* ]]; then
is_artifact_ref="true"
fi
should_skip="false"
skip_reason=""
if [[ "$is_tag_ref" == "true" ]]; then
should_skip="true"
skip_reason="tag refs are not supported"
elif [[ "$is_artifact_ref" == "true" ]]; then
should_skip="true"
skip_reason="artifact refs are ignored"
fi
echo "source_ref=$source_ref" >> "$GITHUB_OUTPUT"
echo "artifact_prefix=$artifact_prefix" >> "$GITHUB_OUTPUT"
echo "is_tag_ref=$is_tag_ref" >> "$GITHUB_OUTPUT"
echo "is_artifact_ref=$is_artifact_ref" >> "$GITHUB_OUTPUT"
echo "should_skip=$should_skip" >> "$GITHUB_OUTPUT"
echo "skip_reason=$skip_reason" >> "$GITHUB_OUTPUT"
echo "SOURCE_REF=$source_ref" >> "$GITHUB_ENV"
echo "ARTIFACT_PREFIX=$artifact_prefix" >> "$GITHUB_ENV"
- name: Skip unsupported refs
if: ${{ steps.resolve_refs.outputs.should_skip == 'true' }}
shell: bash
env:
SOURCE_REF: ${{ steps.resolve_refs.outputs.source_ref }}
SKIP_REASON: ${{ steps.resolve_refs.outputs.skip_reason }}
run: |
echo "::notice::Skipping action for '${SOURCE_REF}' (${SKIP_REASON})."
- name: Check out the repository
if: ${{ inputs.action == 'publish' && steps.resolve_refs.outputs.should_skip != 'true' }}
uses: actions/checkout@v6
with:
ref: ${{ steps.resolve_refs.outputs.source_ref }}
- name: Set up Node.js
if: ${{ steps.resolve_refs.outputs.should_skip != 'true' }}
uses: actions/setup-node@v6
with:
node-version: ${{ inputs.nodeVersion }}
- name: Set up Deno
if: ${{ steps.resolve_refs.outputs.should_skip != 'true' }}
uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- uses: oven-sh/setup-bun@v2
if: ${{ steps.resolve_refs.outputs.should_skip != 'true' }}
- name: Install dependencies
if: ${{ inputs.action == 'publish' && steps.resolve_refs.outputs.should_skip != 'true' }}
shell: bash
run: |
# Keep project install-time generators (if any) available for builds.
bun install --frozen-lockfile
- name: Prepare manifest configuration JSON
if: ${{ inputs.action == 'publish' && steps.resolve_refs.outputs.should_skip != 'true' }}
shell: bash
env:
MANIFEST_PATH: ${{ inputs.manifestPath }}
SKIP_BOT_EVENTS: ${{ inputs.skipBotEvents }}
EXCLUDE_SUPPORTED_EVENTS: ${{ inputs.excludeSupportedEvents }}
GITHUB_WORKSPACE: ${{ github.workspace }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF_NAME: ${{ steps.resolve_refs.outputs.source_ref }}
run: |
echo "Resolved SKIP_BOT_EVENTS=${SKIP_BOT_EVENTS}"
node ${{ github.action_path }}/.github/scripts/update-manifest.js
- name: Build project
if: ${{ inputs.action == 'publish' && steps.resolve_refs.outputs.should_skip != 'true' }}
shell: bash
run: |
echo "Deleting previous dist..."
rm -rf "${{ github.workspace }}/dist"
if [ "${{ inputs.bundleSingleFile }}" = "true" ]; then
echo "Compiling plugin (single file)..."
bun x esbuild ${{ inputs.pluginEntry }} --bundle --platform=node --format=esm --target=node20 --minify ${{ inputs.sourcemap == 'true' && '--sourcemap' || '' }} --external:./tests --outfile=dist/plugin/index.js
echo "Compiling plugin types (single file)..."
bun x esbuild ${{ inputs.schemaPath }} --bundle --platform=node --format=esm --target=node20 --minify --outfile=plugin/index.js
else
echo "Compiling plugin..."
bun x @vercel/ncc build ${{ inputs.pluginEntry }} --external "./tests" -m ${{ inputs.sourcemap == 'true' && '-s' || '' }} -o dist/plugin
echo "Compiling plugin types..."
bun x @vercel/ncc build ${{ inputs.schemaPath }} --external "./tests" -m -o plugin
fi
- name: Replace __dirname with import.meta.dirname
if: ${{ inputs.action == 'publish' && inputs.treatAsEsm && steps.resolve_refs.outputs.should_skip != 'true' }}
shell: bash
run: |
if [ "${{ inputs.treatAsEsm }}" = "true" ]; then
sed -i 's/__dirname/import.meta.dirname/g' "${{ github.workspace }}/dist/plugin/index.js"
fi
- name: Finalize manifest configuration JSON
if: ${{ inputs.action == 'publish' && steps.resolve_refs.outputs.should_skip != 'true' }}
shell: bash
env:
MANIFEST_PATH: ${{ inputs.manifestPath }}
SKIP_BOT_EVENTS: ${{ inputs.skipBotEvents }}
EXCLUDE_SUPPORTED_EVENTS: ${{ inputs.excludeSupportedEvents }}
GITHUB_WORKSPACE: ${{ github.workspace }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF_NAME: ${{ steps.resolve_refs.outputs.source_ref }}
run: |
node ${{ github.action_path }}/.github/scripts/update-manifest.js
- name: Get GitHub App token
if: env.APP_ID != '' && env.APP_PRIVATE_KEY != '' && steps.resolve_refs.outputs.should_skip != 'true'
uses: actions/create-github-app-token@v1
id: get_installation_token
with:
app-id: ${{ env.APP_ID }}
private-key: ${{ env.APP_PRIVATE_KEY }}
- name: Install push script dependencies
if: ${{ steps.resolve_refs.outputs.should_skip != 'true' }}
shell: bash
run: |
echo "Installing dependencies for the push script in ${{ github.action_path }}"
cd ${{ github.action_path }}
bun install
- name: Inject reassembly entrypoints
if: ${{ inputs.action == 'publish' && steps.resolve_refs.outputs.should_skip != 'true' }}
shell: bash
env:
TREAT_AS_ESM: ${{ inputs.treatAsEsm }}
run: |
if [[ "${TREAT_AS_ESM}" == "true" ]]; then
if [ ! -f dist/plugin/package.json ]; then
printf '{"type":"module"}\n' > dist/plugin/package.json
fi
cp "${{ github.action_path }}/.github/scripts/reassembly-esm.js" dist/index.js
printf '%s\n' \
'import("./index.js").catch((error) => {' \
' console.error("Failed to load dist/index.js from CJS bridge:", error);' \
' process.exit(1);' \
'});' > dist/index.cjs
cp dist/plugin/package.json dist/package.json
else
cp "${{ github.action_path }}/.github/scripts/reassembly-cjs.js" dist/index.js
cp "${{ github.action_path }}/.github/scripts/reassembly-cjs.js" dist/index.cjs
fi
- name: Publish manifest.json and dist to artifact branch
if: ${{ inputs.action == 'publish' && steps.resolve_refs.outputs.should_skip != 'true' }}
shell: bash
env:
GITHUB_TOKEN: ${{ steps.get_installation_token.outputs.token || github.token }}
GITHUB_WORKSPACE: ${{ github.workspace }}
COMMIT_MESSAGE: ${{ inputs.commitMessage }}
MANIFEST_PATH: ${{ inputs.manifestPath }}
SOURCE_REF: ${{ steps.resolve_refs.outputs.source_ref }}
ARTIFACT_PREFIX: ${{ steps.resolve_refs.outputs.artifact_prefix }}
run: |
# Enforce final manifest values after all build-time lifecycle scripts.
echo "Re-applying manifest before publish with SKIP_BOT_EVENTS=${{ inputs.skipBotEvents }}"
SKIP_BOT_EVENTS="${{ inputs.skipBotEvents }}" \
EXCLUDE_SUPPORTED_EVENTS="${{ inputs.excludeSupportedEvents }}" \
GITHUB_WORKSPACE="${{ github.workspace }}" \
GITHUB_REPOSITORY="${{ github.repository }}" \
GITHUB_REF_NAME="${{ steps.resolve_refs.outputs.source_ref }}" \
node ${{ github.action_path }}/.github/scripts/update-manifest.js
bun ${{ github.action_path }}/.github/scripts/push-changes.js
- name: Delete artifact branch
if: ${{ inputs.action == 'delete' && steps.resolve_refs.outputs.should_skip != 'true' }}
shell: bash
env:
GITHUB_TOKEN: ${{ steps.get_installation_token.outputs.token || github.token }}
SOURCE_REF: ${{ steps.resolve_refs.outputs.source_ref }}
ARTIFACT_PREFIX: ${{ steps.resolve_refs.outputs.artifact_prefix }}
run: |
bun ${{ github.action_path }}/.github/scripts/delete-artifact-branch.js