77 lines
2.6 KiB
Bash
Executable file
77 lines
2.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Publishes the public part of the repository to GitHub. Forgejo (origin) holds the
|
|
# whole history, internal documents included; GitHub gets the same history with the
|
|
# internal paths removed from every commit and tag, as if they had never been there.
|
|
#
|
|
# The rewrite is deterministic (dates, authors and messages are kept), so commits
|
|
# already published keep their hashes and a new publication only adds commits.
|
|
# Never `git push github` directly: its push URL is disabled for that reason.
|
|
#
|
|
# scripts/publish-github.sh # main and all tags
|
|
# DRY_RUN=1 scripts/publish-github.sh # rewrite and check only, print the result
|
|
set -euo pipefail
|
|
|
|
remote="${GITHUB_URL:-ssh://git@ssh.github.com:443/vrubelroman/chessPenguin.git}"
|
|
root="$(git rev-parse --show-toplevel)"
|
|
|
|
# Internal: the brief, the agent team, design and research notes, QA reports,
|
|
# developer notes, draft icons and the website (it lives on Forgejo only).
|
|
internal=(
|
|
"техническое задание.txt"
|
|
AGENTS.md
|
|
opencode.jsonc
|
|
.opencode
|
|
docs/agent-team.md
|
|
docs/architecture.md
|
|
docs/decisions.md
|
|
docs/implementation-plan.md
|
|
docs/research
|
|
docs/design
|
|
docs/qa
|
|
docs/dev
|
|
icons
|
|
website
|
|
scripts/publish-github.sh
|
|
)
|
|
|
|
work="$(mktemp -d)"
|
|
trap 'rm -rf "${work}"' EXIT
|
|
git clone --quiet --bare --no-local "${root}" "${work}/repo.git"
|
|
cd "${work}/repo.git"
|
|
# Only main and the tags are published: other branches (work in progress) are dropped
|
|
# from this copy before filtering.
|
|
git for-each-ref --format='%(refname)' refs/heads | { grep -vx 'refs/heads/main' || true; } | while read -r ref; do
|
|
git update-ref -d "${ref}"
|
|
done
|
|
|
|
quoted=""
|
|
for p in "${internal[@]}"; do
|
|
quoted+=" $(printf '%q' "${p}")"
|
|
done
|
|
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --force \
|
|
--index-filter "git rm -r -q --cached --ignore-unmatch --${quoted}" \
|
|
--tag-name-filter cat --prune-empty -- main --tags
|
|
|
|
# The backup refs of filter-branch keep the old history: drop them.
|
|
git for-each-ref --format='%(refname)' refs/original | while read -r ref; do
|
|
git update-ref -d "${ref}"
|
|
done
|
|
|
|
# Nothing internal may be left in any published commit.
|
|
for p in "${internal[@]}"; do
|
|
if [[ -n "$(git log --all --format=%H -- "${p}")" ]]; then
|
|
echo "publish-github.sh: ${p} is still in the history" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
if [[ -n "${DRY_RUN:-}" ]]; then
|
|
git log --oneline -5 main
|
|
git ls-tree -r --name-only main | grep -v '^crates/\|^apps/' | sed 's/^/ /'
|
|
git show-ref --tags --abbrev
|
|
exit 0
|
|
fi
|
|
|
|
git push --force "${remote}" main
|
|
git push --force "${remote}" --tags
|
|
echo "Published $(git rev-parse --short main) to ${remote}"
|