|
| 1 | +name: Licence compliance |
| 2 | + |
| 3 | +# Makes the licence position self-enforcing. |
| 4 | +# |
| 5 | +# The distribution model here is the strictest of the three AI Studio repos. |
| 6 | +# aistudio-server conveys container images; aistudio-app serves a JS bundle; |
| 7 | +# this ships a compiled Go binary that STATICALLY LINKS every dependency. There |
| 8 | +# is no node_modules or site-packages beside the artifact for notices to live |
| 9 | +# in — the binary is the whole distribution, so the notices have to be inside |
| 10 | +# it. These checks confirm they are. |
| 11 | + |
| 12 | +on: |
| 13 | + push: |
| 14 | + branches: [master, main] |
| 15 | + pull_request: |
| 16 | + schedule: |
| 17 | + # Weekly. Upstream modules change licences occasionally and silently. |
| 18 | + - cron: "0 6 * * 1" |
| 19 | + workflow_dispatch: |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + |
| 24 | +env: |
| 25 | + GO_VERSION: "1.25" |
| 26 | + |
| 27 | +jobs: |
| 28 | + files: |
| 29 | + name: Licence files and bench UI assets |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Static compliance checks |
| 35 | + # Same target as `make compliance` locally, so the feedback loop does |
| 36 | + # not require a push. Covers LICENSE completeness and filled-in |
| 37 | + # copyright, required files, no CDN references in the bench UI, and that |
| 38 | + # the vendored fonts and Chart.js are present with their licences. |
| 39 | + # |
| 40 | + # Needs no Go toolchain and no network, deliberately — these are the |
| 41 | + # checks anyone should be able to run on any checkout. The placeholder |
| 42 | + # state is reported here, not failed on; that is the `build` job's job. |
| 43 | + run: make compliance |
| 44 | + |
| 45 | + - name: Vendored UI assets match their declared versions |
| 46 | + run: | |
| 47 | + # These binaries are committed (go:embed needs them at compile time |
| 48 | + # and `go build` cannot run npm), so nothing stops someone editing |
| 49 | + # them by hand. Regenerate into a scratch dir and compare. |
| 50 | + VENDOR_DEST=/tmp/vendor-check ./scripts/vendor-ui-assets.sh |
| 51 | + if ! diff -r /tmp/vendor-check ai-studio-cli/internal/benchui/ui/vendor; then |
| 52 | + echo "::error::vendored UI assets differ from a clean regeneration." |
| 53 | + echo "Run ./scripts/vendor-ui-assets.sh and commit the result." |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | + echo "Vendored assets reproduce exactly." |
| 57 | +
|
| 58 | + - name: Every font referenced by fonts.css exists |
| 59 | + run: | |
| 60 | + # Guards against a weight being added to the script's list and |
| 61 | + # shipping as a CSS rule with no file behind it — which go:embed |
| 62 | + # would happily compile into the binary. |
| 63 | + cd ai-studio-cli/internal/benchui/ui/vendor |
| 64 | + missing=0 |
| 65 | + for url in $(grep -oE 'url\("\./[^"]+"\)' fonts.css | sed -E 's|url\("\./||; s|"\)||'); do |
| 66 | + [ -f "$url" ] || { echo "::error::fonts.css references missing $url"; missing=1; } |
| 67 | + done |
| 68 | + exit $missing |
| 69 | +
|
| 70 | + build: |
| 71 | + name: Build with generated notices and verify the binary carries them |
| 72 | + runs-on: ubuntu-latest |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v4 |
| 75 | + |
| 76 | + - uses: actions/setup-go@v5 |
| 77 | + with: |
| 78 | + go-version: ${{ env.GO_VERSION }} |
| 79 | + cache-dependency-path: ai-studio-cli/go.sum |
| 80 | + |
| 81 | + - name: Generate notices and build |
| 82 | + # Generation happens HERE rather than being compared against a committed |
| 83 | + # copy. An earlier version of this workflow diffed the generated output |
| 84 | + # against a file in the repo, which meant a reviewable branch could not |
| 85 | + # exist without a Go toolchain and network access, and every dependency |
| 86 | + # bump carried a regenerate-and-commit step whose only failure mode was |
| 87 | + # a red build with a misleading message. |
| 88 | + # |
| 89 | + # `go list -deps` answers the only question that matters: which modules |
| 90 | + # are actually linked into this binary — not everything in go.sum, which |
| 91 | + # also lists test and tooling modules that never reach a user. |
| 92 | + run: make build-release |
| 93 | + |
| 94 | + - name: "`licenses` prints real notices" |
| 95 | + # The check that actually matters. Everything else verifies files exist |
| 96 | + # in a repository; this verifies the notices are inside the artifact a |
| 97 | + # user receives, which is what the obligation is. |
| 98 | + run: | |
| 99 | + out=$(./bin/ai-studio-cli licenses 2>&1) || { |
| 100 | + echo "::error::\`bin/ai-studio-cli licenses\` failed:" |
| 101 | + echo "$out" |
| 102 | + exit 1 |
| 103 | + } |
| 104 | +
|
| 105 | + if grep -q "NOTICES-NOT-GENERATED" <<<"$out"; then |
| 106 | + echo "::error::the binary embeds the placeholder — make build-release did not generate them." |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | +
|
| 110 | + copyrights=$(grep -ci "copyright" <<<"$out" || true) |
| 111 | + if [ "$copyrights" -lt 10 ]; then |
| 112 | + echo "::error::only $copyrights copyright notices in the binary output — expected 10+." |
| 113 | + exit 1 |
| 114 | + fi |
| 115 | + echo "$copyrights copyright notices embedded." |
| 116 | +
|
| 117 | + # The go:embed'd UI assets are not Go modules, so the module walk |
| 118 | + # cannot see them. generate-notices.sh appends them; confirm it did. |
| 119 | + grep -qi "SIL Open Font License" <<<"$out" || { |
| 120 | + echo "::error::OFL-1.1 text missing, but Inter is embedded (OFL s2)." |
| 121 | + exit 1 |
| 122 | + } |
| 123 | + grep -qi "chart.js" <<<"$out" || { |
| 124 | + echo "::error::Chart.js attribution missing, but it is embedded (MIT)." |
| 125 | + exit 1 |
| 126 | + } |
| 127 | + echo "Embedded UI asset notices present." |
| 128 | +
|
| 129 | + - name: Bench UI serves no external assets |
| 130 | + run: | |
| 131 | + # Belt and braces against the Makefile check: assert the reference is |
| 132 | + # absent from the compiled binary, not just from the source tree. |
| 133 | + # |
| 134 | + # Matches a LOADING position (`="https://host`), not any mention of a |
| 135 | + # hostname. index.html carries a comment explaining why the Google |
| 136 | + # Fonts links were removed, and that comment names the hostname — it is |
| 137 | + # embedded verbatim by go:embed, so a bare hostname grep matches our own |
| 138 | + # documentation and fails the build. It did exactly that on the first |
| 139 | + # run of this check. |
| 140 | + # |
| 141 | + # The `="` prefix is what separates markup from prose: a real |
| 142 | + # regression looks like `<link href="https://fonts.googleapis.com/...`. |
| 143 | + if strings ./bin/ai-studio-cli \ |
| 144 | + | grep -nE '=["'"'"']https?://(fonts\.(googleapis|gstatic)\.com|cdn\.|unpkg\.com|cdnjs\.|.*jsdelivr)'; then |
| 145 | + echo "::error::the compiled binary loads an asset from a third-party origin (above)." |
| 146 | + exit 1 |
| 147 | + fi |
| 148 | + echo "No third-party asset loads in the binary." |
| 149 | +
|
| 150 | + - uses: actions/upload-artifact@v4 |
| 151 | + if: always() |
| 152 | + with: |
| 153 | + name: third-party-notices |
| 154 | + path: ai-studio-cli/internal/notices/THIRD-PARTY-NOTICES.txt |
| 155 | + if-no-files-found: warn |
| 156 | + |
| 157 | + vet: |
| 158 | + name: go vet |
| 159 | + runs-on: ubuntu-latest |
| 160 | + steps: |
| 161 | + - uses: actions/checkout@v4 |
| 162 | + - uses: actions/setup-go@v5 |
| 163 | + with: |
| 164 | + go-version: ${{ env.GO_VERSION }} |
| 165 | + cache-dependency-path: ai-studio-cli/go.sum |
| 166 | + - run: make vet |
0 commit comments