From 89c0023b56228e4273fee097b8cccd7f35c4bc9a Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 4 Jun 2024 02:14:54 +0200 Subject: [PATCH 1/8] Add action-readme pre-commit hook --- .pre-commit-config.yaml | 7 +++++++ scripts/action-readme.sh | 8 ++++++++ 2 files changed, 15 insertions(+) create mode 100755 scripts/action-readme.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 06b2943b..b4572ff3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,3 +9,10 @@ repos: - id: end-of-file-fixer - id: mixed-line-ending - id: trailing-whitespace + - repo: local + hooks: + - id: action-readme + name: action-readme + entry: scripts/action-readme.sh + language: script + files: docs/ diff --git a/scripts/action-readme.sh b/scripts/action-readme.sh new file mode 100755 index 00000000..3ceb51b1 --- /dev/null +++ b/scripts/action-readme.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -euo pipefail + +find . \( -name "action.yml" -o -name "action.yaml" \) -exec dirname {} \; | while read -r dir; do + printf "%s: " "$dir" + gh action-readme update --action="$dir/action.yml" --readme="$dir/README.md" +done From 5b3fc90cc58b1dc093f4fed0a0dd267382ca5886 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 4 Jun 2024 09:36:22 +0200 Subject: [PATCH 2/8] fixes --- .ci/scripts/action-readme.sh | 19 +++++++++++++++++++ .pre-commit-config.yaml | 5 +++-- scripts/action-readme.sh | 8 -------- 3 files changed, 22 insertions(+), 10 deletions(-) create mode 100755 .ci/scripts/action-readme.sh delete mode 100755 scripts/action-readme.sh diff --git a/.ci/scripts/action-readme.sh b/.ci/scripts/action-readme.sh new file mode 100755 index 00000000..906321f7 --- /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 + gh action-readme update --action="$dir/action.yml" --readme="$dir/README.md" +done diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b4572ff3..7957b0fe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,6 +13,7 @@ repos: hooks: - id: action-readme name: action-readme - entry: scripts/action-readme.sh + entry: .ci/scripts/action-readme.sh language: script - files: docs/ + pass_filenames: false + files: (action.ya?ml|README.md)$ diff --git a/scripts/action-readme.sh b/scripts/action-readme.sh deleted file mode 100755 index 3ceb51b1..00000000 --- a/scripts/action-readme.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -find . \( -name "action.yml" -o -name "action.yaml" \) -exec dirname {} \; | while read -r dir; do - printf "%s: " "$dir" - gh action-readme update --action="$dir/action.yml" --readme="$dir/README.md" -done From 7fa540021581598e5ebb65961cba483d040cb000 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 4 Jun 2024 09:38:48 +0200 Subject: [PATCH 3/8] Fix pre-commit workflow --- .github/workflows/pre-commit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index a75390c4..b34dc084 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,5 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Install gh-action-readme + run: gh extension install actions/gh-action-readme --pin v0.2.0 - uses: actions/setup-python@v5 - uses: pre-commit/action@v3.0.1 From 2e05cd79a96cde93f8bfe39fadef36903a424b5a Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 4 Jun 2024 09:39:30 +0200 Subject: [PATCH 4/8] Fix gh usage --- .github/workflows/pre-commit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index b34dc084..8e18a7bb 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -15,5 +15,7 @@ jobs: - uses: actions/checkout@v4 - name: Install gh-action-readme run: gh extension install actions/gh-action-readme --pin v0.2.0 + env: + GH_TOKEN: ${{ github.token }} - uses: actions/setup-python@v5 - uses: pre-commit/action@v3.0.1 From fb150ae30ac5c9a6b1f82a6a59b004bef83f5f28 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 4 Jun 2024 09:40:16 +0200 Subject: [PATCH 5/8] fix gh cli extension name --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 8e18a7bb..3db9de0b 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install gh-action-readme - run: gh extension install actions/gh-action-readme --pin v0.2.0 + run: gh extension install reakaleek/gh-action-readme --pin v0.2.0 env: GH_TOKEN: ${{ github.token }} - uses: actions/setup-python@v5 From 435da4581d9d99ff716d59f2fd4f9acdbf08e424 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 4 Jun 2024 09:49:15 +0200 Subject: [PATCH 6/8] Add VERSION env --- .github/workflows/pre-commit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 3db9de0b..0687b0e4 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -19,3 +19,5 @@ jobs: GH_TOKEN: ${{ github.token }} - uses: actions/setup-python@v5 - uses: pre-commit/action@v3.0.1 + env: + VERSION: v1 # needed for the action-readme hook From 21817516dd607e00db1bbbe1bf673c20397d290c Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 4 Jun 2024 09:51:00 +0200 Subject: [PATCH 7/8] Move VERSION env to script --- .ci/scripts/action-readme.sh | 2 +- .github/workflows/pre-commit.yml | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.ci/scripts/action-readme.sh b/.ci/scripts/action-readme.sh index 906321f7..805a5362 100755 --- a/.ci/scripts/action-readme.sh +++ b/.ci/scripts/action-readme.sh @@ -15,5 +15,5 @@ function find_dirs_with_action_yml_and_readme_md() { } for dir in $(find_dirs_with_action_yml_and_readme_md); do - gh action-readme update --action="$dir/action.yml" --readme="$dir/README.md" + 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 0687b0e4..3db9de0b 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -19,5 +19,3 @@ jobs: GH_TOKEN: ${{ github.token }} - uses: actions/setup-python@v5 - uses: pre-commit/action@v3.0.1 - env: - VERSION: v1 # needed for the action-readme hook From 61f924159cfbbd717a092f808d8a80851cfdc0a8 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 4 Jun 2024 10:01:58 +0200 Subject: [PATCH 8/8] Add instructions for pre-commit and gh cli --- docs/CONTRIBUTING.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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)