Skip to content

Fetch Licenses

Fetch Licenses #552

name: Fetch Licenses
on:
workflow_dispatch:
inputs:
force_run:
description: 'Force run license extraction'
required: false
default: 'false'
schedule:
- cron: '5 4 * * *' # Runs at 0405 UTC (0605 CET, 0005 ET, 2105 PT)
jobs:
fetch-licenses:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Setup Git
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Checkout this repository
uses: actions/checkout@v5
- name: Checkout official SPDX Repository
uses: actions/checkout@v5
with:
repository: spdx/license-list-data
path: official-spdx-licenses # creates a tmp dir to hold the SPDX licenses from the official repo
- name: Copy Licenses
run: |
cp official-spdx-licenses/json/licenses.json cmd/licenses.json
cp official-spdx-licenses/json/exceptions.json cmd/exceptions.json
- name: Get date
id: date
run: echo "DT_STAMP"=$(date +'%Y-%m-%d %H:%M UTC') >> $GITHUB_ENV
- name: Check for changes in SPDX json files
id: src-changes
run: |
src_changed=true
# --quiet: Exits with 1 if there are changes; otherwise, exits with 0
git diff --quiet -- cmd/licenses.json cmd/exceptions.json && src_changed=false
if [ $src_changed != 'true' ]; then
if [ ${{ github.event.inputs.force_run }} == 'true' ]; then
echo -e '***************\nNo changes in spdx json, but skipping abort due to force run\n***************'
else
echo -e '***************\nABORTING: No changes to spdx json data\n***************'
exit 0
fi
fi
echo "SRC_CHANGED=$src_changed" >> $GITHUB_ENV
- name: Run license extraction
if: ${{ env.SRC_CHANGED == 'true' || github.event.inputs.force_run == 'true' }}
run: |
cd cmd
echo "Current branch: $(git branch)"
go run . extract -l -e
cd ..
git log --oneline -n 5
- name: Check for changes in generated files
id: genfiles-changes
run: |
genfiles_changed=true
# --quiet: Exits with 1 if there are changes; otherwise, exits with 0
git diff --quiet -- spdxexp/spdxlicenses/*.go && genfiles_changed=false
if [ $genfiles_changed != 'true' ]; then
if [ ${{ github.event.inputs.force_run }} == 'true' ]; then
echo -e '***************\nNo changes to generated files, but skipping abort due to force run\n***************'
else
# This happens when the generated files are already up to date
# or the only changes in the source json are data not included in the generated files (e.g. IDs)
echo -e '***************\nABORTING: No changes to license data in generated files\n***************'
exit 0
fi
fi
echo "GENFILES_CHANGED=$genfiles_changed" >> $GITHUB_ENV
- name: Create Pull Request
if: ${{ env.GENFILES_CHANGED == 'true' || github.event.inputs.force_run == 'true' }}
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Add updated license files
branch: auto-update-licenses
base: main
title: "Update SPDX license files (${{ env.DT_STAMP }})"
body: "The files in this PR are auto-generated by the [fetch-licenses](./.git/workflows/fetch-license.yaml) workflow when it runs the `extract` command defined in [cmd/main.go](./cmd/main.go). It updates SPDX licenses based on the latest released set in the [spdx/license-list-data](https://github.com/spdx/license-list-data) repository maintained by [SPDX](https://spdx.org/licenses/). \n\nTODO: [spdxexp/spdxlicenses/license_ranges.go](./spdxexp/spdxlicenses/license_range.go) has to be updated manually."
labels: 'auto-update,licenses'