Skip to content

Commit

Permalink
ci: fix license checks
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <[email protected]>
  • Loading branch information
jkowalleck committed Jan 14, 2025
1 parent 622ff8d commit e7f230b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 21 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ jobs:
run: yarn run test:lint

test-licenses:
needs: [ 'build' ]
name: test licenses
runs-on: ubuntu-latest
timeout-minutes: 10
Expand All @@ -152,28 +151,22 @@ jobs:
run: corepack enable yarn
- name: Setup subject
run: yarn install --immutable
- name: fetch build artifact
# see https://github.com/actions/download-artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.BUNDLES_DIR }}
path: ${{ env.BUNDLES_DIR }}
- name: make NOTICE and summary
run: |
mkdir -p _tmp
yarn node tools/write-3rd-party-licenses.cjs _tmp/NOTICE _tmp/lsummary
yarn node tools/write-3rd-party-licenses.cjs _tmp/NOTICE _tmp/lsummary.json
- name: artifact build result
# see https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v4
with:
name: licenses-files
path: |
_tmp/NOTICE
_tmp/lsummary
_tmp/lsummary.json
retention-days: 5
if-no-files-found: error
- name: test license compatibility
run: flict display-compatibility $(cat _tmp/lsummary)
run: tools/test-licenses.sh

test-node:
needs: [ 'build' ]
Expand Down
34 changes: 27 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,41 @@ jobs:
if-no-files-found: error

test-licenses:
needs: [ 'build' ]
name: test licenses
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: install flict
run: pip install flict==1.2.14
- name: fetch build artifact
# see https://github.com/actions/download-artifact
uses: actions/download-artifact@v4
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@v4
- name: Setup Node.js ${{ env.NODE_ACTIVE_LTS }}
# see https://github.com/actions/setup-node
uses: actions/setup-node@v4
with:
name: ${{ env.DIST_DIR }}
path: ${{ env.DIST_DIR }}
node-version: ${{ env.NODE_ACTIVE_LTS }}
# cache: 'yarn'
- name: Setup yarn
run: corepack enable yarn
- name: Setup subject
run: yarn install --immutable
- name: make NOTICE and summary
run: |
mkdir -p _tmp
yarn node tools/write-3rd-party-licenses.cjs _tmp/NOTICE _tmp/lsummary.json
- name: artifact build result
# see https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v4
with:
name: licenses-files
path: |
_tmp/NOTICE
_tmp/lsummary.json
retention-days: 5
if-no-files-found: error
- name: test license compatibility
run: flict display-compatibility $(cat "$DIST_DIR"/*.lsummary)
run: tools/test-licenses.sh

test-node:
needs:
Expand Down
31 changes: 31 additions & 0 deletions tools/test-licenses.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -ue

EC=0
LICENSES_JSON="$1"

OL="$(jq -r '.ol' "$LICENSES_JSON")"

flict verify \
-ol "$OL" \
-il "$(jq -r '.ils | join(" AND ")' "$LICENSES_JSON")" \
|| EC=$?;

if [[ $EC -eq 0 ]]
then
exit $EC
fi

echo "ERROR: non-zero exit code: $EC" >&2
echo "ERROR: found license issues. lets see details..." >&2

# the below is an alternative
# it tells which license is incompatible,
# but it is slower

jq -r '.ils[]' "$LICENSES_JSON" | while read -r IL
do
flict verify -ol "$OL" -il "$IL" >&2
done

exit $EC
14 changes: 10 additions & 4 deletions tools/write-3rd-party-licenses.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,18 @@ async function main (outputFile, includeLicense) {

if (require.main === module) {
const outputFile = process.argv[2] || `${metaFile}.NOTICE`
const lsummaryFile = process.argv[3] || `${outputFile}.lsummary`
const lsummaryFile = process.argv[3] || `${outputFile}.lsummary.json`
const includeLicense = false
main(outputFile, includeLicense).then(licenses => {
const assert = require('assert')
main(outputFile, includeLicense).then(ils => {
const ol = JSON.parse(readFileSync(join(projectRoot, 'package.json'))).license;

Check failure on line 170 in tools/write-3rd-party-licenses.cjs

View workflow job for this annotation

GitHub Actions / test standard

Extra semicolon. (semi)
assert(typeof ol === 'string' && ol.length > 0);

Check failure on line 171 in tools/write-3rd-party-licenses.cjs

View workflow job for this annotation

GitHub Actions / test standard

Extra semicolon. (semi)
assert(ils.size > 0);

Check failure on line 172 in tools/write-3rd-party-licenses.cjs

View workflow job for this annotation

GitHub Actions / test standard

Extra semicolon. (semi)
const lsummaryFH = openSync(lsummaryFile, 'w')
writeSync(lsummaryFH, JSON.parse(readFileSync(join(projectRoot, 'package.json'))).license + '\n')
writeSync(lsummaryFH, Array.from(licenses).sort().join('\n'))
writeSync(lsummaryFH, JSON.stringify({
ol,
ils: Array.from(ils).sort()
}))
closeSync(lsummaryFH)
})
} else {
Expand Down

0 comments on commit e7f230b

Please sign in to comment.