Skip to content

Commit 30eae48

Browse files
committed
Implement a two-way mirroring between the wiki and its public repo
Previously, changes to the wiki would get merged to the public repo in a once-a-week action. This significantly revises this, making the two sides be mirrors (up to the few seconds it takes to do a merge). This is driven by a minimal-ish yaml file in both sides (`TypeScript` and `TypeScript-wiki`) that *always* works from the script in the public repo. The two action specs are nearly identical, but there are some differences: - On the main repo, trigger on a `gollum` event, and in the wiki repo the usual (pushes, schedule, manual). (The schedule run is kept as a just-in-case, and it's now running twice a week.) - The filename is `sync-wiki` on the TS side and just `sync` in the wiki. (Good to avoid confusion if both files somehow find themselves in the same neighborhood.) - The secret names are different since I used the name that already exists in each side. The script does *not* start with a checkout of its repository. Doing this in the TS side would be redundant (it would get the TS tree) and slow. Instead, it's always cloning the public wiki repo (`DASHREMOTE`, since its url is `.../TypeScript-wiki`) and then fetching into it the repo of the rendered wiki (`DOTREMOTE`, with a `.../TypeScript.wiki`) url. Also revised the README, since they should always be mirrored with this change, and therefore there is no "source of truth".
1 parent 567dac5 commit 30eae48

File tree

3 files changed

+57
-34
lines changed

3 files changed

+57
-34
lines changed

.github/workflows/sync

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
set -ue
4+
shopt -s extglob
5+
6+
PUSHER="${PUSHER// +( )/ }"; PUSHER="${PUSHER# }"; PUSHER="${PUSHER% }"
7+
NAME="${PUSHER% <*}"
8+
EMAIL="${PUSHER##* <}"; EMAIL="${EMAIL%>}"
9+
echo "Setting git username to \"$NAME\" and email to \"$EMAIL\""
10+
export GIT_AUTHOR_NAME="$NAME"
11+
export GIT_AUTHOR_EMAIL="$EMAIL"
12+
export GIT_COMMITTER_NAME="$NAME"
13+
export GIT_COMMITTER_EMAIL="$EMAIL"
14+
15+
DASHREMOTE="$(git remote get-url origin)"
16+
DOTREMOTE="${DASHREMOTE//-wiki/.wiki}"
17+
echo "\$DASHREMOTE = $DASHREMOTE, \$DOTREMOTE = $DOTREMOTE"
18+
19+
for r in "$DASHREMOTE" "$DOTREMOTE"; do
20+
if [[ "$(git ls-remote --symref "$r" HEAD | grep "^ref:")" \
21+
!= $'ref: refs/heads/master\tHEAD' ]]; then
22+
echo "Unexpected branch name at $r: expected to see \"master\""
23+
fi
24+
done
25+
26+
echo ">>> Adding DOTREMOTE"
27+
git remote add dot "$DOTREMOTE"
28+
git fetch dot
29+
30+
echo ">>> Merging changes"
31+
git pull --no-edit --no-rebase dot "master"
32+
33+
echo ">>> Pushing merges"
34+
git push origin
35+
git push dot

.github/workflows/sync.yml

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,27 @@
1-
# Based on https://www.growingwiththeweb.com/2016/07/enabling-pull-requests-on-github-wikis.html
1+
# Roughly based on
2+
# https://www.growingwiththeweb.com/2016/07/enabling-pull-requests-on-github-wikis.html
3+
24
name: Sync Two Wiki Repos
35

46
on:
5-
# Merged PRs
6-
push:
7-
branches: [master]
8-
# Weekly
9-
schedule:
10-
# https://crontab.guru/#0_12_*_*_1
11-
- cron: "0 12 * * 1"
12-
# Whenever someone asks
13-
workflow_dispatch:
7+
push: {branches: [master]}
8+
schedule: [{cron: "7 0 * * 1,3"}] # https://crontab.guru/#7_0_*_*_1,3
9+
workflow_dispatch: # on request
1410

1511
jobs:
1612
sync:
1713
runs-on: ubuntu-latest
1814
steps:
19-
- uses: actions/checkout@v1
20-
21-
# Setup Git
22-
- run: git config user.name "typescript-bot"
23-
- run: git config user.email "bot@typescriptlang.org"
24-
25-
# Replace remotes with auth'd versions, then pull the .wiki version (the one people can't PR to)
26-
# then merge in any changes from here and push
27-
-
28-
run: |
29-
git remote remove origin
30-
git remote add origin https://$GITHUB_TOKEN@github.com/microsoft/TypeScript-wiki.git
31-
git remote add upstream https://$GITHUB_TOKEN@github.com/microsoft/TypeScript.wiki.git
32-
git fetch origin
33-
git fetch upstream
34-
git merge upstream/master --no-edit
35-
git push origin HEAD:master
36-
git push upstream HEAD:master
37-
env:
38-
GITHUB_TOKEN: ${{ secrets.TS_BOT_TOKEN }}
39-
15+
- name: Get repo name
16+
run: R=${GITHUB_REPOSITORY%?wiki}; echo "BASENAME=${R##*/}" >> $GITHUB_ENV
17+
- name: Checkout ${{ env.BASENAME }}-wiki
18+
uses: actions/checkout@v2
19+
with:
20+
repository: "${{ GITHUB.repository_owner }}/${{ env.BASENAME }}-wiki"
21+
token: ${{ secrets.TS_BOT_TOKEN }}
22+
fetch-depth: 0
23+
- name: Run sync
24+
run: ./.github/workflows/sync
25+
env:
26+
PUSHER: typescript-bot <bot@typescriptlang.org>
27+
AUTH: ${{ secrets.TS_BOT_TOKEN }}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## The TypeScript wiki
22

3-
This repo is the source of truth for the GitHub wiki, PRs to this repo are automatically merged into the
4-
auto-generated GitHub [repo for the wiki](https://github.com/microsoft/TypeScript/wiki). This is done
5-
in a GitHub Action in [`.github/workflows/sync.yml`](.github/workflows/sync.yml).
3+
This repo is a mirror of [the TypeScript wiki](https://github.com/Microsoft/TypeScript/wiki).
4+
Changes on either the wiki or this repo are immediately mirrored to the other side.
5+
This is done in a GitHub Action [here](.github/workflows/sync.yml), and [another](https://github.com/microsoft/TypeScript/blob/master/.github/workflows/ci.yml) in the TS repo.
66

77
The wiki root is [Home.md](./Home.md).
88

0 commit comments

Comments
 (0)