Skip to content

Commit 0abb17f

Browse files
authored
ci: fix license checks (#247)
fixes #242 --------- Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent 622ff8d commit 0abb17f

File tree

5 files changed

+83
-16
lines changed

5 files changed

+83
-16
lines changed

.github/workflows/nodejs.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ jobs:
137137
runs-on: ubuntu-latest
138138
timeout-minutes: 10
139139
steps:
140-
- name: install flict
141-
run: pip install flict==1.2.14
142140
- name: Checkout
143141
# see https://github.com/actions/checkout
144142
uses: actions/checkout@v4
143+
- name: install tools
144+
run: pip install -r tools/test-3rd-party-licenses.requirements.txt
145145
- name: Setup Node.js ${{ env.NODE_ACTIVE_LTS }}
146146
# see https://github.com/actions/setup-node
147147
uses: actions/setup-node@v4
@@ -150,30 +150,30 @@ jobs:
150150
# cache: 'yarn'
151151
- name: Setup yarn
152152
run: corepack enable yarn
153-
- name: Setup subject
154-
run: yarn install --immutable
155153
- name: fetch build artifact
156154
# see https://github.com/actions/download-artifact
157155
uses: actions/download-artifact@v4
158156
with:
159157
name: ${{ env.BUNDLES_DIR }}
160158
path: ${{ env.BUNDLES_DIR }}
159+
- name: Setup subject
160+
run: yarn install --immutable
161161
- name: make NOTICE and summary
162162
run: |
163163
mkdir -p _tmp
164-
yarn node tools/write-3rd-party-licenses.cjs _tmp/NOTICE _tmp/lsummary
164+
yarn node tools/write-3rd-party-licenses.cjs _tmp/NOTICE _tmp/lsummary.json
165165
- name: artifact build result
166166
# see https://github.com/actions/upload-artifact
167167
uses: actions/upload-artifact@v4
168168
with:
169169
name: licenses-files
170170
path: |
171171
_tmp/NOTICE
172-
_tmp/lsummary
172+
_tmp/lsummary.json
173173
retention-days: 5
174174
if-no-files-found: error
175175
- name: test license compatibility
176-
run: flict display-compatibility $(cat _tmp/lsummary)
176+
run: tools/test-3rd-party-licenses.sh _tmp/lsummary.json
177177

178178
test-node:
179179
needs: [ 'build' ]

.github/workflows/release.yml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,43 @@ jobs:
129129
runs-on: ubuntu-latest
130130
timeout-minutes: 10
131131
steps:
132-
- name: install flict
133-
run: pip install flict==1.2.14
132+
- name: Checkout
133+
# see https://github.com/actions/checkout
134+
uses: actions/checkout@v4
135+
- name: install tools
136+
run: pip install -r tools/test-3rd-party-licenses.requirements.txt
137+
- name: Setup Node.js ${{ env.NODE_ACTIVE_LTS }}
138+
# see https://github.com/actions/setup-node
139+
uses: actions/setup-node@v4
140+
with:
141+
node-version: ${{ env.NODE_ACTIVE_LTS }}
142+
# cache: 'yarn'
143+
- name: Setup yarn
144+
run: corepack enable yarn
134145
- name: fetch build artifact
135146
# see https://github.com/actions/download-artifact
136147
uses: actions/download-artifact@v4
137148
with:
138-
name: ${{ env.DIST_DIR }}
139-
path: ${{ env.DIST_DIR }}
149+
name: ${{ env.BUNDLES_DIR }}
150+
path: ${{ env.BUNDLES_DIR }}
151+
- name: Setup subject
152+
run: yarn install --immutable
153+
- name: make NOTICE and summary
154+
run: |
155+
mkdir -p _tmp
156+
yarn node tools/write-3rd-party-licenses.cjs _tmp/NOTICE _tmp/lsummary.json
157+
- name: artifact build result
158+
# see https://github.com/actions/upload-artifact
159+
uses: actions/upload-artifact@v4
160+
with:
161+
name: licenses-files
162+
path: |
163+
_tmp/NOTICE
164+
_tmp/lsummary.json
165+
retention-days: 5
166+
if-no-files-found: error
140167
- name: test license compatibility
141-
run: flict display-compatibility $(cat "$DIST_DIR"/*.lsummary)
168+
run: tools/test-3rd-party-licenses.sh _tmp/lsummary.json
142169

143170
test-node:
144171
needs:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://pypi.org/project/flict/
2+
flict==1.2.14

tools/test-3rd-party-licenses.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
set -ue
3+
EC=0
4+
5+
# file format like: {"ol":"Apache-2.0","ils":["...","MIT","GPL-2.0-only"]}
6+
LICENSES_JSON="$1"
7+
8+
OL="$(jq -r '.ol' "$LICENSES_JSON")"
9+
10+
flict verify \
11+
-ol "$OL" \
12+
-il "$(jq -r '.ils | join(" AND ")' "$LICENSES_JSON")" \
13+
|| EC=$?;
14+
15+
if [[ $EC -eq 0 ]]
16+
then
17+
exit $EC
18+
fi
19+
20+
echo "ERROR: non-zero exit code: $EC" >&2
21+
echo "ERROR: found license issues. lets see details..." >&2
22+
23+
# the below is an alternative
24+
# it tells which license is incompatible,
25+
# but it is slower
26+
27+
jq -r '.ils[]' "$LICENSES_JSON" | while read -r IL
28+
do
29+
flict verify -ol "$OL" -il "$IL" >&2
30+
done
31+
32+
exit $EC

tools/write-3rd-party-licenses.cjs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,18 @@ async function main (outputFile, includeLicense) {
163163

164164
if (require.main === module) {
165165
const outputFile = process.argv[2] || `${metaFile}.NOTICE`
166-
const lsummaryFile = process.argv[3] || `${outputFile}.lsummary`
166+
const lsummaryFile = process.argv[3] || `${outputFile}.lsummary.json`
167167
const includeLicense = false
168-
main(outputFile, includeLicense).then(licenses => {
168+
const assert = require('assert')
169+
main(outputFile, includeLicense).then(ils => {
170+
const ol = JSON.parse(readFileSync(join(projectRoot, 'package.json'))).license
171+
assert(typeof ol === 'string' && ol.length > 0)
172+
assert(ils.size > 0)
169173
const lsummaryFH = openSync(lsummaryFile, 'w')
170-
writeSync(lsummaryFH, JSON.parse(readFileSync(join(projectRoot, 'package.json'))).license + '\n')
171-
writeSync(lsummaryFH, Array.from(licenses).sort().join('\n'))
174+
writeSync(lsummaryFH, JSON.stringify({
175+
ol,
176+
ils: Array.from(ils).sort()
177+
}))
172178
closeSync(lsummaryFH)
173179
})
174180
} else {

0 commit comments

Comments
 (0)