From 1d03ed5f06f84db24dec0513324ebcdbaeae1ca0 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Sun, 21 Apr 2024 10:12:31 +1000 Subject: [PATCH] [#143] Added linting of the GitHub actions. --- .github/.yamllint-for-gha.yml | 17 +++++++++++++++++ .github/workflows/release-php.yml | 6 +++--- .github/workflows/test-actions.yml | 26 ++++++++++++++++++++++++++ .github/workflows/test-php.yml | 4 ++-- .github/workflows/test-scaffold.yml | 2 +- docs/content/ci/test.mdx | 13 ++++++++++++- 6 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 .github/.yamllint-for-gha.yml create mode 100644 .github/workflows/test-actions.yml diff --git a/.github/.yamllint-for-gha.yml b/.github/.yamllint-for-gha.yml new file mode 100644 index 0000000..3b57fff --- /dev/null +++ b/.github/.yamllint-for-gha.yml @@ -0,0 +1,17 @@ +# Yamllint configuration file used to check GitHub Actions configuration files. +extends: default + +rules: + comments: + min-spaces-from-content: 1 + document-start: + present: false + empty-lines: + max: 1 + max-start: 0 + max-end: 0 + line-length: + max: 255 + truthy: + allowed-values: ['true', 'false'] + check-keys: false diff --git a/.github/workflows/release-php.yml b/.github/workflows/release-php.yml index e6e1e5c..503b66b 100644 --- a/.github/workflows/release-php.yml +++ b/.github/workflows/release-php.yml @@ -30,17 +30,17 @@ jobs: - name: Install dependencies run: composer install - #;< PHP_PHAR + # yamllint disable-line #;< PHP_PHAR - name: Build PHAR run: composer build - name: Test PHAR run: ./.build/php-command.phar || exit 1 - #;> PHP_PHAR + # yamllint disable-line #;> PHP_PHAR - name: Get tag name id: get-version - run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + run: echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" - name: Create Release uses: softprops/action-gh-release@v2 diff --git a/.github/workflows/test-actions.yml b/.github/workflows/test-actions.yml new file mode 100644 index 0000000..5b47787 --- /dev/null +++ b/.github/workflows/test-actions.yml @@ -0,0 +1,26 @@ +name: Test Actions + +on: + push: + branches: + - main + pull_request: + branches: + - main + - 'feature/**' + +jobs: + test-actions: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check coding standards with yamllint + run: yamllint --config-file .github/.yamllint-for-gha.yml .github/workflows + continue-on-error: ${{ vars.CI_LINT_IGNORE_FAILURE == '1' }} + + - name: Check coding standards with actionlint + run: docker run --rm -v "${GITHUB_WORKSPACE:-.}":/app --workdir /app rhysd/actionlint:1.6.27 + continue-on-error: ${{ vars.CI_LINT_IGNORE_FAILURE == '1' }} diff --git a/.github/workflows/test-php.yml b/.github/workflows/test-php.yml index 2802eda..4ab18f6 100644 --- a/.github/workflows/test-php.yml +++ b/.github/workflows/test-php.yml @@ -57,7 +57,7 @@ jobs: fail_ci_if_error: true token: ${{ secrets.CODECOV_TOKEN }} - #;< PHP_PHAR + # yamllint disable-line #;< PHP_PHAR build-php: runs-on: ubuntu-latest steps: @@ -83,4 +83,4 @@ jobs: - name: Test PHAR run: ./.build/php-command.phar || exit 1 - #;> PHP_PHAR + # yamllint disable-line #;> PHP_PHAR diff --git a/.github/workflows/test-scaffold.yml b/.github/workflows/test-scaffold.yml index a279d63..b1129e6 100644 --- a/.github/workflows/test-scaffold.yml +++ b/.github/workflows/test-scaffold.yml @@ -42,7 +42,7 @@ jobs: run: npm --prefix=tests/scaffold ci - name: Run tests - run: kcov --include-pattern=.sh,.bash --bash-parse-files-in-dir=. --exclude-pattern=vendor,node_modules,.scaffold-coverage-html $(pwd)/.scaffold-coverage-html ./tests/scaffold/node_modules/.bin/bats tests/scaffold + run: kcov --include-pattern=.sh,.bash --bash-parse-files-in-dir=. --exclude-pattern=vendor,node_modules,.scaffold-coverage-html "$(pwd)"/.scaffold-coverage-html ./tests/scaffold/node_modules/.bin/bats tests/scaffold - name: Upload coverage report as an artifact uses: actions/upload-artifact@v4 diff --git a/docs/content/ci/test.mdx b/docs/content/ci/test.mdx index c506d37..6e534de 100644 --- a/docs/content/ci/test.mdx +++ b/docs/content/ci/test.mdx @@ -58,7 +58,7 @@ The workflow includes steps for linting, testing, and code coverage. [//]: # (#;< SHELL) -## Node.js job +## Shell job - Runs on a matrix of several OSes. - Checks out code. @@ -71,6 +71,17 @@ The workflow includes steps for linting, testing, and code coverage. [//]: # (#;> SHELL) +## Actions job + +Used to validate the GitHub Actions workflow files in the repository. + +- Checks out code. +- Runs code linting with [`yamllint`](https://github.com/adrienverge/yamllint) using [configuration](https://github.com/AlexSkrypnyk/scaffold/blob/main/.github/.yamllint-for-gha.yml) file. +- Runs code linting with [`actionlint`](https://github.com/rhysd/actionlint). + +Add `CI_LINT_IGNORE_FAILURE` with a value of `1` to your repository's variables +to ignore linting failures. + ## Code coverage The workflow publishes code coverage reports for PHP and Node.js projects to