From 5d36f9f8b8b21ed8c50fe5d59b788e5b1da45ab1 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 4 Jun 2024 10:16:23 +0200 Subject: [PATCH] Add action-readme pre-commit hook (#23) * Add action-readme pre-commit hook * fixes * Fix pre-commit workflow * Fix gh usage * fix gh cli extension name * Add VERSION env * Move VERSION env to script * Add instructions for pre-commit and gh cli --- .ci/scripts/action-readme.sh | 19 +++++++++++++++++++ .github/workflows/pre-commit.yml | 4 ++++ .pre-commit-config.yaml | 8 ++++++++ docs/CONTRIBUTING.md | 24 ++++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100755 .ci/scripts/action-readme.sh diff --git a/.ci/scripts/action-readme.sh b/.ci/scripts/action-readme.sh new file mode 100755 index 00000000..805a5362 --- /dev/null +++ b/.ci/scripts/action-readme.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# This script updates the README.md files in the directories that contain both an action.yml and a README.md file. +# Prerequisites: +# - gh: GitHub CLI +# +set -euo pipefail + +function find_dirs_with_action_yml_and_readme_md() { + find . \( -name 'action.yml' -o -name 'README.md' \) -exec dirname {} \; \ + | sort \ + | uniq -c \ + | grep -E '^\s+2' \ + | awk '{ print $2 }' +} + +for dir in $(find_dirs_with_action_yml_and_readme_md); do + VERSION=v1 gh action-readme update --action="$dir/action.yml" --readme="$dir/README.md" +done diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index a75390c4..3db9de0b 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,5 +13,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Install gh-action-readme + run: gh extension install reakaleek/gh-action-readme --pin v0.2.0 + env: + GH_TOKEN: ${{ github.token }} - uses: actions/setup-python@v5 - uses: pre-commit/action@v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 06b2943b..7957b0fe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,3 +9,11 @@ repos: - id: end-of-file-fixer - id: mixed-line-ending - id: trailing-whitespace + - repo: local + hooks: + - id: action-readme + name: action-readme + entry: .ci/scripts/action-readme.sh + language: script + pass_filenames: false + files: (action.ya?ml|README.md)$ diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 26aba05f..700de8e9 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -1,5 +1,29 @@ # Contribution Guidelines +## Prerequisites + +### Pre-commit + +This repository uses [pre-commit](https://pre-commit.com/) to enforce code quality. +To install pre-commit follow the instructions [here](https://pre-commit.com/#install). + +After installing pre-commit, run the following command to install the pre-commit hooks: + +```bash +pre-commit install +``` + +### GitHub CLI + +This repository uses the [gh-action-readme](https://github.com/reakaleek/gh-action-readme) GitHub CLI extension to generate and update the `README.md` files for the actions. +To install the GitHub CLI follow the instructions [here](https://github.com/cli/cli#installation). + +After installing the GitHub CLI, run the following command to install the `gh-action-readme` extension: + +```bash +gh extension install reakaleek/gh-action-readme +``` + ## Action Documentation Every action should have a `README.md` file in its directory. The `README.md` file is generated and updated by the [gh-action-readme](https://github.com/reakaleek/gh-action-readme)