Skip to content

Commit 8a81b41

Browse files
authored
[CI] Add GH workflow to run dev build using submodules at head (#5561)
1 parent 6a6ce10 commit 8a81b41

File tree

3 files changed

+111
-13
lines changed

3 files changed

+111
-13
lines changed

.github/workflows/build-dev.yml

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Dev build
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
submodule_path_regex:
7+
description:
8+
Regex of submodule paths to updated to HEAD before building.
9+
default: content-modules
10+
type: string
11+
12+
jobs:
13+
build-and-test:
14+
name: BUILD and CHECK LINKS
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Create NPM cache-hash input file
20+
run: |
21+
mkdir -p tmp
22+
jq '{devDependencies, dependencies, engines, gitHubActionCacheKey}' package.json > tmp/package-ci.json
23+
24+
- name: Create and use reduced-dependencies package.json
25+
run: |
26+
jq '.devDependencies |= with_entries(
27+
select(.key | test("prefix|hugo|css"))
28+
)
29+
| del(.dependencies, .optionalDependencies)' \
30+
package.json > tmp/package-min.json
31+
cp tmp/package-min.json package.json
32+
33+
- uses: actions/setup-node@v4
34+
with:
35+
node-version-file: .nvmrc
36+
cache: npm
37+
cache-dependency-path: tmp/package-ci.json
38+
39+
- run: npm install --omit=optional
40+
41+
- name: Fetch all submodules at HEAD
42+
run: npm run update:submodule
43+
44+
- name:
45+
Revert to pinned versions of submodules except for
46+
submodule_path_regex
47+
run: npm run _sync -- ${{ inputs.submodule_path_regex }}
48+
49+
- run: npm run log:test-and-fix
50+
continue-on-error: true
51+
env:
52+
GET: no
53+
54+
- uses: actions/upload-artifact@v4
55+
with:
56+
name: build-log-etc
57+
path: |
58+
tmp/build-log.txt
59+
tmp/package*.json
60+
static/refcache.json
61+
62+
check-refcache:
63+
name: REFCACHE updates?
64+
needs: build-and-test
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: actions/checkout@v4
68+
- uses: actions/download-artifact@v4
69+
with: { name: build-log-etc }
70+
- name: Fail when refcache contains entries with HTTP status 4XX
71+
run: |
72+
if grep -B 1 -e '"StatusCode": 4' static/refcache.json; then
73+
echo "Run 'npx gulp prune' to remove 4xx entries from the refcache"
74+
exit 1
75+
fi
76+
- name: Does the refcache need updating?
77+
run: npm run diff:fail
78+
79+
check-build-log-for-issues:
80+
name: WARNINGS in build log?
81+
needs: build-and-test
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: actions/checkout@v4
85+
- uses: actions/download-artifact@v4
86+
with: { name: build-log-etc }
87+
- run: cat tmp/build-log.txt
88+
- run: scripts/check-build-log.sh

