Skip to content

Commit 08d3519

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 08d3519

32 files changed

+3153
-76
lines changed

.gitattributes

+2-1
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

+6
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

+4
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

+1-1
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

+28-2
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,23 @@ 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
4044

41-
- name: Update version of @types/node
45+
- name: Override version of @types/node
4246
if: matrix.node-types-version != 'current'
4347
env:
4448
NODE_TYPES_VERSION: ${{ matrix.node-types-version }}
@@ -52,6 +56,25 @@ jobs:
5256
# `npm install` on Linux.
5357
npm install
5458
59+
# esbuild embeds package.json version details into these files.
60+
# Since the jq step has actively changed package.json, we know that if these files
61+
# are successfully rebuilt (without the changes below), they would be dirty.
62+
#
63+
# In order to allow check-js.sh to verify that it can build them at all, we ignore them,
64+
# delete them, and commit those changes. Thus, when it runs, it will be able to try to
65+
# build them, and as long at they build, it will be happy. If it can't build them, it can
66+
# complain, although that error won't make much sense, because you shouldn't update them
67+
# using the wrong node types version information.
68+
(
69+
echo '*/*-action.js';
70+
echo '*/*-action-post.js'
71+
) >> .gitignore
72+
for action in $(
73+
find * -mindepth 1 -maxdepth 1 -type f -name action.yml
74+
); do
75+
git rm -f "$(dirname "$action")"/*-action*.js
76+
done
77+
5578
if [ ! -z "$(git status --porcelain)" ]; then
5679
git config --global user.email "[email protected]"
5780
git config --global user.name "github-actions[bot]"
@@ -112,6 +135,9 @@ jobs:
112135

113136
steps:
114137
- uses: actions/checkout@v4
138+
- name: Build
139+
run: |
140+
npm run build
115141
- name: npm test
116142
run: |
117143
# Run any commands referenced in package.json using Bash, otherwise

.github/workflows/rebuild.yml

+11-6
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/check-js.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ if [ ! -z "$(git status --porcelain)" ]; then
77
>&2 echo "Failed: Repo should be clean before testing!"
88
exit 1
99
fi
10-
# Wipe the lib directory in case there are extra unnecessary files in there
11-
rm -rf lib
1210
# Generate the JavaScript files
1311
npm run-script build
1412
# Check that repo is still clean
1513
if [ ! -z "$(git status --porcelain)" ]; then
1614
# If we get a fail here then the PR needs attention
17-
>&2 echo "Failed: JavaScript files are not up to date. Run 'rm -rf lib && npm run-script build' to update"
15+
>&2 echo "Failed: JavaScript files are not up to date. Run 'npm run-script build' to update"
1816
git status
1917
exit 1
2018
fi

.github/workflows/script/package.sh

+18
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

-21
This file was deleted.

.github/workflows/update-dependencies.yml

+3-4
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

+5-3
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

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ No user facing changes.
2828

2929
- The CodeQL Action now downloads bundles compressed using Zstandard on GitHub Enterprise Server when using Linux or macOS runners. This speeds up the installation of the CodeQL tools. This feature is already available to GitHub.com users. [#2573](https://github.com/github/codeql-action/pull/2573)
3030
- Update default CodeQL bundle version to 2.19.3. [#2576](https://github.com/github/codeql-action/pull/2576)
31+
- The CodeQL Action is now faster to download by several seconds since `node_modules` are no longer included in this repository. [#2578](https://github.com/github/codeql-action/pull/2578)
3132

3233
## 3.27.0 - 22 Oct 2024
3334

CONTRIBUTING.md

+3-9
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,14 @@ Before you start, ensure that you have a recent version of node (16 or higher) i
1717

1818
### Common tasks
1919

20-
* Transpile the TypeScript to JavaScript: `npm run build`. Note that the JavaScript files are committed to git.
21-
* Run tests: `npm run test`. You’ll need to ensure that the JavaScript files are up-to-date first by running the command above.
22-
* Run the linter: `npm run lint`.
20+
* Transpile the TypeScript to JavaScript: `npm run build`. Note that the bundled action files are committed to git.
21+
* Run tests: `npm run test`. You’ll need to ensure that the `node_modules` are available and JavaScript files are up-to-date first by running the commands above.
22+
* Run the linter: `npm run lint` (requires the first command).
2323

2424
This project also includes configuration to run tests from VSCode (with support for breakpoints) - open the test file you wish to run and choose "Debug AVA test file" from the Run menu in the Run panel.
2525

2626
You may want to run `tsc --watch` from the command line or inside of vscode in order to ensure build artifacts are up to date as you are working.
2727

28-
### Checking in compiled artifacts and `node_modules`
29-
30-
Because CodeQL Action users consume the code directly from this repository, and there can be no build step during an GitHub Actions run, this repository contains all compiled artifacts and node modules. There is a PR check that will fail if any of the compiled artifacts are not up to date. Compiled artifacts are stored in the `lib/` directory. For all day-to-day development purposes, this folder can be ignored.
31-
32-
Only run `npm install` if you are explicitly changing the set of dependencies in `package.json`. The `node_modules` directory should be up to date when you check out, but if for some reason, there is an inconsistency use `npm ci && npm run removeNPMAbsolutePaths` to ensure the directory is in a state consistent with the `package-lock.json`. Note that due to a macOS-specific dependency, this command should be run on a macOS machine. There is a PR check to ensure the consistency of the `node_modules` directory.
33-
3428
### Running the action
3529

3630
To see the effect of your changes and to test them, push your changes in a branch and then look at the [Actions output](https://github.com/github/codeql-action/actions) for that branch. You can also exercise the code locally by running the automated tests.

analyze/action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ outputs:
9292
description: The ID of the uploaded SARIF file.
9393
runs:
9494
using: node20
95-
main: "../lib/analyze-action.js"
96-
post: "../lib/analyze-action-post.js"
95+
main: "analyze-action.js"
96+
post: "analyze-action-post.js"

analyze/analyze-action-post.js

+379
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analyze/analyze-action.js

+230
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

autobuild/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ inputs:
1616
required: false
1717
runs:
1818
using: node20
19-
main: '../lib/autobuild-action.js'
19+
main: 'autobuild-action.js'

autobuild/autobuild-action.js

+180
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eslint.config.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export default [
3131
"tests/**/*",
3232
"eslint.config.mjs",
3333
".github/**/*",
34+
"*/*-action.js",
35+
"*/*-action-post.js",
3436
],
3537
},
3638
...fixupConfigRules(

init/action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,5 @@ outputs:
147147
description: The version of the CodeQL binary used for analysis
148148
runs:
149149
using: node20
150-
main: '../lib/init-action.js'
151-
post: '../lib/init-action-post.js'
150+
main: 'init-action.js'
151+
post: 'init-action-post.js'

init/init-action-post.js

+379
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

init/init-action.js

+187
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)