Debian Codegraph @

.github/workflows/fetch-licenses.yaml

raw symbols SCIP
1 name: Fetch Licenses
2
3 on:
4 workflow_dispatch:
5 inputs:
6 force_run:
7 description: 'Force run license extraction'
8 required: false
9 default: 'false'
10 schedule:
11 - cron: '5 4 * * *' # Runs at 0405 UTC (0605 CET, 0005 ET, 2105 PT)
12
13 jobs:
14 fetch-licenses:
15 runs-on: ubuntu-latest
16 permissions:
17 contents: write
18 pull-requests: write
19
20 steps:
21 - name: Setup Git
22 run: |
23 git config --global user.name "GitHub Actions"
24 git config --global user.email "github-actions[bot]@users.noreply.github.com"
25
26 - name: Checkout this repository
27 uses: actions/checkout@v6
28
29 - name: Checkout official SPDX Repository
30 uses: actions/checkout@v6
31 with:
32 repository: spdx/license-list-data
33 path: official-spdx-licenses # creates a tmp dir to hold the SPDX licenses from the official repo
34
35 - name: Copy Licenses
36 run: |
37 cp official-spdx-licenses/json/licenses.json cmd/licenses.json
38 cp official-spdx-licenses/json/exceptions.json cmd/exceptions.json
39
40 - name: Get date
41 id: date
42 run: echo "DT_STAMP"=$(date +'%Y-%m-%d %H:%M UTC') >> $GITHUB_ENV
43
44 - name: Check for changes in SPDX json files
45 id: src-changes
46 run: |
47 src_changed=true
48 # --quiet: Exits with 1 if there are changes; otherwise, exits with 0
49 git diff --quiet -- cmd/licenses.json cmd/exceptions.json && src_changed=false
50 if [ $src_changed != 'true' ]; then
51 if [ ${{ github.event.inputs.force_run }} == 'true' ]; then
52 echo -e '***************\nNo changes in spdx json, but skipping abort due to force run\n***************'
53 else
54 echo -e '***************\nABORTING: No changes to spdx json data\n***************'
55 exit 0
56 fi
57 fi
58 echo "SRC_CHANGED=$src_changed" >> $GITHUB_ENV
59
60 - name: Run license extraction
61 if: ${{ env.SRC_CHANGED == 'true' || github.event.inputs.force_run == 'true' }}
62 run: |
63 cd cmd
64 echo "Current branch: $(git branch)"
65 go run . extract -l -e
66 cd ..
67 git log --oneline -n 5
68
69 - name: Check for changes in generated files
70 id: genfiles-changes
71 run: |
72 genfiles_changed=true
73 # --quiet: Exits with 1 if there are changes; otherwise, exits with 0
74 git diff --quiet -- spdxexp/spdxlicenses/*.go && genfiles_changed=false
75 if [ $genfiles_changed != 'true' ]; then
76 if [ ${{ github.event.inputs.force_run }} == 'true' ]; then
77 echo -e '***************\nNo changes to generated files, but skipping abort due to force run\n***************'
78 else
79 # This happens when the generated files are already up to date
80 # or the only changes in the source json are data not included in the generated files (e.g. IDs)
81 echo -e '***************\nABORTING: No changes to license data in generated files\n***************'
82 exit 0
83 fi
84 fi
85 echo "GENFILES_CHANGED=$genfiles_changed" >> $GITHUB_ENV
86
87 - name: Create Pull Request
88 if: ${{ env.GENFILES_CHANGED == 'true' || github.event.inputs.force_run == 'true' }}
89 uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1
90 with:
91 token: ${{ secrets.GITHUB_TOKEN }}
92 commit-message: Add updated license files
93 branch: auto-update-licenses
94 base: main
95 title: "Update SPDX license files (${{ env.DT_STAMP }})"
96 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."
97 labels: 'auto-update,licenses'