Skip to content

Commit d908f1e

Browse files
authored
Merge pull request #12 from per1234/sync-check-deps
Sync "Check Go Dependencies" workflow with upstream
2 parents 0cd7739 + 021a791 commit d908f1e

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

.github/workflows/check-go-dependencies-task.yml

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
name: Check Go Dependencies
33

44
env:
5-
# See: https://github.com/actions/setup-go/tree/v2#readme
5+
# See: https://github.com/actions/setup-go/tree/v3#readme
66
GO_VERSION: "1.13"
77

8-
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
8+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
99
on:
10+
create:
1011
push:
1112
paths:
1213
- ".github/workflows/check-go-dependencies-task.ya?ml"
@@ -27,16 +28,44 @@ on:
2728
- "**/.gitmodules"
2829
- "**/go.mod"
2930
- "**/go.sum"
31+
schedule:
32+
# Run periodically to catch breakage caused by external changes.
33+
- cron: "0 8 * * WED"
3034
workflow_dispatch:
3135
repository_dispatch:
3236

3337
jobs:
38+
run-determination:
39+
runs-on: ubuntu-latest
40+
outputs:
41+
result: ${{ steps.determination.outputs.result }}
42+
steps:
43+
- name: Determine if the rest of the workflow should run
44+
id: determination
45+
run: |
46+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
47+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
48+
if [[
49+
"${{ github.event_name }}" != "create" ||
50+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
51+
]]; then
52+
# Run the other jobs.
53+
RESULT="true"
54+
else
55+
# There is no need to run the other jobs.
56+
RESULT="false"
57+
fi
58+
59+
echo "::set-output name=result::$RESULT"
60+
3461
check-cache:
62+
needs: run-determination
63+
if: needs.run-determination.outputs.result == 'true'
3564
runs-on: ubuntu-latest
3665

3766
steps:
3867
- name: Checkout repository
39-
uses: actions/checkout@v2
68+
uses: actions/checkout@v3
4069
with:
4170
submodules: recursive
4271

@@ -47,7 +76,7 @@ jobs:
4776
version: 3.x
4877

4978
- name: Install Go
50-
uses: actions/setup-go@v2
79+
uses: actions/setup-go@v3
5180
with:
5281
go-version: ${{ env.GO_VERSION }}
5382

@@ -63,8 +92,8 @@ jobs:
6392
- name: Check for outdated cache
6493
id: diff
6594
run: |
66-
git add --intent-to-add .
67-
if ! git diff --color --exit-code; then
95+
git add .
96+
if ! git diff --cached --color --exit-code; then
6897
echo
6998
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"
7099
exit 1
@@ -73,18 +102,20 @@ jobs:
73102
# Some might find it convenient to have CI generate the cache rather than setting up for it locally
74103
- name: Upload cache to workflow artifact
75104
if: failure() && steps.diff.outcome == 'failure'
76-
uses: actions/upload-artifact@v2
105+
uses: actions/upload-artifact@v3
77106
with:
78107
if-no-files-found: error
79108
name: dep-licenses-cache
80109
path: .licenses/
81110

82111
check-deps:
112+
needs: run-determination
113+
if: needs.run-determination.outputs.result == 'true'
83114
runs-on: ubuntu-latest
84115

85116
steps:
86117
- name: Checkout repository
87-
uses: actions/checkout@v2
118+
uses: actions/checkout@v3
88119
with:
89120
submodules: recursive
90121

@@ -95,7 +126,7 @@ jobs:
95126
version: 3.x
96127

97128
- name: Install Go
98-
uses: actions/setup-go@v2
129+
uses: actions/setup-go@v3
99130
with:
100131
go-version: ${{ env.GO_VERSION }}
101132

0 commit comments

Comments
 (0)