From 8f4455253a0b4cf5cd1ccb911576b045a39ed662 Mon Sep 17 00:00:00 2001 From: Nathan Weinberg Date: Mon, 14 Oct 2024 11:45:45 -0400 Subject: [PATCH] ci: add linter for github actions this is an action we use in other instructlab repos to lint github actions within repos to ensure new or changed actions will run without issue Signed-off-by: Nathan Weinberg --- .github/workflows/actionlint.dockerfile | 3 ++ .github/workflows/actionlint.yml | 53 ++++++++++++++++++++++ .github/workflows/matchers/actionlint.json | 17 +++++++ 3 files changed, 73 insertions(+) create mode 100644 .github/workflows/actionlint.dockerfile create mode 100644 .github/workflows/actionlint.yml create mode 100644 .github/workflows/matchers/actionlint.json diff --git a/.github/workflows/actionlint.dockerfile b/.github/workflows/actionlint.dockerfile new file mode 100644 index 00000000..6f171d53 --- /dev/null +++ b/.github/workflows/actionlint.dockerfile @@ -0,0 +1,3 @@ +# Since dependabot cannot update workflows using docker, +# we use this indirection since dependabot can update this file. +FROM rhysd/actionlint:1.7.3@sha256:7617f05bd698cd2f1c3aedc05bc733ccec92cca0738f3e8722c32c5b42c70ae6 diff --git a/.github/workflows/actionlint.yml b/.github/workflows/actionlint.yml new file mode 100644 index 00000000..da8f5c2b --- /dev/null +++ b/.github/workflows/actionlint.yml @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: Apache-2.0 + +name: Lint GitHub Actions workflows +on: + push: + branches: + - "main" + - "release-**" + paths: + - '.github/actions/*.ya?ml' + - '.github/workflows/*.ya?ml' + - '.github/workflows/actionlint.*' # This workflow + pull_request: + branches: + - "main" + - "release-**" + paths: + - '.github/actions/*.ya?ml' + - '.github/workflows/*.ya?ml' + - '.github/workflows/actionlint.*' # This workflow + +env: + LC_ALL: en_US.UTF-8 + +defaults: + run: + shell: bash + +permissions: + contents: read + +jobs: + actionlint: + runs-on: ubuntu-latest + steps: + - name: "Harden Runner" + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs + + - name: "Checkout" + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + with: + fetch-depth: 0 + + - name: "Download actionlint" + run: | + docker build --tag actionlint - < .github/workflows/actionlint.dockerfile + + - name: "Check workflow files" + run: | + echo "::add-matcher::.github/workflows/matchers/actionlint.json" + docker run --volume="${PWD}:/repo" --workdir=/repo actionlint -color diff --git a/.github/workflows/matchers/actionlint.json b/.github/workflows/matchers/actionlint.json new file mode 100644 index 00000000..4613e161 --- /dev/null +++ b/.github/workflows/matchers/actionlint.json @@ -0,0 +1,17 @@ +{ + "problemMatcher": [ + { + "owner": "actionlint", + "pattern": [ + { + "regexp": "^(?:\\x1b\\[\\d+m)?(.+?)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*: (?:\\x1b\\[\\d+m)*(.+?)(?:\\x1b\\[\\d+m)* \\[(.+?)\\]$", + "file": 1, + "line": 2, + "column": 3, + "message": 4, + "code": 5 + } + ] + } + ] +}