Skip to content

Commit fb8a638

Browse files
Add Github Action workflows (#3)
1 parent f5b449a commit fb8a638

20 files changed

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

.github/workflows/check-license.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-license.md
2+
name: Check License
3+
4+
env:
5+
EXPECTED_LICENSE_FILENAME: LICENSE.txt
6+
# SPDX identifier: https://spdx.org/licenses/
7+
EXPECTED_LICENSE_TYPE: AGPL-3.0
8+
9+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
10+
on:
11+
create:
12+
push:
13+
paths:
14+
- ".github/workflows/check-license.ya?ml"
15+
# See: https://github.com/licensee/licensee/blob/master/docs/what-we-look-at.md#detecting-the-license-file
16+
- "[cC][oO][pP][yY][iI][nN][gG]*"
17+
- "[cC][oO][pP][yY][rR][iI][gG][hH][tH]*"
18+
- "[lL][iI][cC][eE][nN][cCsS][eE]*"
19+
- "[oO][fF][lL]*"
20+
- "[pP][aA][tT][eE][nN][tT][sS]*"
21+
pull_request:
22+
paths:
23+
- ".github/workflows/check-license.ya?ml"
24+
- "[cC][oO][pP][yY][iI][nN][gG]*"
25+
- "[cC][oO][pP][yY][rR][iI][gG][hH][tH]*"
26+
- "[lL][iI][cC][eE][nN][cCsS][eE]*"
27+
- "[oO][fF][lL]*"
28+
- "[pP][aA][tT][eE][nN][tT][sS]*"
29+
schedule:
30+
# Run periodically to catch breakage caused by external changes.
31+
- cron: "0 6 * * WED"
32+
workflow_dispatch:
33+
repository_dispatch:
34+
35+
jobs:
36+
run-determination:
37+
runs-on: ubuntu-latest
38+
permissions: {}
39+
outputs:
40+
result: ${{ steps.determination.outputs.result }}
41+
steps:
42+
- name: Determine if the rest of the workflow should run
43+
id: determination
44+
run: |
45+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
46+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
47+
if [[
48+
"${{ github.event_name }}" != "create" ||
49+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
50+
]]; then
51+
# Run the other jobs.
52+
RESULT="true"
53+
else
54+
# There is no need to run the other jobs.
55+
RESULT="false"
56+
fi
57+
58+
echo "result=$RESULT" >> $GITHUB_OUTPUT
59+
60+
check-license:
61+
needs: run-determination
62+
if: needs.run-determination.outputs.result == 'true'
63+
runs-on: ubuntu-latest
64+
permissions:
65+
contents: read
66+
67+
steps:
68+
- name: Checkout repository
69+
uses: actions/checkout@v3
70+
71+
- name: Install Ruby
72+
uses: ruby/setup-ruby@v1
73+
with:
74+
ruby-version: ruby # Install latest version
75+
76+
- name: Install licensee
77+
run: gem install licensee
78+
79+
- name: Check license file
80+
run: |
81+
EXIT_STATUS=0
82+
# See: https://github.com/licensee/licensee
83+
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"
84+
85+
DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
86+
echo "Detected license file: $DETECTED_LICENSE_FILE"
87+
if [ "$DETECTED_LICENSE_FILE" != "\"${EXPECTED_LICENSE_FILENAME}\"" ]; then
88+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: $EXPECTED_LICENSE_FILENAME"
89+
EXIT_STATUS=1
90+
fi
91+
92+
DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
93+
echo "Detected license type: $DETECTED_LICENSE_TYPE"
94+
if [ "$DETECTED_LICENSE_TYPE" != "\"${EXPECTED_LICENSE_TYPE}\"" ]; then
95+
echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${EXPECTED_LICENSE_TYPE}\""
96+
EXIT_STATUS=1
97+
fi
98+
99+
exit $EXIT_STATUS
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-markdown-task.md
2+
name: Check Markdown
3+
4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
8+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
9+
on:
10+
create:
11+
push:
12+
paths:
13+
- ".github/workflows/check-markdown-task.ya?ml"
14+
- ".markdown-link-check.json"
15+
- "package.json"
16+
- "package-lock.json"
17+
- "Taskfile.ya?ml"
18+
- "**/.markdownlint*"
19+
- "**.mdx?"
20+
- "**.mkdn"
21+
- "**.mdown"
22+
- "**.markdown"
23+
pull_request:
24+
paths:
25+
- ".github/workflows/check-markdown-task.ya?ml"
26+
- ".markdown-link-check.json"
27+
- "package.json"
28+
- "package-lock.json"
29+
- "Taskfile.ya?ml"
30+
- "**/.markdownlint*"
31+
- "**.mdx?"
32+
- "**.mkdn"
33+
- "**.mdown"
34+
- "**.markdown"
35+
schedule:
36+
# Run every Tuesday at 8 AM UTC to catch breakage caused by external changes.
37+
- cron: "0 8 * * TUE"
38+
workflow_dispatch:
39+
repository_dispatch:
40+
41+
jobs:
42+
run-determination:
43+
runs-on: ubuntu-latest
44+
permissions: {}
45+
outputs:
46+
result: ${{ steps.determination.outputs.result }}
47+
steps:
48+
- name: Determine if the rest of the workflow should run
49+
id: determination
50+
run: |
51+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
52+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
53+
if [[
54+
"${{ github.event_name }}" != "create" ||
55+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
56+
]]; then
57+
# Run the other jobs.
58+
RESULT="true"
59+
else
60+
# There is no need to run the other jobs.
61+
RESULT="false"
62+
fi
63+
64+
echo "result=$RESULT" >> $GITHUB_OUTPUT
65+
66+
lint:
67+
needs: run-determination
68+
if: needs.run-determination.outputs.result == 'true'
69+
runs-on: ubuntu-latest
70+
permissions:
71+
contents: read
72+
73+
steps:
74+
- name: Checkout repository
75+
uses: actions/checkout@v3
76+
77+
- name: Setup Node.js
78+
uses: actions/setup-node@v3
79+
with:
80+
node-version: ${{ env.NODE_VERSION }}
81+
82+
- name: Initialize markdownlint-cli problem matcher
83+
uses: xt0rted/markdownlint-problem-matcher@v2
84+
85+
- name: Install Task
86+
uses: arduino/setup-task@v1
87+
with:
88+
repo-token: ${{ secrets.GITHUB_TOKEN }}
89+
version: 3.x
90+
91+
- name: Lint
92+
run: task markdown:lint
93+
94+
links:
95+
needs: run-determination
96+
if: needs.run-determination.outputs.result == 'true'
97+
runs-on: ubuntu-latest
98+
permissions:
99+
contents: read
100+
101+
steps:
102+
- name: Checkout repository
103+
uses: actions/checkout@v3
104+
105+
- name: Setup Node.js
106+
uses: actions/setup-node@v3
107+
with:
108+
node-version: ${{ env.NODE_VERSION }}
109+
110+
- name: Install Task
111+
uses: arduino/setup-task@v1
112+
with:
113+
repo-token: ${{ secrets.GITHUB_TOKEN }}
114+
version: 3.x
115+
116+
- name: Check links
117+
run: task --silent markdown:check-links

0 commit comments

Comments
 (0)