Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add workflow to fetch spdx licenses #62

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/fetch-licenses.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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

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's auto-update-licenses branch
uses: actions/checkout@v2

- name: Checkout official SPDX Repository
uses: actions/checkout@v2
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: Check for changes
run: |
git diff --exit-code -- cmd/licenses.json cmd/exceptions.json || exit 0

- name: Run license extraction
run: |
cd cmd
echo "Current branch: $(git branch)"
go run . extract -l -e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to setup go for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actions have go available without setup. The version of go isn't terribly important to be able to run this simple script.

cd ..
git log --oneline -n 5

- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Add updated license files
branch: auto-update-licenses
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it possible to append a unique hash to the name of the branch to avoid collisions and problems with the branch? Something like this

Suggested change
branch: auto-update-licenses
branch: auto-update-licenses-${{ github.run_id }}-${{ github.run_attempt }}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peter-evans/create-pull-request will either create the branch or update it and associated PR if it already exists. As this is designed to run once a day on a schedule, the chances that there will be a race condition seem unlikely. I like that the PR will be updated as it prevents proliferation of PRs if one is not immediately merged.

I'd like to keep it as is for now. If in reality there are collisions or other problems, we can add a unique branch identifier at that time.

base: main
title: "Update SPDX license files"
body: "The files in this PR are auto-generated by the [fetch-licenses](./.git/workflows/fetch-license.yaml) workflow when it runs the `cmd/extract` script. 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'
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func main() {
os.Exit(1)
}
fmt.Println("Done!")
fmt.Println("---------------------------")
}
default:
writeHelpMessage()
Expand Down