Skip to content

Commit

Permalink
Add action-readme pre-commit hook (#23)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
reakaleek authored Jun 4, 2024
1 parent a825eed commit 5d36f9f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .ci/scripts/action-readme.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)$
24 changes: 24 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 5d36f9f

Please sign in to comment.