forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitpublish.sh
executable file
·62 lines (50 loc) · 1.34 KB
/
gitpublish.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
#!/bin/bash
# This script maintains a git branch which mirrors master but in a form that
# what will eventually be deployed to npm, allowing npm dependencies to use:
#
# "graphql": "git://github.com/graphql/graphql-js.git#npm"
#
# Additionally it use use to push Deno build to `deno` branch.
BRANCH=$1
DIST_DIR=$2
# Exit immediately if any subcommand terminated
set -e
if [ -z "${BRANCH}" ]; then
echo 'Must provide BRANCH as first argument!'
exit 1;
fi;
if [ -z "${DIST_DIR}" ]; then
echo 'Must provide DIST_DIR as second argument!'
exit 1;
fi;
if [ -z "${GH_TOKEN}" ]; then
echo 'Must provide GH_TOKEN as environment variable!'
exit 1;
fi;
if [ ! -d $DIST_DIR ]; then
echo "Directory '${DIST_DIR}' does not exist!"
exit 1;
fi;
# Create empty directory
rm -rf $BRANCH
git clone -b $BRANCH -- "https://${GH_TOKEN}@github.com/graphql/graphql-js.git" $BRANCH
# Remove existing files first
rm -rf $BRANCH/**/*
rm -rf $BRANCH/*
# Copy over necessary files
cp -r $DIST_DIR/* $BRANCH/
# Reference current commit
HEAD_REV=`git rev-parse HEAD`
echo $HEAD_REV
# Deploy
cd $BRANCH
git config user.name "GitHub Action Script"
git config user.email "please@open.issue"
git add -A .
if git diff --staged --quiet; then
echo "Nothing to publish"
else
git commit -a -m "Deploy $HEAD_REV to '$BRANCH' branch"
git push > /dev/null 2>&1
echo "Pushed"
fi