Skip to content

Commit 9d99ede

Browse files
committed
Fixes #7202: Verify integrity of bundled assets in CI
1 parent 4a13ee6 commit 9d99ede

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

Diff for: .github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ jobs:
5858

5959
- name: Check UI ESLint, TypeScript, and Prettier Compliance
6060
run: yarn --cwd netbox/project-static validate
61+
62+
- name: Validate Static Asset Integrity
63+
run: scripts/verify-bundles.sh
6164

6265
- name: Run tests
6366
run: coverage run --source="netbox/" netbox/manage.py test netbox/

Diff for: docs/release-notes/version-3.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [#7169](https://github.com/netbox-community/netbox/issues/7169) - Fix CSV import file upload
1010
* [#7176](https://github.com/netbox-community/netbox/issues/7176) - Fix issue where query parameters were duplicated across different forms of the same type
1111
* [#7193](https://github.com/netbox-community/netbox/issues/7193) - Fix prefix (flat) template issue when viewing child prefixes with prefixes available
12+
* [#7202](https://github.com/netbox-community/netbox/issues/7202) - Verify integrity of static assets in CI
1213

1314
---
1415

Diff for: scripts/verify-bundles.sh

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
# This script verifies the integrity of *bundled* static assets by re-running the bundling process
4+
# and checking for changed files. Because bundle output should not change given the same source
5+
# input, the bundle process shouldn't produce any changes. If they do, it's an indication that
6+
# the dist files have been altered, or that dist files were not committed. In either case, tests
7+
# should fail.
8+
9+
PROJECT_STATIC="$PWD/netbox/project-static"
10+
DIST="$PROJECT_STATIC/dist/"
11+
12+
# Bundle static assets.
13+
bundle() {
14+
echo "Bundling static assets..."
15+
yarn --cwd $PROJECT_STATIC bundle >/dev/null 2>&1
16+
if [[ $? != 0 ]]; then
17+
echo "Error bundling static assets"
18+
exit 1
19+
fi
20+
}
21+
22+
# See if any files have changed.
23+
check_dist() {
24+
local diff=$(git --no-pager diff $DIST)
25+
if [[ $diff != "" ]]; then
26+
local SHA=$(git rev-parse HEAD)
27+
echo "Commit '$SHA' produced different static assets than were committed"
28+
exit 1
29+
fi
30+
}
31+
32+
bundle
33+
check_dist
34+
35+
if [[ $? = 0 ]]; then
36+
echo "Static asset check passed"
37+
exit 0
38+
else
39+
echo "Error checking static asset integrity"
40+
exit 1
41+
fi

0 commit comments

Comments
 (0)