From 736f5114bf968328caf09f037f77b7e4201b283a Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 19 Jul 2023 14:12:56 +0200 Subject: [PATCH 1/4] id.mk: Bypass default-branch detection outside of github.com in favor of 'main' The DEFAULT_BRANCH environment variable can still be used to override it. --- id.mk | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/id.mk b/id.mk index 270f5389..8d612b3e 100644 --- a/id.mk +++ b/id.mk @@ -111,7 +111,14 @@ BRANCH_FETCH := true endif export BRANCH_FETCH ifeq (,$(DEFAULT_BRANCH)) +ifeq (github.com,$(GITHUB_HOST)) DEFAULT_BRANCH := $(shell BRANCH_FETCH=$(BRANCH_FETCH) $(LIBDIR)/default-branch.py $(GITHUB_USER) $(GITHUB_REPO) $(GITHUB_API_TOKEN)) +else +# default-branch.py recognition only works on GitHub; on other hosters it needs +# to be set manually (also around setup.mk!), or they just use the default +# value. +DEFAULT_BRANCH := main +endif endif export DEFAULT_BRANCH From 800285fbd7885aa863ac9bd5bd3bd274bfef9975 Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 19 Jul 2023 14:14:06 +0200 Subject: [PATCH 2/4] setup-readme: Use host argument This change may need some revisiting, because it copies over code from the build-index.sh. --- setup-readme.sh | 33 ++++++++++++++++++++++++++------- setup.mk | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/setup-readme.sh b/setup-readme.sh index caca4e6f..f06b073b 100755 --- a/setup-readme.sh +++ b/setup-readme.sh @@ -1,13 +1,32 @@ #!/usr/bin/env bash -# Usage: $0 [draftxml ...] - -user="$1" -repo="$2" +# Usage: $0 github.com [draftxml ...] + +host="$1" +user="$2" +repo="$3" +# This is not overridden for non-github hosts because the typical way this is +# called is through setup.mk anyway, which exports DEFAULT_BRANCH +# unconditionally default_branch="${DEFAULT_BRANCH:-$("$(dirname "$0")/default-branch.py")}" -shift 2 - -githubio="https://${user}.github.io/${repo}/#go" +shift 3 + +case "$host" in + codeberg.org) + hostpages="codeberg.page" + ;; + github.com) + hostpages="github.io" + ;; + gitlab.com) + hostpages="gitlab.io" + ;; + *) + hostpages="pages.${host}" + ;; +esac + +githubio="https://${user}.${hostpages}/${repo}/#go" function fixup_other_md() { markdown=(LICENSE.md CONTRIBUTING.md) diff --git a/setup.mk b/setup.mk index d3e3a2a3..66bab222 100644 --- a/setup.mk +++ b/setup.mk @@ -84,7 +84,7 @@ endif git add $< README.md: $(LIBDIR)/setup-readme.sh $(drafts_xml) $(filter %.md, $(TEMPLATE_FILES)) - $(LIBDIR)/setup-readme.sh $(GITHUB_USER) $(GITHUB_REPO) $(filter %.xml,$^) >$@ + $(LIBDIR)/setup-readme.sh $(GITHUB_HOST) $(GITHUB_USER) $(GITHUB_REPO) $(filter %.xml,$^) >$@ git add $@ $(filter %.md, $(TEMPLATE_FILES)) .PHONY: setup-note From ae4cd3aa030c19627a55d778309dae27b5e5eb55 Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 19 Jul 2023 14:23:44 +0200 Subject: [PATCH 3/4] setup-readme: Build per-hoster src_base to which CONTRIBUTING.md can be appended --- setup-readme.sh | 11 ++++++----- template/LICENSE.md | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/setup-readme.sh b/setup-readme.sh index f06b073b..d867c74e 100755 --- a/setup-readme.sh +++ b/setup-readme.sh @@ -13,15 +13,19 @@ shift 3 case "$host" in codeberg.org) + src_base="https://${host}/${user}/${repo}/src/branch/${default_branch}/" hostpages="codeberg.page" ;; github.com) + src_base="https://${host}/${user}/${repo}/blob/${default_branch}/" hostpages="github.io" ;; gitlab.com) + src_base="https://${host}/${user}/${repo}/-/blob/${default_branch}/" hostpages="gitlab.io" ;; *) + src_base="./" hostpages="pages.${host}" ;; esac @@ -30,10 +34,7 @@ githubio="https://${user}.${hostpages}/${repo}/#go" function fixup_other_md() { markdown=(LICENSE.md CONTRIBUTING.md) - s='s~{WG_NAME}~'"$1"'~g' - s="$s"';s~{GITHUB_USER}~'"$user"'~g' - s="$s"';s~{GITHUB_REPO}~'"$repo"'~g' - s="$s"';s~{GITHUB_BRANCH}~'"$default_branch"'~g' + s="$s"';s~{SRC_BASE}~'"$src_base"'~g' sed -i~ -e "$s" "${markdown[@]}" for i in "${markdown[@]}"; do rm -f "$i"~ @@ -101,7 +102,7 @@ cat < Date: Wed, 19 Jul 2023 14:24:48 +0200 Subject: [PATCH 4/4] setup-readme: Replace hardcoded "GitHub" with host-dependent name --- setup-readme.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup-readme.sh b/setup-readme.sh index d867c74e..c6bc04bb 100755 --- a/setup-readme.sh +++ b/setup-readme.sh @@ -105,7 +105,7 @@ See the [guidelines for contributions](${src_base}CONTRIBUTING.md). Contributions can be made by creating pull requests. -The GitHub interface supports creating pull requests using the Edit (✏) button. +The ${host} interface supports creating pull requests using the Edit (✏) button. ## Command Line Usage @@ -147,7 +147,7 @@ Discussion of this work occurs on the [${group_name} ${group_type} mailing list](mailto:${ml}) ([archive](${ml_arch}), [subscribe](${ml_sub})). -In addition to contributions in GitHub, you are encouraged to participate in +In addition to contributions in ${host}, you are encouraged to participate in discussions there. **Note**: Some working groups adopt a policy whereby substantive discussion of