| 1 |
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-go-dependencies-task.md |
| 2 |
name: Check Go Dependencies |
| 3 |
|
| 4 |
# See: https://docs.github.com/actions/reference/workflows-and-actions/events-that-trigger-workflows |
| 5 |
on: |
| 6 |
create: |
| 7 |
push: |
| 8 |
paths: |
| 9 |
- ".github/workflows/check-go-dependencies-task.ya?ml" |
| 10 |
- ".licenses/**" |
| 11 |
- ".licensed.json" |
| 12 |
- ".licensed.ya?ml" |
| 13 |
- "Taskfile.ya?ml" |
| 14 |
- "**/.gitmodules" |
| 15 |
- "**/go.mod" |
| 16 |
- "**/go.sum" |
| 17 |
pull_request: |
| 18 |
paths: |
| 19 |
- ".github/workflows/check-go-dependencies-task.ya?ml" |
| 20 |
- ".licenses/**" |
| 21 |
- ".licensed.json" |
| 22 |
- ".licensed.ya?ml" |
| 23 |
- "Taskfile.ya?ml" |
| 24 |
- "**/.gitmodules" |
| 25 |
- "**/go.mod" |
| 26 |
- "**/go.sum" |
| 27 |
schedule: |
| 28 |
# Run periodically to catch breakage caused by external changes. |
| 29 |
- cron: "0 8 * * WED" |
| 30 |
workflow_dispatch: |
| 31 |
repository_dispatch: |
| 32 |
|
| 33 |
jobs: |
| 34 |
run-determination: |
| 35 |
runs-on: ubuntu-latest |
| 36 |
permissions: {} |
| 37 |
outputs: |
| 38 |
result: ${{ steps.determination.outputs.result }} |
| 39 |
steps: |
| 40 |
- name: Determine if the rest of the workflow should run |
| 41 |
id: determination |
| 42 |
run: | |
| 43 |
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" |
| 44 |
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. |
| 45 |
if [[ |
| 46 |
"${{ github.event_name }}" != "create" || |
| 47 |
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX |
| 48 |
]]; then |
| 49 |
# Run the other jobs. |
| 50 |
RESULT="true" |
| 51 |
else |
| 52 |
# There is no need to run the other jobs. |
| 53 |
RESULT="false" |
| 54 |
fi |
| 55 |
|
| 56 |
echo "result=$RESULT" >>$GITHUB_OUTPUT |
| 57 |
|
| 58 |
check-cache: |
| 59 |
needs: run-determination |
| 60 |
if: needs.run-determination.outputs.result == 'true' |
| 61 |
runs-on: ubuntu-latest |
| 62 |
permissions: |
| 63 |
contents: read |
| 64 |
|
| 65 |
steps: |
| 66 |
- name: Checkout repository |
| 67 |
uses: actions/checkout@v7 |
| 68 |
with: |
| 69 |
submodules: recursive |
| 70 |
|
| 71 |
# This is required to allow licensee/setup-licensed to install Licensed via Ruby gem. |
| 72 |
- name: Install Ruby |
| 73 |
uses: ruby/setup-ruby@v1 |
| 74 |
with: |
| 75 |
ruby-version: ruby # Install latest version |
| 76 |
|
| 77 |
- name: Install licensed |
| 78 |
uses: licensee/[email protected] |
| 79 |
with: |
| 80 |
github_token: ${{ secrets.GITHUB_TOKEN }} |
| 81 |
version: 5.x |
| 82 |
|
| 83 |
- name: Install Go |
| 84 |
uses: actions/setup-go@v7 |
| 85 |
with: |
| 86 |
go-version-file: go.mod |
| 87 |
|
| 88 |
- name: Update dependencies license metadata cache |
| 89 |
run: | |
| 90 |
go tool \ |
| 91 |
github.com/go-task/task/v3/cmd/task \ |
| 92 |
--silent \ |
| 93 |
general:cache-dep-licenses |
| 94 |
|
| 95 |
- name: Check for outdated cache |
| 96 |
id: diff |
| 97 |
run: | |
| 98 |
git add . |
| 99 |
if |
| 100 |
! git diff \ |
| 101 |
--cached \ |
| 102 |
--color \ |
| 103 |
--exit-code |
| 104 |
then |
| 105 |
echo |
| 106 |
echo "::error::Dependency license metadata out of sync. See: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-go-dependencies-task.md#metadata-cache" |
| 107 |
exit 1 |
| 108 |
fi |
| 109 |
|
| 110 |
# Some might find it convenient to have CI generate the cache rather than setting up for it locally |
| 111 |
- name: Upload cache to workflow artifact |
| 112 |
if: failure() && steps.diff.outcome == 'failure' |
| 113 |
uses: actions/upload-artifact@v7 |
| 114 |
with: |
| 115 |
if-no-files-found: error |
| 116 |
include-hidden-files: true |
| 117 |
name: dep-licenses-cache |
| 118 |
path: .licenses/ |
| 119 |
|
| 120 |
check-deps: |
| 121 |
needs: run-determination |
| 122 |
if: needs.run-determination.outputs.result == 'true' |
| 123 |
runs-on: ubuntu-latest |
| 124 |
permissions: |
| 125 |
contents: read |
| 126 |
|
| 127 |
steps: |
| 128 |
- name: Checkout repository |
| 129 |
uses: actions/checkout@v7 |
| 130 |
with: |
| 131 |
submodules: recursive |
| 132 |
|
| 133 |
# This is required to allow licensee/setup-licensed to install Licensed via Ruby gem. |
| 134 |
- name: Install Ruby |
| 135 |
uses: ruby/setup-ruby@v1 |
| 136 |
with: |
| 137 |
ruby-version: ruby # Install latest version |
| 138 |
|
| 139 |
- name: Install licensed |
| 140 |
uses: licensee/[email protected] |
| 141 |
with: |
| 142 |
github_token: ${{ secrets.GITHUB_TOKEN }} |
| 143 |
version: 5.x |
| 144 |
|
| 145 |
- name: Install Go |
| 146 |
uses: actions/setup-go@v7 |
| 147 |
with: |
| 148 |
go-version-file: go.mod |
| 149 |
|
| 150 |
- name: Check for dependencies with unapproved licenses |
| 151 |
run: | |
| 152 |
go tool \ |
| 153 |
github.com/go-task/task/v3/cmd/task \ |
| 154 |
--silent \ |
| 155 |
general:check-dep-licenses |