Skip to content

Commit

Permalink
Merge pull request arduino#121 from per1234/check-workflows
Browse files Browse the repository at this point in the history
Add infrastructure to validate GitHub Actions workflows
  • Loading branch information
per1234 authored Mar 25, 2023
2 parents 1c249bf + 1c1267e commit 71e88e7
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/check-workflows-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-workflows-task.md
name: Check Workflows

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

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

jobs:
validate:
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 workflows
run: task --silent ci:validate
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[![Check Python status](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml)
[![Check Taskfiles status](https://github.com/arduino/compile-sketches/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-taskfiles.yml)
[![Check ToC status](https://github.com/arduino/compile-sketches/actions/workflows/check-toc-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-toc-task.yml)
[![Check Workflows status](https://github.com/arduino/compile-sketches/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-workflows-task.yml)
[![Spell Check status](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml)
[![Sync Labels status](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml)
[![Test Python status](https://github.com/arduino/compile-sketches/actions/workflows/test-python-poetry-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/test-python-poetry-task.yml)
Expand Down
29 changes: 29 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tasks:
desc: Check for problems with the project
deps:
- task: action:validate
- task: ci:validate
- task: general:check-formatting
- task: general:check-spelling
- task: markdown:check-links
Expand Down Expand Up @@ -53,6 +54,34 @@ tasks:
-s "{{.ACTION_METADATA_SCHEMA_PATH}}" \
-d "action.yml"
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml
ci:validate:
desc: Validate GitHub Actions workflows against their JSON schema
vars:
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow
WORKFLOW_SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="workflow-schema-XXXXXXXXXX.json"
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
deps:
- task: npm:install-deps
cmds:
- |
wget \
--quiet \
--output-document="{{.WORKFLOW_SCHEMA_PATH}}" \
{{.WORKFLOW_SCHEMA_URL}}
- |
npx \
--package=ajv-cli \
--package=ajv-formats \
ajv validate \
--all-errors \
--strict=false \
-c ajv-formats \
-s "{{.WORKFLOW_SCHEMA_PATH}}" \
-d "{{.WORKFLOWS_DATA_PATH}}"
docs:generate:
desc: Create all generated documentation content
# This is an "umbrella" task used to call any documentation generation processes the project has.
Expand Down

0 comments on commit 71e88e7

Please sign in to comment.