Skip to content

greenc-FNAL checking GitHub Actions workflows #1221

greenc-FNAL checking GitHub Actions workflows

greenc-FNAL checking GitHub Actions workflows #1221

name: Actionlint Check
run-name: "${{ github.actor }} checking GitHub Actions workflows"
permissions:
contents: read
pull-requests: read
"on":
pull_request:
workflow_dispatch:
inputs:
ref:
description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch."
required: false
type: string
workflow_call:
inputs:
checkout-path:
description: "Path to check out code to"
required: false
type: string
skip-relevance-check:
description: "Bypass relevance check"
required: false
type: boolean
default: false
pr-base-sha:
description: "Base SHA of the PR for relevance check"
required: false
type: string
pr-head-sha:
description: "Head SHA of the PR for relevance check"
required: false
type: string
ref:
description: "The branch, ref, or SHA to checkout"
required: false
type: string
repo:
description: "The repository to checkout from"
required: false
type: string
jobs:
setup:
runs-on: ubuntu-latest
outputs:
is_act: ${{ steps.setup.outputs.is_act }}
ref: ${{ steps.setup.outputs.ref }}
repo: ${{ steps.setup.outputs.repo }}
base_sha: ${{ steps.setup.outputs.base_sha }}
pr_number: ${{ steps.setup.outputs.pr_number }}
checkout_path: ${{ steps.setup.outputs.checkout_path }}
has_changes: ${{ steps.setup.outputs.has_changes }}
steps:
- name: Workflow setup
id: setup
uses: Framework-R-D/phlex/.github/actions/workflow-setup@main
with:
include-globs: |
.github/workflows/**/*.yml
.github/workflows/**/*.yaml
.github/actions/**/*.yml
.github/actions/**/*.yaml
head-ref: ${{ inputs.pr-head-sha }}
ref: ${{ inputs.ref }}
repo: ${{ inputs.repo }}
pr-base-sha: ${{ inputs.pr-base-sha }}
checkout-path: ${{ inputs.checkout-path }}
actionlint-check:
needs: setup
if: >
always() && (
github.event_name == 'workflow_dispatch' ||
inputs.skip-relevance-check ||
needs.setup.outputs.has_changes == 'true'
)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ needs.setup.outputs.ref }}
path: ${{ needs.setup.outputs.checkout_path }}
repository: ${{ needs.setup.outputs.repo }}
persist-credentials: false
- name: Announce actionlint check
run: echo "➡️ Running actionlint check..."
- name: Run actionlint
id: lint
env:
CHECKOUT_PATH: ${{ needs.setup.outputs.checkout_path }}
run: |
docker run --rm \
-v "$GITHUB_WORKSPACE/${CHECKOUT_PATH}:/work" \
-w /work \
rhysd/actionlint:latest \
-config-file .github/actionlint.yaml
continue-on-error: true
- name: Evaluate actionlint result
if: always() && steps.lint.outcome != 'skipped'
run: |
if [ "${{ steps.lint.outcome }}" = 'success' ]; then
echo "✅ actionlint check passed."
else
echo "::error::actionlint check failed. Please review the output above for details."
exit 1
fi