-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Rework website publishing workflow #8837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Usage: | ||
# BOT_TOKEN=<dotty-bot password> ./genDocs [-doc-snapshot] | ||
|
||
set -e | ||
GENDOC_EXTRA_ARGS=$@ | ||
|
||
# set extended glob, needed for rm everything but x | ||
shopt -s extglob | ||
shopt -s extglob # needed for rm everything but x | ||
echo "Working directory: $PWD" | ||
|
||
# make sure that BOT_TOKEN is set | ||
if [ -z "$BOT_TOKEN" ]; then | ||
echo "Error: BOT_TOKEN env unset, unable to push without password" 1>&2 | ||
exit 1 | ||
GENDOC_EXTRA_ARGS=$@ | ||
GIT_HEAD=$(git rev-parse HEAD) # save current head for commit message in gh-pages | ||
PREVIOUS_SNAPSHOTS_DIR="$PWD/../prev_snapshots" | ||
SCRIPT_DIR="(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)" | ||
SITE_OUT_DIR="$PWD/docs/_site" | ||
|
||
### Obtain the previous versions of the website ### | ||
if [ -d "$PREVIOUS_SNAPSHOTS_DIR" ]; then | ||
rm -rf "$PREVIOUS_SNAPSHOTS_DIR" | ||
fi | ||
|
||
echo "Working directory: $PWD" | ||
mkdir -pv "$PREVIOUS_SNAPSHOTS_DIR" | ||
git remote add doc-remote "https://github.com/lampepfl/dotty-website.git" | ||
git fetch doc-remote gh-pages | ||
git checkout gh-pages | ||
(cp -vr 0.*/ "$PREVIOUS_SNAPSHOTS_DIR"; true) # Don't fail if no `0.*` found to copy | ||
git checkout "$GIT_HEAD" | ||
|
||
### Generate the current snapshot of the website ### | ||
# this command will generate docs in $PWD/docs/_site | ||
SBT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/sbt" | ||
SBT="$SCRIPT_DIR/sbt" | ||
"$SBT" "dotty-bootstrapped/genDocs $GENDOC_EXTRA_ARGS" | ||
|
||
# make sure that the previous command actually succeeded | ||
if [ ! -d "$PWD/docs/_site" ]; then | ||
echo "Output directory did not exist: $PWD/docs/_site" 1>&2 | ||
exit 1 | ||
if [ ! -d "$SITE_OUT_DIR" ]; then | ||
echo "Output directory did not exist: $SITE_OUT_DIR" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
# save current head for commit message in gh-pages | ||
GIT_HEAD=$(git rev-parse HEAD) | ||
|
||
|
||
# set up remote and github credentials | ||
git remote add doc-remote "https://dotty-bot:$BOT_TOKEN@github.com/lampepfl/dotty-website.git" | ||
git config user.name "dotty-bot" | ||
git config user.email "dotty-bot@d-d.me" | ||
|
||
# check out correct branch | ||
git fetch doc-remote gh-pages | ||
git checkout gh-pages | ||
|
||
# save the old snapshots to the newly generated site | ||
# This command must never fail since failures short-circuit the script | ||
# The reason for failure is that no folder matches "0.*" pattern | ||
# because snapshots may not be generated yet | ||
(mv 0.*/ $PWD/docs/_site; true) | ||
|
||
# move newly generated _site dir to $PWD | ||
mv $PWD/docs/_site . | ||
|
||
# remove everything BUT _site dir | ||
rm -rf !(_site) | ||
|
||
# copy new contents to $PWD | ||
mv _site/* . | ||
|
||
# remove now empty _site dir | ||
rm -rf _site | ||
|
||
# add all contents of $PWD to commit | ||
git add -A | ||
git commit -m "Update gh-pages site for $GIT_HEAD" || echo "nothing new to commit" | ||
|
||
# push to doc-remote | ||
git push doc-remote || echo "couldn't push, since nothing was added" | ||
### Move previous versions' snapshots to _site ### | ||
mv -v "$PREVIOUS_SNAPSHOTS_DIR"/* "$SITE_OUT_DIR" | ||
rm -rf "$PREVIOUS_SNAPSHOTS_DIR" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.