From 31c4cafaec2d4c14b11b91f91e472fa98e5be3a0 Mon Sep 17 00:00:00 2001 From: Altan Orhon Date: Tue, 24 Oct 2023 16:16:59 -0700 Subject: [PATCH] Build README.md via GitHub Action (#6) * Put README generation in GitHub Action --- .build/Makefile | 41 ------------------------------ .build/README.j2.md | 4 +-- .github/workflows/mkreadme.yml | 46 ++++++++++++++++++++++++++++++++++ README.md | 5 ++-- 4 files changed, 51 insertions(+), 45 deletions(-) delete mode 100644 .build/Makefile create mode 100644 .github/workflows/mkreadme.yml diff --git a/.build/Makefile b/.build/Makefile deleted file mode 100644 index db32fec..0000000 --- a/.build/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -SHELL := /bin/bash -.SHELLFLAGS := -e -O xpg_echo -o errtrace -o functrace -c -MAKEFLAGS += --no-builtin-rules -MAKEFLAGS += --no-builtin-variables -MAKE := $(make) -DATETIME_FORMAT := %(%Y-%m-%d %H:%M:%S)T -.ONESHELL: -.SUFFIXES: -.DELETE_ON_ERROR: - - -has_jinja := $(shell command -v jinja 2> /dev/null) - -REMOTE_NAME ?= origin -var_branch ?= main -var_repo_url := $(shell git config --get remote.$(REMOTE_NAME).url | sed -E 's/\.git$$//') -var_repo_name := $(shell git config --get remote.$(REMOTE_NAME).url | sed -E 's/\.git$$//; s/^.*github\.com\///') -var_raw_script_url := $(shell echo $(var_repo_url) | sed -E 's/github\.com/raw.githubusercontent.com/; s/\/tree\/.*//')/$(var_branch)/hyakvnc -var_container_registry := "oras://ghcr.io/maouw/hyakvnc_apptainer" -var_hyakvnc_apptainer_repo := "https://github.com/maouw/hyakvnc_apptainer" -config.inc.md: ../hyakvnc - $(shell sed -E '/^HYAKVNC_.*#\s*%%/!d; s/=.*(#\s*%%)/:/g; s/(^.)/- \1/g' $< > $@) - - -usage.inc.md: ../hyakvnc ## Generate usage documentatoin from `hyakvnc help` output - $(shell for x in create status show stop config install; do ../hyakvnc help "$$x" | sed -E '1 s/(.*)/\n### \1\n/; 2 s/^$$/```text/' | pr -e4 -t && echo '```'; done > $@) - -../README.md: README.j2.md usage.inc.md config.inc.md Makefile -ifndef has_jinja - $(error "jinja is not available. Please install jinja-cli with `pip install jinja-cli`") -endif - jinja -D repo_url $(var_repo_url) -D repo_name $(var_repo_name) -D container_registry $(var_container_registry) -D raw_script_url $(var_raw_script_url) -D hyakvnc_apptainer_repo $(var_hyakvnc_apptainer_repo) $< | sed 's/^.*.*$$//g' > $@ - -.PHONY: README -README: ../README.md - -.PHONY: clean -clean: - rm -f ../README.md usage.inc.md config.inc.md - -.DEFAULT_GOAL := README diff --git a/.build/README.j2.md b/.build/README.j2.md index 4fdefab..ae43b52 100644 --- a/.build/README.j2.md +++ b/.build/README.j2.md @@ -78,7 +78,7 @@ ssh your-uw-netid@klone.hyak.uw.edu After you've connected to the login node, you can download and install `hyakvnc` by running the following command. Copy and paste it into the terminal window where you are connected to the login node and press enter: ```bash -curl -o ~/.local/bin/hyakvnc --create-dirs -fsSL https://raw.githubusercontent.com/{{ repo_name }}/main/hyakvnc && chmod +x ~/.local/bin/hyakvnc && [[ ":${PATH}:" != *":$HOME/.local/bin:"* ]] && export PATH="$HOME/.local/bin:$PATH" && [-n "${ZSH_VERSION:-}" ] && rehash +curl -o ~/.local/bin/hyakvnc --create-dirs -fsSL https://raw.githubusercontent.com/{{github_repository}}/{{github_ref_name}}/hyakvnc && chmod +x ~/.local/bin/hyakvnc && [[ ":${PATH}:" != *":$HOME/.local/bin:"* ]] && export PATH="$HOME/.local/bin:$PATH" && [-n "${ZSH_VERSION:-}" ] && rehash ``` This will download and install `hyakvnc` to your `~/.local/bin` directory and add it to your `$PATH` so you can run it by typing `hyakvnc` into the terminal window. @@ -88,7 +88,7 @@ This will download and install `hyakvnc` to your `~/.local/bin` directory and ad In a terminal window connected to a login node, enter this command to clone the repository and navigate into the repository directory: ```bash -git clone {{ repo_url }} && cd hyakvnc +git clone https://github.com/{{github_repository}} && cd hyakvnc ``` Then, run the following command to install `hyakvnc`: diff --git a/.github/workflows/mkreadme.yml b/.github/workflows/mkreadme.yml new file mode 100644 index 0000000..7d98a26 --- /dev/null +++ b/.github/workflows/mkreadme.yml @@ -0,0 +1,46 @@ +name: Build documentation +"on": + push: + +jobs: + build-readme: + runs-on: ubuntu-latest + name: Build README.md + permissions: write-all + steps: + - name: Install jinja-cli + run: | + python3 -m pip install jinja-cli + - name: Check out code for the container build + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Check if README.md has changed + id: readme-changed + run: | + if git --no-pager diff --name-only --quiet --diff-filter=AM ${{ github.event.before }} ${{ github.event.after }} -- hyakvnc .build/README.j2.md .github/workflows/mkreadme.yml; then + gh run cancel ${{ github.run_id }} + gh run watch ${{ github.run_id }} + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Generate configuration descriptions + run: | + pushd .build/ + sed -E '/^HYAKVNC_.*#\s*%%/!d; s/=.*(#\s*%%)/:/g; s/(^.)/- \1/g' ../hyakvnc > config.inc.md + popd + - name: Generate usage descriptions + run: | + pushd .build/ + for x in create status show stop config install; do ../hyakvnc help "$x" | sed -E '1 s/(.*)/\n### \1\n/; 2 s/^$/```text/' | pr -e4 -t && echo '```'; done > usage.inc.md + popd + - name: Create and push README.md + run: | + pushd .build/ + jinja -D github_repository "${{ github.repository }}" -D github_ref_name "${{ github.ref_name }}" README.j2.md | sed 's/^.*.*$//g' > ../README.md + popd + git config --local user.email "${{ github.event.sender.id }}+${{ github.event.sender.login }}@users.noreply.github.com" + git config --local user.name ${{ github.event.sender.login }} + git add README.md + git commit -am "Update README.md" + git push diff --git a/README.md b/README.md index e945dff..15f538e 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ ssh your-uw-netid@klone.hyak.uw.edu After you've connected to the login node, you can download and install `hyakvnc` by running the following command. Copy and paste it into the terminal window where you are connected to the login node and press enter: ```bash -curl -o ~/.local/bin/hyakvnc --create-dirs -fsSL https://raw.githubusercontent.com/maouw/hyakvnc/main/hyakvnc && chmod +x ~/.local/bin/hyakvnc && [[ ":${PATH}:" != *":$HOME/.local/bin:"* ]] && export PATH="$HOME/.local/bin:$PATH" && [-n "${ZSH_VERSION:-}" ] && rehash +curl -o ~/.local/bin/hyakvnc --create-dirs -fsSL https://raw.githubusercontent.com/maouw/hyakvnc/mkreadme-gha/hyakvnc && chmod +x ~/.local/bin/hyakvnc && [[ ":${PATH}:" != *":$HOME/.local/bin:"* ]] && export PATH="$HOME/.local/bin:$PATH" && [-n "${ZSH_VERSION:-}" ] && rehash ``` This will download and install `hyakvnc` to your `~/.local/bin` directory and add it to your `$PATH` so you can run it by typing `hyakvnc` into the terminal window. @@ -245,7 +245,7 @@ Examples: Usage: hyakvnc config [config options...] Description: - Show the current configuration for hyakvnc, as set in the user configuration file at /home/altan/.hyakvnc/hyakvnc-config.env, in the current environment, or the default values set by hyakvnc. + Show the current configuration for hyakvnc, as set in the user configuration file at /home/runner/.hyakvnc/hyakvnc-config.env, in the current environment, or the default values set by hyakvnc. Options: -h, --help Show this help message and exit @@ -291,6 +291,7 @@ When you set an environment variable, it is advisable to surround the value with The following variables are available: - HYAKVNC_DIR: Local directory to store application data (default: `$HOME/.hyakvnc`) +- HYAKVNC_CHECK_UPDATE_FREQUENCY: How often to check for updates in `[d]`ays or `[m]`inutes (default: `0` for every time. Use `1d` for daily, `10m` for every 10 minutes, etc. `-1` to disable.) - HYAKVNC_CONFIG_FILE: Configuration file to use (default: `$HYAKVNC_DIR/hyakvnc-config.env`) - HYAKVNC_LOG_FILE: Log file to use (default: `$HYAKVNC_DIR/hyakvnc.log`) - HYAKVNC_LOG_LEVEL: Log level to use for interactive output (default: `INFO`)