-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Run checks and tests | ||
run-name: Run checks and tests ⚡️ | ||
on: | ||
push: | ||
paths: | ||
- '**.sh' | ||
jobs: | ||
shellcheck: | ||
name: Shellcheck | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run ShellCheck | ||
uses: ludeeus/action-shellcheck@master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# update-brew-tap-toc-action | ||
|
||
This GitHub action reads the Homebrew tap folder and procduces a table of content. | ||
The list of formulae is then placed in the specified files. | ||
|
||
## Example | ||
|
||
An example workflow can look like. | ||
|
||
```yaml | ||
name: Update TOC | ||
run-name: Update TOC 🚀 | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- Formula/*.rb | ||
- README.md | ||
jobs: | ||
update-toc: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Update TOC | ||
uses: qaware/update-brew-tap-toc-action@main | ||
|
||
- name: Commit & Push changes | ||
# Use some action that fits your needs | ||
``` | ||
|
||
You can pass options. | ||
|
||
```yaml | ||
# ... | ||
steps: | ||
- name: Update TOC | ||
uses: qaware/update-brew-tap-toc-action@main | ||
with: | ||
formula-folder: Formula-cstm | ||
replace-in: README.md,TOC.md,docs/content.adoc | ||
replace-marker-start: '// START TOC' | ||
replace-marker-end: '// END TOC' | ||
``` | ||
## Maintainers | ||
* Alexander Eimer ([@aeimer](https://github.com/aeimer)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: update-brew-tap-toc-action | ||
description: Reads the formulae stored in the tap (repo) and updates the list in the README | ||
author: aeimer | ||
inputs: | ||
formula-folder: | ||
description: The folder path from the repo root where the Formulae are placed | ||
required: true | ||
default: Formula | ||
replace-in: | ||
description: In which files should the TOC be updated. Eg. "README.md,docs/content.adoc" | ||
required: true | ||
default: README.md | ||
replace-marker-start: | ||
description: Where to replace the TOC starts | ||
required: true | ||
default: <!-- BEGIN TOC --> | ||
replace-marker-end: | ||
description: Where to replace the TOC ends | ||
required: true | ||
default: <!-- END TOC --> | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Update TOC | ||
shell: bash | ||
run: ${{ github.action_path }}/update-toc.sh | ||
env: | ||
INPUT_FORMULA_FOLDER: ${{ inputs.formula-folder }} | ||
INPUT_REPLACE_IN: ${{ inputs.replace-in }} | ||
INPUT_REPLACE_MARKER_START: ${{ inputs.replace-marker-start }} | ||
INPUT_REPLACE_MARKER_END: ${{ inputs.replace-marker-end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
# Enable debug - print commands | ||
#set -x | ||
|
||
############# | ||
# FUNCTIONS # | ||
############# | ||
|
||
function generateToc() { | ||
programNameList=() | ||
|
||
while read -r file; do | ||
programName=$(cut -d@ -f1 <<<"$file" | sed 's/.rb//') | ||
programNameList+=("$programName") | ||
done < <(find "$INPUT_FORMULA_FOLDER" -maxdepth 1 -type f -name '*.rb' -exec basename {} \; | sort) | ||
|
||
if [[ ${#programNameList[@]} == "0" ]]; then | ||
programNameList=("_n/a (no formula found)_") | ||
fi | ||
|
||
printf "* %s\n" "${programNameList[@]}" | sort -u | ||
} | ||
|
||
############### | ||
# CHECK INPUT # | ||
############### | ||
|
||
echo "Checking input" | ||
if [[ -z "${INPUT_FORMULA_FOLDER:-}" ]]; then | ||
echo "ERROR: No formula-folder defined" | ||
exit 1 | ||
fi | ||
echo " formula-folder: $INPUT_FORMULA_FOLDER" | ||
|
||
if [[ -z "${INPUT_REPLACE_IN:-}" ]]; then | ||
echo "ERROR: No replace-in defined" | ||
exit 1 | ||
fi | ||
echo " replace-in: $INPUT_REPLACE_IN" | ||
|
||
if [[ -z "${INPUT_REPLACE_MARKER_START:-}" ]]; then | ||
echo "ERROR: No replace-marker-start defined" | ||
exit 1 | ||
fi | ||
echo " replace-marker-start: $INPUT_REPLACE_MARKER_START" | ||
|
||
if [[ -z "${INPUT_REPLACE_MARKER_END:-}" ]]; then | ||
echo "ERROR: No replace-marker-end defined" | ||
exit 1 | ||
fi | ||
echo " replace-marker-start: $INPUT_REPLACE_MARKER_END" | ||
|
||
####### | ||
# RUN # | ||
####### | ||
|
||
echo "Generating TOC..." | ||
toc=$(generateToc) | ||
echo "TOC:" | ||
echo "----" | ||
echo "$toc" | ||
echo "----" | ||
|
||
for file in ${INPUT_REPLACE_IN//,/ }; do | ||
# https://stackoverflow.com/questions/2699666/replace-delimited-block-of-text-in-file-with-the-contents-of-another-file | ||
sed -i -ne '/'"$INPUT_REPLACE_MARKER_START"'/ {p; r '<(cat <<<"$toc") -e ':a; n; /'"$INPUT_REPLACE_MARKER_START"'/ {p; b}; ba}; p' "$file" | ||
done |