Skip to content

Commit eddc244

Browse files
committed
Bundle action using esbuild
Instead of using a bundled node_modules, * Run `npm install` before performing various tasks Change pr-checks to not be particularly picky about the generated content because it will differ between different versions as everything is bundled together.
1 parent db6ee56 commit eddc244

31 files changed

+3142
-73
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
lib/*.js linguist-generated=true
1+
*/*-action.js linguist-generated=true
2+
*/*-action-post.js linguist-generated=true
23
.github/workflows/__* linguist-generated=true
34

45
# Reduce incidence of needless merge conflicts on CHANGELOG.md

.github/actions/prepare-test/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ outputs:
1919
runs:
2020
using: composite
2121
steps:
22+
- name: npm install
23+
shell: bash
24+
run: |
25+
if command -v npm >/dev/null 2>/dev/null; then
26+
npm ci
27+
fi
2228
- name: Move codeql-action
2329
shell: bash
2430
run: |

.github/actions/update-bundle/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ runs:
88
shell: bash
99
run: npm install -g ts-node
1010

11+
- name: Install
12+
shell: bash
13+
run: npm ci
14+
1115
- name: Run update script
1216
working-directory: ${{ github.action_path }}
1317
shell: bash

.github/actions/update-bundle/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async function main() {
5858
const previousDefaults: Defaults = JSON.parse(fs.readFileSync('../../../src/defaults.json', 'utf8'));
5959
const newDefaults = await getNewDefaults(previousDefaults);
6060
// Update the source file in the repository. Calling workflows should subsequently rebuild
61-
// the Action to update `lib/defaults.json`.
61+
// the Action.
6262
fs.writeFileSync('../../../src/defaults.json', JSON.stringify(newDefaults, null, 2) + "\n");
6363
}
6464

.github/workflows/pr-checks.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@ jobs:
2626
- name: Checkout
2727
uses: actions/checkout@v4
2828

29+
- name: Install
30+
shell: bash
31+
run: npm install
32+
2933
- name: Lint
3034
id: lint
3135
run: npm run-script lint-ci
3236

3337
- name: Upload sarif
3438
uses: github/codeql-action/upload-sarif@v3
3539
# Only upload SARIF for the latest version of Node.js
36-
if: "!cancelled() && matrix.node-types-version == 'current' && !startsWith(github.head_ref, 'dependabot/')"
40+
if: ${{ !cancelled() && matrix.node-types-version == 'current' && !startsWith(github.head_ref, 'dependabot/') }}
3741
with:
3842
sarif_file: eslint.sarif
3943
category: eslint
@@ -52,6 +56,16 @@ jobs:
5256
# `npm install` on Linux.
5357
npm install
5458
59+
(
60+
echo '*/*-action.js';
61+
echo '*/*-action-post.js'
62+
) >> .gitignore
63+
for action in $(
64+
find * -mindepth 1 -maxdepth 1 -type f -name action.yml
65+
); do
66+
git rm -f "$(dirname "$action")"/*-action*.js
67+
done
68+
5569
if [ ! -z "$(git status --porcelain)" ]; then
5670
git config --global user.email "github-actions@github.com"
5771
git config --global user.name "github-actions[bot]"
@@ -112,6 +126,9 @@ jobs:
112126

113127
steps:
114128
- uses: actions/checkout@v4
129+
- name: Build
130+
run: |
131+
npm run build
115132
- name: npm test
116133
run: |
117134
# Run any commands referenced in package.json using Bash, otherwise

.github/workflows/rebuild.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,19 @@ jobs:
3131
run: |
3232
git fetch origin "$BASE_BRANCH"
3333
34-
# Allow merge conflicts in `lib`, since rebuilding should resolve them.
34+
# Allow merge conflicts in `action(-post|-pre|).js`, since rebuilding should resolve them.
3535
git merge "origin/$BASE_BRANCH" || echo "Merge conflicts detected"
3636
37-
# Check for merge conflicts outside of `lib`. Disable git diff's trailing whitespace check
38-
# since `node_modules/@types/semver/README.md` fails it.
39-
if git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/'; then
40-
echo "Merge conflicts detected outside of lib/ directory. Please resolve them manually."
41-
git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/' || true
37+
git_diff_ignore_generated_actions() {
38+
git diff --check |
39+
grep --invert-match -- '-action-pre\.js$' |
40+
grep --invert-match -- '-action\.js$' |
41+
grep --invert-match -- '-action-post\.js$'
42+
}
43+
44+
if git_diff_ignore_generated_actions | grep -q .; then
45+
echo "Merge conflicts detected outside of generated action js files. Please resolve them manually."
46+
git_diff_ignore_generated_actions || true
4247
exit 1
4348
fi
4449

.github/workflows/script/package.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
bundle_file() {
3+
module=$(dirname "$1")
4+
file=$(perl -ne 'next unless m<'"$2"': .(?:.*/|)(.*\.js)>;print $1' "$1")
5+
if [ -n "$file" ]; then
6+
if [ "$2" = main ]; then
7+
suffix=''
8+
else
9+
suffix="-$2"
10+
fi
11+
./node_modules/.bin/esbuild "lib/$module-action$suffix.js" --bundle --minify --platform=node --outfile="./$module/$file"
12+
perl -pi -e 's/scripts:\{.*?\}/scripts:{}/' "./$module/$file"
13+
fi
14+
};
15+
for a in */action.yml; do
16+
bundle_file $a main;
17+
bundle_file $a post;
18+
done

.github/workflows/script/update-node-modules.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/update-dependencies.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ jobs:
2828
run: |
2929
git fetch origin "$BRANCH" --depth=1
3030
git checkout "origin/$BRANCH"
31-
.github/workflows/script/update-node-modules.sh update
31+
npm run build
3232
if [ ! -z "$(git status --porcelain)" ]; then
3333
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
3434
git config --global user.name "github-actions[bot]"
35-
git add node_modules
36-
git commit -am "Update checked-in dependencies"
35+
git commit -am "Update action bundles"
3736
git push origin "HEAD:$BRANCH"
38-
echo "Pushed a commit to update the checked-in dependencies." \
37+
echo "Pushed a commit to update the checked-in action bundles." \
3938
"Please mark the PR as ready for review to trigger PR checks." |
4039
gh pr comment --body-file - --repo github/codeql-action "${{ github.event.pull_request.number }}"
4140
gh pr ready --undo --repo github/codeql-action "${{ github.event.pull_request.number }}"

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# Ignore for example failing-tests.json from AVA
2-
node_modules/.cache/
1+
# actions are bundled to make this repository lightweight for consumers
2+
node_modules/
3+
# lib is generated by tsc
4+
lib
35
# Java build files
46
.gradle/
57
*.class
@@ -8,4 +10,4 @@ node_modules/.cache/
810
# eslint sarif report
911
eslint.sarif
1012
# for local incremental compilation
11-
tsconfig.tsbuildinfo
13+
tsconfig.tsbuildinfo

0 commit comments

Comments
 (0)