Skip to content

Commit 34f71d6

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 34f71d6

33 files changed

+3154
-108
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: 29 additions & 14 deletions
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 "github-actions@github.com"
5780
git config --global user.name "github-actions[bot]"
@@ -63,17 +86,6 @@ jobs:
6386
- name: Check generated JS
6487
run: .github/workflows/script/check-js.sh
6588

66-
check-node-modules:
67-
if: github.event_name != 'push' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/releases/v')
68-
name: Check modules up to date
69-
runs-on: macos-latest
70-
timeout-minutes: 45
71-
72-
steps:
73-
- uses: actions/checkout@v4
74-
- name: Check node modules up to date
75-
run: .github/workflows/script/check-node-modules.sh
76-
7789
check-file-contents:
7890
if: github.event_name != 'push' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/releases/v')
7991
name: Check file contents
@@ -102,7 +114,7 @@ jobs:
102114
npm-test:
103115
if: github.event_name != 'push' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/releases/v')
104116
name: Unit Test
105-
needs: [check-js, check-node-modules]
117+
needs: check-js
106118
strategy:
107119
fail-fast: false
108120
matrix:
@@ -112,6 +124,9 @@ jobs:
112124

113125
steps:
114126
- uses: actions/checkout@v4
127+
- name: Build
128+
run: |
129+
npm run build
115130
- name: npm test
116131
run: |
117132
# 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/check-js.sh

Lines changed: 1 addition & 3 deletions
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/check-node-modules.sh

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

.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.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy