forked from graphql/graphql-spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.sh
executable file
·126 lines (112 loc) · 3.04 KB
/
publish.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash -e
# This script publishes the GraphQL specification document to the web.
# Build the specification document into publishable form
echo "Building spec"
npm run build > /dev/null 2>&1
# Determine if this is a tagged release
GITTAG=$(git tag --points-at HEAD)
# Check out gh-pages locally.
echo "Cloning gh-pages"
rm -rf gh-pages
git clone -b gh-pages "https://${GH_TOKEN}@github.com/facebook/graphql.git" gh-pages > /dev/null 2>&1
# Replace /draft with this build.
echo "Publishing to: /draft"
rm -rf gh-pages/draft
cp -r out/ gh-pages/draft
# If this is a tagged commit, publish to a permalink and index.
if [ -n "$GITTAG" ]; then
echo "Publishing to: /$GITTAG"
cp -r out/ "gh-pages/$GITTAG"
fi
# Create the index file
echo "Rebuilding: / (index)"
HTML="<html>
<head>
<title>GraphQL Specification Versions</title>
<style>
body {
color: #333333;
font: 13pt/18pt Cambria, 'Palatino Linotype', Palatino, 'Liberation Serif', serif;
margin: 6rem auto 3rem;
max-width: 780px;
}
@media (min-width: 1240px) {
body {
padding-right: 300px;
}
}
a {
color: #3B5998;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
h1 {
font-size: 1.5em;
margin: 8rem 0 2em;
}
td {
padding-bottom: 5px;
}
td + td {
padding-left: 2ch;
}
</style>
</head>
<body>
<h1>GraphQL</h1>
<table>"
# Include latest draft
GITDATE=$(git show -s --format=%cd --date=format:"%a, %b %-d, %Y" HEAD)
HTML="$HTML
<tr>
<td><em>Prerelease</em></td>
<td><a href=\"./draft\" keep-hash>Working Draft</a></td>
<td>$GITDATE</td>
<td></td>
</tr>"
GITHUB_RELEASES="https://github.com/facebook/graphql/releases/tag"
for GITTAG in $(git tag -l --sort='-*committerdate') ; do
VERSIONYEAR=${GITTAG: -4}
TAGTITLE="${GITTAG%$VERSIONYEAR} $VERSIONYEAR"
TAGGEDCOMMIT=$(git rev-list -1 "$GITTAG")
GITDATE=$(git show -s --format=%cd --date=format:"%a, %b %-d, %Y" $TAGGEDCOMMIT)
HTML="$HTML
<tr>"
[ -z $HAS_LATEST_RELEASE ] && HTML="$HTML
<td><em>Latest Release</em></td>" || HTML="$HTML
<td></td>"
HAS_LATEST_RELEASE=1
HTML="$HTML
<td><a href=\"./$GITTAG\" keep-hash>$TAGTITLE</a></td>
<td>$GITDATE</td>
<td><a href=\"$GITHUB_RELEASES/$GITTAG\">Release Notes</a></td>
</tr>"
done
HTML="$HTML
</table>
<script>
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (links[i].hasAttribute('keep-hash')) {
links[i].href += location.hash;
links[i].removeAttribute('keep-hash');
}
}
</script>
</body>
</html>"
echo $HTML > "gh-pages/index.html"
echo "Pushing update"
cd gh-pages
git config user.name "Travis CI"
git config user.email "[email protected]"
git add -A .
if git diff --staged --quiet; then
echo "Nothing to publish"
else
git commit -a -m "Deploy to GitHub Pages"
git push > /dev/null 2>&1
echo "Pushed"
fi