Skip to content

Commit

Permalink
Update infrastructure for action metadata validation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
per1234 committed Mar 25, 2023
1 parent 0b6522b commit 5bf853c
Show file tree
Hide file tree
Showing 7 changed files with 657 additions and 47 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/check-action-metadata-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-action-metadata-task.md
name: Check Action Metadata

env:
# See: https://github.com/actions/setup-node/#readme
NODE_VERSION: 16.x

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
create:
push:
paths:
- ".github/workflows/check-action-metadata-task.ya?ml"
- "action.ya?ml"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
pull_request:
paths:
- ".github/workflows/check-action-metadata-task.ya?ml"
- "action.ya?ml"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
schedule:
# Run every Tuesday at 8 AM UTC to catch breakage from changes to the JSON schema.
- cron: "0 8 * * TUE"
workflow_dispatch:
repository_dispatch:

jobs:
run-determination:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.determination.outputs.result }}
steps:
- name: Determine if the rest of the workflow should run
id: determination
run: |
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
if [[
"${{ github.event_name }}" != "create" ||
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
]]; then
# Run the other jobs.
RESULT="true"
else
# There is no need to run the other jobs.
RESULT="false"
fi
echo "result=$RESULT" >> $GITHUB_OUTPUT
validate:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Validate action.yml
run: task --silent action:validate
47 changes: 0 additions & 47 deletions .github/workflows/validate-action_yml.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ venv/
*.bak
*.code-workspace
*.sublime-workspace

/node_modules/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# `arduino/compile-sketches` action

[![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)
[![Tests](https://github.com/arduino/compile-sketches/workflows/Test%20Python%20code/badge.svg)](https://github.com/arduino/compile-sketches/actions?workflow=Test+Python+code)
[![Lint](https://github.com/arduino/compile-sketches/workflows/Lint%20Python%20code/badge.svg)](https://github.com/arduino/compile-sketches/actions?workflow=Lint+Python+code)
[![Spell Check](https://github.com/arduino/compile-sketches/workflows/Spell%20Check/badge.svg)](https://github.com/arduino/compile-sketches/actions?workflow=Spell+Check)
Expand Down
72 changes: 72 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# See: https://taskfile.dev/#/usage
version: "3"

tasks:
check:
desc: Check for problems with the project
deps:
- task: action:validate

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-action-metadata-task/Taskfile.yml
action:validate:
desc: Validate GitHub Actions metadata against JSON schema
vars:
ACTION_METADATA_SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="github-action-schema-XXXXXXXXXX.json"
deps:
- task: npm:install-deps
cmds:
- |
wget \
--quiet \
--output-document="{{.ACTION_METADATA_SCHEMA_PATH}}" \
https://json.schemastore.org/github-action
- |
npx \
ajv-cli \
validate \
--strict=false \
-s "{{.ACTION_METADATA_SCHEMA_PATH}}" \
-d "action.yml"
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
npm:install-deps:
desc: Install dependencies managed by npm
run: once
cmds:
- npm install

# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
utility:mktemp-file:
vars:
RAW_PATH:
sh: mktemp --tmpdir "{{.TEMPLATE}}"
cmds:
- task: utility:normalize-path
vars:
RAW_PATH: "{{.RAW_PATH}}"

# Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
utility:mktemp-folder:
vars:
RAW_PATH:
sh: mktemp --directory --tmpdir "{{.TEMPLATE}}"
cmds:
- task: utility:normalize-path
vars:
RAW_PATH: "{{.RAW_PATH}}"

# Print a normalized version of the path passed via the RAW_PATH variable to stdout
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
utility:normalize-path:
cmds:
- |
if [[ "{{.OS}}" == "Windows_NT" ]] && which cygpath &>/dev/null; then
# Even though the shell handles POSIX format absolute paths as expected, external applications do not.
# So paths passed to such applications must first be converted to Windows format.
cygpath -w "{{.RAW_PATH}}"
else
echo "{{.RAW_PATH}}"
fi
Loading

0 comments on commit 5bf853c

Please sign in to comment.