Skip to content

Commit 5bf853c

Browse files
committed
Update infrastructure for action metadata validation
A task and GitHub Actions workflow are provided here for validating the action.yml metadata file of GitHub Actions actions. On every push or pull request that affects the metadata file, and periodically, validate action.yml against its JSON schema.
1 parent 0b6522b commit 5bf853c

File tree

7 files changed

+657
-47
lines changed

7 files changed

+657
-47
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-action-metadata-task.md
2+
name: Check Action Metadata
3+
4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
8+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
9+
on:
10+
create:
11+
push:
12+
paths:
13+
- ".github/workflows/check-action-metadata-task.ya?ml"
14+
- "action.ya?ml"
15+
- "package.json"
16+
- "package-lock.json"
17+
- "Taskfile.ya?ml"
18+
pull_request:
19+
paths:
20+
- ".github/workflows/check-action-metadata-task.ya?ml"
21+
- "action.ya?ml"
22+
- "package.json"
23+
- "package-lock.json"
24+
- "Taskfile.ya?ml"
25+
schedule:
26+
# Run every Tuesday at 8 AM UTC to catch breakage from changes to the JSON schema.
27+
- cron: "0 8 * * TUE"
28+
workflow_dispatch:
29+
repository_dispatch:
30+
31+
jobs:
32+
run-determination:
33+
runs-on: ubuntu-latest
34+
outputs:
35+
result: ${{ steps.determination.outputs.result }}
36+
steps:
37+
- name: Determine if the rest of the workflow should run
38+
id: determination
39+
run: |
40+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
41+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
42+
if [[
43+
"${{ github.event_name }}" != "create" ||
44+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
45+
]]; then
46+
# Run the other jobs.
47+
RESULT="true"
48+
else
49+
# There is no need to run the other jobs.
50+
RESULT="false"
51+
fi
52+
53+
echo "result=$RESULT" >> $GITHUB_OUTPUT
54+
55+
validate:
56+
needs: run-determination
57+
if: needs.run-determination.outputs.result == 'true'
58+
runs-on: ubuntu-latest
59+
60+
steps:
61+
- name: Checkout repository
62+
uses: actions/checkout@v3
63+
64+
- name: Setup Node.js
65+
uses: actions/setup-node@v3
66+
with:
67+
node-version: ${{ env.NODE_VERSION }}
68+
69+
- name: Install Task
70+
uses: arduino/setup-task@v1
71+
with:
72+
repo-token: ${{ secrets.GITHUB_TOKEN }}
73+
version: 3.x
74+
75+
- name: Validate action.yml
76+
run: task --silent action:validate

.github/workflows/validate-action_yml.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ venv/
1818
*.bak
1919
*.code-workspace
2020
*.sublime-workspace
21+
22+
/node_modules/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# `arduino/compile-sketches` action
22

3+
[![Check Action Metadata status](https://github.com/arduino/compile-sketches/actions/workflows/check-action-metadata-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-action-metadata-task.yml)
34
[![Tests](https://github.com/arduino/compile-sketches/workflows/Test%20Python%20code/badge.svg)](https://github.com/arduino/compile-sketches/actions?workflow=Test+Python+code)
45
[![Lint](https://github.com/arduino/compile-sketches/workflows/Lint%20Python%20code/badge.svg)](https://github.com/arduino/compile-sketches/actions?workflow=Lint+Python+code)
56
[![Spell Check](https://github.com/arduino/compile-sketches/workflows/Spell%20Check/badge.svg)](https://github.com/arduino/compile-sketches/actions?workflow=Spell+Check)

Taskfile.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# See: https://taskfile.dev/#/usage
2+
version: "3"
3+
4+
tasks:
5+
check:
6+
desc: Check for problems with the project
7+
deps:
8+
- task: action:validate
9+
10+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-action-metadata-task/Taskfile.yml
11+
action:validate:
12+
desc: Validate GitHub Actions metadata against JSON schema
13+
vars:
14+
ACTION_METADATA_SCHEMA_PATH:
15+
sh: task utility:mktemp-file TEMPLATE="github-action-schema-XXXXXXXXXX.json"
16+
deps:
17+
- task: npm:install-deps
18+
cmds:
19+
- |
20+
wget \
21+
--quiet \
22+
--output-document="{{.ACTION_METADATA_SCHEMA_PATH}}" \
23+
https://json.schemastore.org/github-action
24+
- |
25+
npx \
26+
ajv-cli \
27+
validate \
28+
--strict=false \
29+
-s "{{.ACTION_METADATA_SCHEMA_PATH}}" \
30+
-d "action.yml"
31+
32+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
33+
npm:install-deps:
34+
desc: Install dependencies managed by npm
35+
run: once
36+
cmds:
37+
- npm install
38+
39+
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
40+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
41+
utility:mktemp-file:
42+
vars:
43+
RAW_PATH:
44+
sh: mktemp --tmpdir "{{.TEMPLATE}}"
45+
cmds:
46+
- task: utility:normalize-path
47+
vars:
48+
RAW_PATH: "{{.RAW_PATH}}"
49+
50+
# Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout
51+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
52+
utility:mktemp-folder:
53+
vars:
54+
RAW_PATH:
55+
sh: mktemp --directory --tmpdir "{{.TEMPLATE}}"
56+
cmds:
57+
- task: utility:normalize-path
58+
vars:
59+
RAW_PATH: "{{.RAW_PATH}}"
60+
61+
# Print a normalized version of the path passed via the RAW_PATH variable to stdout
62+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
63+
utility:normalize-path:
64+
cmds:
65+
- |
66+
if [[ "{{.OS}}" == "Windows_NT" ]] && which cygpath &>/dev/null; then
67+
# Even though the shell handles POSIX format absolute paths as expected, external applications do not.
68+
# So paths passed to such applications must first be converted to Windows format.
69+
cygpath -w "{{.RAW_PATH}}"
70+
else
71+
echo "{{.RAW_PATH}}"
72+
fi

0 commit comments

Comments
 (0)