diff --git a/STANDARDS.md b/STANDARDS.md index 27eb164..c7b086e 100644 --- a/STANDARDS.md +++ b/STANDARDS.md @@ -487,6 +487,12 @@ Settings, General, Social preview. Description, topics and homepage are set with `gh repo edit`. Those three are not tracked as files: GitHub's About box already holds them, and a copy in the repo would drift from it. +`configure.sh --diff` notes each part a public repo is missing: no +description, a topic count outside five to ten, no homepage while it publishes a +package, or the repo's own URL as homepage, no custom social preview, and a +README without the banner. These are `note:` lines, not drift, and never fail +`--diff`, since `--apply` could fix none of them. + ## Markdown markdownlint-cli2 and mdformat, both run by `markdown.yml`. mdformat owns diff --git a/scripts/configure.sh b/scripts/configure.sh index a76301a..9cdd678 100755 --- a/scripts/configure.sh +++ b/scripts/configure.sh @@ -18,7 +18,8 @@ # --diff compares the repo's live merge and Actions settings with settings/, # reports classic branch protection, which the ruleset does not replace, # checks the release tag ruleset in a public repo, and checks the branch policy -# of each publishing environment the workflows name. +# of each publishing environment the workflows name. In a public repo it then +# notes each part of the repository profile that is missing, without failing. # Actions may open PRs only in a repo whose workflows run release-please. # Needs an authenticated gh. Written for bash 3.2 (macOS's stock /bin/bash). @@ -330,6 +331,60 @@ check_environment() { " } +# Notes on the repository profile (STANDARDS.md, Repository profile), one +# `note:` line for each part a public repo is missing. Advice, not drift: the +# words are the owner's to write and GitHub has no API for the social preview, +# so --apply could not fix any of it, and none of it changes the exit status. +# A read that fails says so on stderr and skips that part, never failing --diff. +profile_notes() { + [ "$visibility" = public ] || return 0 + local about description homepage own topics custom readme banner + banner=.github/social/social-preview-banner.png + if about=$(gh api "repos/$repo" --jq '[.description // "", .homepage // "", (.topics // [] | length)] | @tsv'); then + description=$(printf '%s' "$about" | cut -f1) + homepage=$(printf '%s' "$about" | cut -f2) + topics=$(printf '%s' "$about" | cut -f3) + [ -n "$description" ] || echo "note: no description" + if [ "${topics:-0}" -lt 5 ] || [ "${topics:-0}" -gt 10 ]; then + echo "note: ${topics:-0} topics, STANDARDS.md asks for 5 to 10" + fi + # GitHub matches owner and repo names in any case. + own=$(printf '%s' "https://github.com/$repo" | tr '[:upper:]' '[:lower:]') + case "$(printf '%s' "$homepage" | tr '[:upper:]' '[:lower:]')" in + "$own" | "$own/") + echo "note: homepage is the repo's own URL; use its registry page or docs site, or leave it empty" + ;; + "") + if names_environment npm-release || names_environment pypi; then + echo "note: no homepage, though it publishes a package; use its registry page" + fi + ;; + esac + else + echo "note: could not read $repo's About box" >&2 + fi + # shellcheck disable=SC2016 # $owner and $name are GraphQL variables. + if custom=$(gh api graphql -f owner="${repo%%/*}" -f name="${repo#*/}" \ + -f query='query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { usesCustomOpenGraphImage } }' \ + --jq .data.repository.usesCustomOpenGraphImage); then + [ "$custom" = true ] || + echo "note: no custom social preview; upload one under Settings, General, Social preview" + else + echo "note: could not check $repo's social preview" >&2 + fi + # Only a 404 means there is no README; any other failure is unknown. + if readme=$(gh api "repos/$repo/readme" --jq .content 2>"$api_error"); then + case "$(printf '%s' "$readme" | base64 --decode)" in + *"$banner"*) ;; + *) echo "note: README does not open with the banner at $banner" ;; + esac + elif grep 'HTTP 404' "$api_error" >/dev/null; then + echo "note: no README" + else + echo "note: could not read $repo's README" >&2 + fi +} + if [ "$mode" = --diff ]; then # Command substitution drops trailing newlines, so print each part rather # than concatenating them. @@ -361,9 +416,11 @@ if [ "$mode" = --diff ]; then [ -z "$classic" ] || echo "$classic" [ -z "$tags" ] || echo "$tags" [ -z "$environment_drift" ] || printf '%s' "$environment_drift" + profile_notes exit 1 fi echo "$repo matches settings/ (release-please: $uses_release_please)" + profile_notes exit 0 fi