docs: fix mc-gate module readme description & links #16
This file contains hidden or 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
| name: Update docs | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'pkgs/**' | |
| - 'modules/**' | |
| - 'flake.nix' | |
| - 'flake.lock' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| update-docs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: DeterminateSystems/nix-installer-action@main | |
| - name: Generate package and module tables | |
| run: | | |
| set -euo pipefail | |
| # --- Packages --- | |
| pkg_json=$(nix eval .#packages.x86_64-linux \ | |
| --apply 'pkgs: builtins.mapAttrs (name: pkg: pkg.version or "N/A") pkgs' \ | |
| --json) | |
| pkg_table=$(echo "$pkg_json" | jq -r ' | |
| to_entries | |
| | sort_by(.key) | |
| | ["| Package | Version |", "|---|---|"] | |
| + map("| `\(.key)` | `\(.value)` |") | |
| | .[] | |
| ') | |
| # --- Modules --- | |
| make_module_table() { | |
| local base_dir="$1" | |
| local table="| Module | Docs |" | |
| table+=$'\n'"|---|---|" | |
| while IFS= read -r nix_file; do | |
| rel="${nix_file#${base_dir}/}" | |
| dir="$(dirname "$rel")" | |
| basename="$(basename "$rel")" | |
| if [ "$basename" = "default.nix" ]; then | |
| mod_path="$dir" | |
| else | |
| mod_path="$dir/$(echo "$basename" | sed 's/\.nix$//')" | |
| fi | |
| attr_path=$(echo "$mod_path" | tr '/' '.') | |
| mod_dir="$(dirname "$nix_file")" | |
| if [ -f "$mod_dir/README.md" ]; then | |
| docs="[README]($mod_dir/README.md)" | |
| else | |
| docs="-" | |
| fi | |
| table+=$'\n'"| \`$attr_path\` | $docs |" | |
| done < <(find "$base_dir" -name '*.nix' | sort) | |
| printf '%s\n' "$table" | |
| } | |
| nixos_mod_table=$(make_module_table modules/nixos) | |
| home_manager_mod_table=$(make_module_table modules/home-manager) | |
| # --- Patch README.md --- | |
| # Replace content between markers | |
| awk -v pkg="$pkg_table" -v nixos_mods="$nixos_mod_table" -v home_manager_mods="$home_manager_mod_table" ' | |
| /<!-- BEGIN PACKAGES -->/ { print; print pkg; skip=1; next } | |
| /<!-- END PACKAGES -->/ { skip=0 } | |
| /<!-- BEGIN NIXOS MODULES -->/ { print; print nixos_mods; skip=1; next } | |
| /<!-- END NIXOS MODULES -->/ { skip=0 } | |
| /<!-- BEGIN HOME MANAGER MODULES -->/ { print; print home_manager_mods; skip=1; next } | |
| /<!-- END HOME MANAGER MODULES -->/ { skip=0 } | |
| !skip { print } | |
| ' README.md > README.md.tmp | |
| mv README.md.tmp README.md | |
| - name: Create pull request | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| commit-message: "docs: update package and module listings" | |
| title: "docs: update package and module listings" | |
| body: | | |
| Automated update of README.md package and module tables. | |
| This PR was generated by the `update-docs` workflow. | |
| branch: docs/update-listings | |
| delete-branch: true |