Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/how-to/migrate-from-gh-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ migration has the same inputs — and it deploys to *your* `github.io`, never up
1. **Fork the repo and enable Actions on the fork** (the **Actions** tab → enable
workflows; forks start with Actions disabled). You have admin on your own fork,
which is what the Pages-source flip in step 2 needs.
2. **Run `migrate.sh` against the fork**, from a clone of it — dry-run first, then for
real:
2. **Run `migrate.sh` against the fork** — dry-run first, then for real:

```bash
scripts/migrate.sh FORKORG/REPO --dry-run
Expand Down Expand Up @@ -88,12 +87,13 @@ tag to the fork if you also want to rehearse the tag re-dispatch.

## Before you start

- `gh` authenticated with **repo-admin** on the target repo (flipping the Pages source
and setting the environment policy need admin; a CI token can't — which is why this is
a local script).
- Run the script from **inside a clone of the target repo**: it reads the repo's tags
and `gh-pages` tree from the working directory (it fetches `origin/gh-pages` for you).
Running it from anywhere else will find no tags/branches.
- Run the script from the **myst-version-switcher-plugin devcontainer** (it needs `gh`,
`zip`, and `node`, which the devcontainer provides).
- Authenticate `gh` with **repo-admin** on the target repo — run `gh auth login` if
needed (flipping the Pages source and setting the environment policy need admin; a CI
token can't — which is why this is a local script).
- If the script detects it is running in a clone of the target repo it will use that,
otherwise it will clone the repo itself.

## Step 1 — dry-run (recommended)

Expand Down
17 changes: 15 additions & 2 deletions scripts/migrate.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env bash
#
# One-time gh-pages → durable-source migration, run LOCALLY by an operator from
# inside a clone of the TARGET repo (it reads that repo's tags and gh-pages tree
# from the working directory; it fetches origin/gh-pages itself).
# the myst-version-switcher-plugin devcontainer. If the script detects it is
# already running inside a clone of the target repo it will use that; otherwise
# it clones the repo itself into a temporary directory.
#
# Why local, not CI (see docs/how-to/migrate-from-gh-pages.md):
# - flipping the Pages source needs repo-admin, which a CI GITHUB_TOKEN lacks;
Expand Down Expand Up @@ -76,6 +77,18 @@ OWNER="${REPO%%/*}"
NAME="${REPO##*/}"
BASE="https://$(echo "$OWNER" | tr '[:upper:]' '[:lower:]').github.io/$NAME"

# Clone the target repo if not already running inside it.
_tmp_clone=""
trap '[ -n "$_tmp_clone" ] && rm -rf "$_tmp_clone"' EXIT
_current_origin=$(git remote get-url origin 2>/dev/null || echo "")
_normalized=$(printf '%s' "$_current_origin" | sed 's|.*github\.com[:/]||; s|\.git$||')
if [ "$_normalized" != "$REPO" ]; then
_tmp_clone=$(mktemp -d)
git clone "https://github.com/$REPO.git" "$_tmp_clone"
cd "$_tmp_clone"
fi
unset _current_origin _normalized

# Fetch the gh-pages ref into its remote-tracking ref (a bare `git fetch origin
# gh-pages` only guarantees FETCH_HEAD; we read `$PAGES_REF` by name).
fetch_pages_ref() {
Expand Down