-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathghactions-deploy-gh-pages-pure-token.sh
executable file
·67 lines (52 loc) · 1.73 KB
/
ghactions-deploy-gh-pages-pure-token.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# shellcheck disable=SC2016
# TODO: replace this script when https://github.com/travis-ci/dpl/issues/694 is fixed
# Taken from https://raw.githubusercontent.com/w3c/permissions/master/deploy.sh
set -e # Exit with nonzero exit code if anything fails
errx() {
# readonly __progname=$(basename ${BASH_SOURCE})
echo -e "[ghactions-deploy-gh-pages.sh] $*" >&2
exit 1
}
TARGET_BRANCH="gh-pages"
main() {
[ -z "$GITHUB_TOKEN" ] && \
errx "No GITHUB_TOKEN provided; it must be set."
# Save some useful information
REPO="https://${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
SHA=$(git rev-parse --verify HEAD)
DEST_DIR=out
# Clone the existing $TARGET_BRANCH for this repo into $DEST_DIR/
# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deploy)
mkdir -p "$DEST_DIR"
pushd "$DEST_DIR"
git init .
git checkout -b "$TARGET_BRANCH" || errx "Unable to checkout git."
# Adding contents within published/ to $DEST_DIR.
cp -a ../published/* ./ || exit 0
# Now let's go have some fun with the cloned repo
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
# Commit the "changes", i.e. the new version.
# The delta will show diffs between new and old versions.
git add .
git status
git commit -m "Deploy to GitHub Pages: ${SHA}"
printf "\n\e[37m"
echo "git ls-files:"
git ls-files
printf "\e[0m\n"
printf "\n\e[37m"
echo "ls -a:"
ls -a
printf "\e[0m\n"
# echo ".gitignore:"
# cat .gitignore || true
# echo
# Now that we're all set up, we can push.
echo "git push $REPO $TARGET_BRANCH -f"
git push "$REPO" "$TARGET_BRANCH" -f || errx "Unable to push to git."
popd
}
main "$@"
exit 0