2018-07-27 04:05:18 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
: "${SOURCECRED_REMOTE:=git@github.com:sourcecred/sourcecred.git}"
|
|
|
|
: "${SOURCECRED_REF:=origin/master}"
|
|
|
|
|
|
|
|
: "${DEPLOY_REMOTE:=git@github.com:sourcecred/sourcecred.github.io.git}"
|
|
|
|
: "${DEPLOY_BRANCH:=master}"
|
2018-07-28 04:22:39 +00:00
|
|
|
: "${DEPLOY_CNAME_URL:=sourcecred.io}"
|
2018-07-27 04:05:18 +00:00
|
|
|
|
|
|
|
export GIT_CONFIG_NOSYSTEM=1
|
|
|
|
export GIT_ATTR_NOSYSTEM=1
|
|
|
|
|
|
|
|
main() {
|
|
|
|
parse_args "$@"
|
|
|
|
|
|
|
|
toplevel="$(git -C "$(dirname "$0")" rev-parse --show-toplevel)"
|
|
|
|
cd "${toplevel}"
|
|
|
|
|
|
|
|
sourcecred_repo=
|
deploy.sh: depend on build_static_site.sh (#611)
Summary:
This is a minimal patch to make the deploy script depend on the
separate, well-tested build script introduced in #592. The patch
suggests a number of improvements that can be made to the deploy script
itself, but I’m deferring those as they’re not on the critical path.
These are tracked at #610.
Test Plan:
Apply the below patch. Then run `./scripts/deploy.sh -n`, and verify
that the served output is correct, including the CNAME file. Verify that
when the `DEPLOY_CNAME_URL` default value is removed, the resulting
output does _not_ have a CNAME file.
Patch, for ease of building:
```diff
diff --git a/scripts/deploy.sh b/scripts/deploy.sh
index cddcece..8925e5b 100755
--- a/scripts/deploy.sh
+++ b/scripts/deploy.sh
@@ -23,7 +23,7 @@ main() {
preview_dir=
trap cleanup EXIT
- ensure_clean_working_tree
+ #ensure_clean_working_tree
build_and_deploy
}
@@ -76,8 +76,7 @@ build_and_deploy() {
"${sourcecred_repo}/scripts/build_static_site.sh" \
--target "${static_site}" \
${DEPLOY_CNAME_URL:+--cname "${DEPLOY_CNAME_URL}"} \
- --repo ipfs/js-ipfs \
- --repo sourcecred/sourcecred \
+ --repo sourcecred/example-github \
;
sourcecred_site="$(mktemp -d --suffix ".sourcecred-site")"
```
wchargin-branch: deploy-via-build
2018-08-07 02:00:35 +00:00
|
|
|
static_site=
|
2018-07-27 04:05:18 +00:00
|
|
|
sourcecred_site=
|
|
|
|
preview_dir=
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
ensure_clean_working_tree
|
|
|
|
build_and_deploy
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_args() {
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
-n|--dry-run)
|
|
|
|
printf 'Setting DRY_RUN=1.\n'
|
|
|
|
DRY_RUN=1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf >&2 'unknown argument: %s\n' "$1"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Adapted from:
|
|
|
|
# https://github.com/git/git/blob/8d530c4d64ffcc853889f7b385f554d53db375ed/git-sh-setup.sh#L207-L222
|
|
|
|
ensure_clean_working_tree() {
|
|
|
|
err=0
|
|
|
|
if ! git diff-files --quiet --ignore-submodules; then
|
|
|
|
printf >&2 'Cannot deploy: You have unstaged changes.\n'
|
|
|
|
err=1
|
|
|
|
fi
|
|
|
|
if ! git diff-index --cached --quiet --ignore-submodules HEAD -- ; then
|
|
|
|
if [ "${err}" -eq 0 ]; then
|
|
|
|
printf >&2 'Cannot deploy: Your index contains uncommitted changes.\n'
|
|
|
|
else
|
|
|
|
printf >&2 'Additionally, your index contains uncommitted changes.\n'
|
|
|
|
fi
|
|
|
|
err=1
|
|
|
|
fi
|
|
|
|
if [ "${err}" -ne 0 ]; then
|
|
|
|
exit "${err}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
build_and_deploy() {
|
|
|
|
sourcecred_repo="$(mktemp -d --suffix ".sourcecred-repo")"
|
|
|
|
git clone "${SOURCECRED_REMOTE}" "${sourcecred_repo}"
|
|
|
|
sourcecred_hash="$(
|
|
|
|
git -C "${sourcecred_repo}" rev-parse --verify "${SOURCECRED_REF}" --
|
|
|
|
)"
|
|
|
|
git -C "${sourcecred_repo}" checkout --detach "${sourcecred_hash}"
|
deploy.sh: depend on build_static_site.sh (#611)
Summary:
This is a minimal patch to make the deploy script depend on the
separate, well-tested build script introduced in #592. The patch
suggests a number of improvements that can be made to the deploy script
itself, but I’m deferring those as they’re not on the critical path.
These are tracked at #610.
Test Plan:
Apply the below patch. Then run `./scripts/deploy.sh -n`, and verify
that the served output is correct, including the CNAME file. Verify that
when the `DEPLOY_CNAME_URL` default value is removed, the resulting
output does _not_ have a CNAME file.
Patch, for ease of building:
```diff
diff --git a/scripts/deploy.sh b/scripts/deploy.sh
index cddcece..8925e5b 100755
--- a/scripts/deploy.sh
+++ b/scripts/deploy.sh
@@ -23,7 +23,7 @@ main() {
preview_dir=
trap cleanup EXIT
- ensure_clean_working_tree
+ #ensure_clean_working_tree
build_and_deploy
}
@@ -76,8 +76,7 @@ build_and_deploy() {
"${sourcecred_repo}/scripts/build_static_site.sh" \
--target "${static_site}" \
${DEPLOY_CNAME_URL:+--cname "${DEPLOY_CNAME_URL}"} \
- --repo ipfs/js-ipfs \
- --repo sourcecred/sourcecred \
+ --repo sourcecred/example-github \
;
sourcecred_site="$(mktemp -d --suffix ".sourcecred-site")"
```
wchargin-branch: deploy-via-build
2018-08-07 02:00:35 +00:00
|
|
|
|
|
|
|
static_site="$(mktemp -d --suffix ".static-site")"
|
|
|
|
"${sourcecred_repo}/scripts/build_static_site.sh" \
|
|
|
|
--target "${static_site}" \
|
|
|
|
${DEPLOY_CNAME_URL:+--cname "${DEPLOY_CNAME_URL}"} \
|
2019-08-07 18:07:31 +00:00
|
|
|
--project @sourcecred \
|
|
|
|
--project @filecoin-project \
|
|
|
|
--project @ipld \
|
|
|
|
--project @libp2p \
|
deploy.sh: depend on build_static_site.sh (#611)
Summary:
This is a minimal patch to make the deploy script depend on the
separate, well-tested build script introduced in #592. The patch
suggests a number of improvements that can be made to the deploy script
itself, but I’m deferring those as they’re not on the critical path.
These are tracked at #610.
Test Plan:
Apply the below patch. Then run `./scripts/deploy.sh -n`, and verify
that the served output is correct, including the CNAME file. Verify that
when the `DEPLOY_CNAME_URL` default value is removed, the resulting
output does _not_ have a CNAME file.
Patch, for ease of building:
```diff
diff --git a/scripts/deploy.sh b/scripts/deploy.sh
index cddcece..8925e5b 100755
--- a/scripts/deploy.sh
+++ b/scripts/deploy.sh
@@ -23,7 +23,7 @@ main() {
preview_dir=
trap cleanup EXIT
- ensure_clean_working_tree
+ #ensure_clean_working_tree
build_and_deploy
}
@@ -76,8 +76,7 @@ build_and_deploy() {
"${sourcecred_repo}/scripts/build_static_site.sh" \
--target "${static_site}" \
${DEPLOY_CNAME_URL:+--cname "${DEPLOY_CNAME_URL}"} \
- --repo ipfs/js-ipfs \
- --repo sourcecred/sourcecred \
+ --repo sourcecred/example-github \
;
sourcecred_site="$(mktemp -d --suffix ".sourcecred-site")"
```
wchargin-branch: deploy-via-build
2018-08-07 02:00:35 +00:00
|
|
|
;
|
2018-07-27 04:05:18 +00:00
|
|
|
|
|
|
|
sourcecred_site="$(mktemp -d --suffix ".sourcecred-site")"
|
|
|
|
git clone "${DEPLOY_REMOTE}" "${sourcecred_site}"
|
|
|
|
|
|
|
|
if ! base_commit="$(
|
|
|
|
git -C "${sourcecred_site}" rev-parse --verify \
|
|
|
|
"refs/remotes/origin/${DEPLOY_BRANCH}" --
|
|
|
|
)"; then
|
|
|
|
printf >&2 'No deploy branch %s.\n' "${DEPLOY_BRANCH}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
git -C "${sourcecred_site}" checkout --detach "${base_commit}"
|
|
|
|
rm "${sourcecred_site}/.git/index"
|
|
|
|
git -C "${sourcecred_site}" clean -qfdx
|
deploy.sh: depend on build_static_site.sh (#611)
Summary:
This is a minimal patch to make the deploy script depend on the
separate, well-tested build script introduced in #592. The patch
suggests a number of improvements that can be made to the deploy script
itself, but I’m deferring those as they’re not on the critical path.
These are tracked at #610.
Test Plan:
Apply the below patch. Then run `./scripts/deploy.sh -n`, and verify
that the served output is correct, including the CNAME file. Verify that
when the `DEPLOY_CNAME_URL` default value is removed, the resulting
output does _not_ have a CNAME file.
Patch, for ease of building:
```diff
diff --git a/scripts/deploy.sh b/scripts/deploy.sh
index cddcece..8925e5b 100755
--- a/scripts/deploy.sh
+++ b/scripts/deploy.sh
@@ -23,7 +23,7 @@ main() {
preview_dir=
trap cleanup EXIT
- ensure_clean_working_tree
+ #ensure_clean_working_tree
build_and_deploy
}
@@ -76,8 +76,7 @@ build_and_deploy() {
"${sourcecred_repo}/scripts/build_static_site.sh" \
--target "${static_site}" \
${DEPLOY_CNAME_URL:+--cname "${DEPLOY_CNAME_URL}"} \
- --repo ipfs/js-ipfs \
- --repo sourcecred/sourcecred \
+ --repo sourcecred/example-github \
;
sourcecred_site="$(mktemp -d --suffix ".sourcecred-site")"
```
wchargin-branch: deploy-via-build
2018-08-07 02:00:35 +00:00
|
|
|
# Explode the static site contents into the current directory.
|
|
|
|
find "${static_site}" -mindepth 1 -maxdepth 1 \
|
2018-07-27 04:05:18 +00:00
|
|
|
\( -name .git -prune \) -o \
|
|
|
|
-exec cp -r -t "${sourcecred_site}" -- {} +
|
|
|
|
git -C "${sourcecred_site}" add --all .
|
|
|
|
git -C "${sourcecred_site}" commit -m "deploy-v1: ${sourcecred_hash}"
|
|
|
|
deploy_commit="$(git -C "${sourcecred_site}" rev-parse HEAD)"
|
|
|
|
|
|
|
|
preview_dir="$(mktemp -d --suffix ".sourcecred-prvw")"
|
|
|
|
git clone -q --no-local --no-checkout "${sourcecred_site}" "${preview_dir}"
|
|
|
|
git -C "${preview_dir}" checkout -q --detach "${deploy_commit}"
|
|
|
|
|
|
|
|
printf '\n'
|
|
|
|
printf 'Please review the build output now---run:\n'
|
|
|
|
printf ' cd "%s" && python -m SimpleHTTPServer\n' "${preview_dir}"
|
2018-07-28 04:30:20 +00:00
|
|
|
line=
|
|
|
|
while [ "${line}" != yes ] && [ "${line}" != no ]; do
|
|
|
|
printf 'Do you want to deploy? yes/no> '
|
|
|
|
read -r line
|
|
|
|
done
|
2018-07-27 04:05:18 +00:00
|
|
|
if [ "${line}" = yes ]; then
|
|
|
|
(
|
|
|
|
set -x;
|
|
|
|
git -C "${sourcecred_site}" push ${DRY_RUN:+--dry-run} \
|
|
|
|
origin \
|
|
|
|
"${deploy_commit}:${DEPLOY_BRANCH}" \
|
|
|
|
;
|
|
|
|
)
|
|
|
|
else
|
|
|
|
printf 'Aborting.\n'
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf 'Done.\n'
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
if [ -d "${sourcecred_repo}" ]; then
|
|
|
|
rm -rf "${sourcecred_repo}"
|
|
|
|
fi
|
deploy.sh: depend on build_static_site.sh (#611)
Summary:
This is a minimal patch to make the deploy script depend on the
separate, well-tested build script introduced in #592. The patch
suggests a number of improvements that can be made to the deploy script
itself, but I’m deferring those as they’re not on the critical path.
These are tracked at #610.
Test Plan:
Apply the below patch. Then run `./scripts/deploy.sh -n`, and verify
that the served output is correct, including the CNAME file. Verify that
when the `DEPLOY_CNAME_URL` default value is removed, the resulting
output does _not_ have a CNAME file.
Patch, for ease of building:
```diff
diff --git a/scripts/deploy.sh b/scripts/deploy.sh
index cddcece..8925e5b 100755
--- a/scripts/deploy.sh
+++ b/scripts/deploy.sh
@@ -23,7 +23,7 @@ main() {
preview_dir=
trap cleanup EXIT
- ensure_clean_working_tree
+ #ensure_clean_working_tree
build_and_deploy
}
@@ -76,8 +76,7 @@ build_and_deploy() {
"${sourcecred_repo}/scripts/build_static_site.sh" \
--target "${static_site}" \
${DEPLOY_CNAME_URL:+--cname "${DEPLOY_CNAME_URL}"} \
- --repo ipfs/js-ipfs \
- --repo sourcecred/sourcecred \
+ --repo sourcecred/example-github \
;
sourcecred_site="$(mktemp -d --suffix ".sourcecred-site")"
```
wchargin-branch: deploy-via-build
2018-08-07 02:00:35 +00:00
|
|
|
if [ -d "${static_site}" ]; then
|
|
|
|
rm -rf "${static_site}"
|
|
|
|
fi
|
|
|
|
if [ -d "${sourcecred_site}" ]; then
|
|
|
|
rm -rf "${sourcecred_site}"
|
|
|
|
fi
|
2018-07-27 04:05:18 +00:00
|
|
|
if [ -d "${preview_dir}" ]; then
|
|
|
|
rm -rf "${preview_dir}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|