forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 5
/
gitpublish.sh
52 lines (42 loc) · 1.16 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
#!/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"
#
# Additionaly it use use to push Deno build to `deno` branch.
BRANCH=$1
DIST_DIR=$2
# Exit immediately if any subcommand terminated
set -e
if [ ! -d $DIST_DIR ]; then
echo "Directory '${DIST_DIR}' does not exist!"
exit 1;
fi;
if [ -z "${GH_TOKEN}" ]; then
echo 'Must provide GH_TOKEN as environment variable!'
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
HEADREV=`git rev-parse HEAD`
echo $HEADREV
# 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 $HEADREV to '$BRANCH' branch"
git push > /dev/null 2>&1
echo "Pushed"
fi