package.json

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"Notes": [
3-
"The 'all' runs _all_ named scripts in sequence, even if one fails; and exits with failure in that case."
3+
"The 'all' runs _all_ named scripts in sequence, even if one fails; and exits with failure in that case.",
4+
"check:links actually has the side-effect of 'fixing' the refcache; this is why test-and-fix uses _fix:most"
45
],
56
"scripts": {
67
"__check:links": "make --keep-going check-links",
@@ -20,6 +21,7 @@
2021
"_diff:fail": "git diff --name-only --exit-code || exit 1",
2122
"_fail": "exit 1",
2223
"_filename-error": "echo 'ERROR: the following files violate naming conventions; fix using: `npm run fix:filenames`'; echo; npm run -s _ls-bad-filenames; exit 1",
24+
"_fix:most": "npm run all -- $(npm -s run _list:fix:* | grep -Ev 'refcache|submodule')",
2325
"_get:no": "echo SKIPPING get operation",
2426
"_get:submodule:non-lang": "npm run _get:submodule -- content-modules/opentelemetry-specification themes/docsy",
2527
"_get:submodule": "set -x && git submodule update --init ${DEPTH:- --depth 999}",
@@ -30,13 +32,13 @@
3032
"_list:dict": "grep '^\\s*\"@cspell' package.json | awk -F: '{print $1}' | tr -d '\"'",
3133
"_list:fix:*": "npm run --loglevel=warn | grep -Ee '^\\s*fix:[^:]+$' | grep -v 'fix:all'",
3234
"_ls-bad-filenames": "find assets content static -name '*_*' ! -name '[_.]*'",
35+
"_pin": "scripts/pin-submodules.pl",
3336
"_prebuild": "npm run seq -- get:submodule cp:spec",
3437
"_prepare:docsy": "cd themes/docsy && npm install",
3538
"_prettier:any": "npx prettier --ignore-path ''",
3639
"_rename-to-kebab-case": "find assets content static -name '*_*' ! -name '[_.]*' -exec sh -c 'mv \"$1\" \"${1//_/-}\"' _ {} \\;",
3740
"_serve:hugo": "hugo server --buildDrafts --minify",
3841
"_serve:netlify": "netlify dev -c \"npm run _serve:hugo -- --renderToMemory\"",
39-
"_sync": "scripts/sync-submodules.pl",
4042
"all": "bash -c 'x=0; for c in \"$@\"; do npm run $c || x=$((x+1)); done; ((!x)) || (echo \"ERROR: some scripts failed!\" && exit 1)' -",
4143
"build:preview": "set -x && npm run _build -- --minify",
4244
"build:production": "npm run _hugo -- --minify",
@@ -59,7 +61,7 @@
5961
"cp:spec": "scripts/content-modules/cp-pages.sh",
6062
"diff:check": "npm run _diff:check || (echo; echo 'WARNING: the files above have not been committed'; echo)",
6163
"diff:fail": "npm run _diff:check || (echo; echo 'ERROR: the files above have changed. Locally rerun `npm run test-and-fix` and commit changes'; echo; exit 1)",
62-
"fix:all": "npm run seq -- $(npm -s run _list:fix:*)",
64+
"fix:all": "npm run all -- $(npm -s run _list:fix:*)",
6365
"fix:dict": "find content/en layouts -name \"*.md\" -print0 | xargs -0 scripts/normalize-cspell-front-matter.pl",
6466
"fix:filenames": "npm run _rename-to-kebab-case",
6567
"fix:format": "npm run format",
@@ -69,12 +71,13 @@
6971
"fix:i18n": "npm run fix:i18n:new",
7072
"fix:markdown": "npm run check:markdown -- --fix",
7173
"fix:refcache": "npm run check:links",
72-
"fix:submodules": "npm run _sync",
74+
"fix:submodules": "npm run update:submodule && npm run _pin",
7375
"fix:text": "npm run check:text -- --fix",
7476
"fix": "npm run fix:all",
7577
"format": "npm run _check:format -- --write && npm run _check:format:ja+zh -- --write",
7678
"get:submodule": "npm run _get:${GET:-submodule} --",
7779
"log:check:links": "npm run check:links | tee tmp/build-log.txt",
80+
"log:test-and-fix": "npm run test-and-fix | tee tmp/build-log.txt",
7881
"make:public": "make public ls-public",
7982
"netlify-build:preview": "npm run seq -- build:preview diff:check",
8083
"netlify-build:production": "npm run seq -- build:production diff:check",
@@ -93,17 +96,11 @@
9396
"serve:hugo": "npm run _serve:hugo -- --renderToMemory",
9497
"serve:netlify": "npm run _serve:netlify",
9598
"serve": "npm run serve:hugo --",
96-
"sync": "scripts/sync-submodules.pl",
97-
"test-and-fix": "npm run seq -- check fix:dict fix:filenames",
99+
"test-and-fix": "npm run seq -- fix:submodules _fix:most test",
98100
"test": "npm run check",
99-
"update:docsy-dep": "npm install --save-dev autoprefixer@latest postcss-cli@latest",
100101
"update:htmltest-config": "scripts/htmltest-config.sh",
101-
"update:hugo": "npm install --save-dev --save-exact hugo-extended@latest",
102-
"update:hugo+": "npm run update:hugo && npm run update:docsy-dep",
103-
"update:netlify": "npm install --save-optional netlify-cli@latest",
104-
"update:other-pkg": "npm install --save-dev gulp@latest",
102+
"update:pkg:hugo": "npm install --save-dev --save-exact hugo-extended@latest",
105103
"update:pkgs": "npx npm-check-updates -u",
106-
"update:submodule:lang": "npm run seq -- update:submodule _get:submodule:non-lang",
107104
"update:submodule": "set -x && git submodule update --remote ${DEPTH:- --depth 999}"
108105
},
109106
"devDependencies": {
@@ -157,5 +154,5 @@
157154
"proseWrap": "always",
158155
"singleQuote": true
159156
},
160-
"spelling": "cSpell:ignore docsy elemetry htmltest hugo loglevel netlify nowrap postnetlify prebuild precheck preinstall postbuild postget refcache textlint -"
157+
"spelling": "cSpell:ignore docsy elemetry htmltest hugo loglevel netlify nowrap pkgs postnetlify prebuild precheck preinstall postbuild postget refcache textlint -"
161158
}

scripts/sync-submodules.pl scripts/pin-submodules.pl

+13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
#!/usr/bin/perl -w
2+
#
3+
# Switch submodules to their pinned versions, all submodules by default. Pass
4+
# submodule-path regex to specify submodules to skip.
25

36
use strict;
47
use warnings;
58
use FileHandle;
69

10+
my $submodule_skip_regex = shift @ARGV;
11+
12+
print "Using submodule-path skip regex: $submodule_skip_regex\n\n"
13+
if $submodule_skip_regex;
14+
715
my $file = '.gitmodules';
816
my $fh = FileHandle->new($file, 'r') or die "Error opening $file: $!";
917
my $content = do { local $/; <$fh> };
@@ -17,6 +25,11 @@
1725
my $submodule_path = $submodules[$i];
1826
my $commit = $submodules[$i + 1];
1927

28+
if ($submodule_skip_regex && $submodule_path =~ /$submodule_skip_regex/) {
29+
printf "Skipping $submodule_path\n";
30+
next;
31+
}
32+
2033
my $command = "cd $submodule_path && git switch --detach $commit";
2134
print "> $command\n";
2235
system($command);

0 commit comments

Comments
 (0)