Skip to content

Commit 01c61a7

Browse files
committed
Setup automatic push of gh-pages
1 parent c638e5b commit 01c61a7

File tree

4 files changed

+92
-5
lines changed

4 files changed

+92
-5
lines changed

.github/deploy.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# Automatically deploy on gh-pages
3+
4+
set -e
5+
6+
SOURCE_BRANCH="master"
7+
TARGET_BRANCH="gh-pages"
8+
9+
# Save some useful information
10+
REPO=$(git config remote.origin.url)
11+
SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
12+
SHA=$(git rev-parse --verify HEAD)
13+
14+
# Clone the existing gh-pages for this repo into out/
15+
(
16+
git clone "$REPO" out
17+
cd out
18+
git checkout $TARGET_BRANCH
19+
)
20+
21+
# Remove the current doc for master
22+
rm -rf out/master/ || exit 0
23+
24+
# Make the doc for master
25+
mkdir out/master/
26+
cp util/gh-pages/index.html out/master
27+
./util/export.py out/master/lints.json
28+
29+
# Save the doc for the current tag and point current/ to it
30+
if [ -n "$TRAVIS_TAG" ]; then
31+
cp -r out/master "out/$TRAVIS_TAG"
32+
rm -f out/current
33+
ln -s "$TRAVIS_TAG" out/current
34+
fi
35+
36+
# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
37+
if [ "$TRAVIS_PULL_REQUEST" != "false" ] || [ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
38+
echo "Generated, won't push"
39+
exit 0
40+
fi
41+
42+
# Now let's go have some fun with the cloned repo
43+
cd out
44+
git config user.name "Travis CI"
45+
git config user.email "[email protected]"
46+
47+
if [ -z "$(git diff --exit-code)" ]; then
48+
echo "No changes to the output on this push; exiting."
49+
exit 0
50+
fi
51+
52+
git add .
53+
git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
54+
55+
# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
56+
ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
57+
ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
58+
ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
59+
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
60+
openssl aes-256-cbc -K "$ENCRYPTED_KEY" -iv "$ENCRYPTED_IV" -in deploy_key.enc -out deploy_key -d
61+
chmod 600 deploy_key
62+
eval $(ssh-agent -s)
63+
ssh-add deploy_key
64+
65+
# Now that we're all set up, we can push.
66+
git push "$SSH_REPO" "$TARGET_BRANCH"

.github/deploy_key.enc

1.64 KB
Binary file not shown.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Used by Travis to be able to push:
2+
/.github/deploy_key
3+
out
4+
15
# Compiled files
26
*.o
37
*.so

util/export.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/usr/bin/env python
2+
# Build the gh-pages
23

4+
import json
35
import os
46
import re
5-
import json
7+
import sys
8+
69

710
level_re = re.compile(r'''(Forbid|Deny|Warn|Allow)''')
811
conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE)
@@ -15,10 +18,19 @@
1518
* `%s: %s`: %s (defaults to `%s`).
1619
"""
1720

21+
1822
# TODO: actual logging
19-
def warn(*args): print(args)
20-
def debug(*args): print(args)
21-
def info(*args): print(args)
23+
def warn(*args):
24+
print(*args)
25+
26+
27+
def debug(*args):
28+
print(*args)
29+
30+
31+
def info(*args):
32+
print(*args)
33+
2234

2335
def parse_path(p="clippy_lints/src"):
2436
lints = []
@@ -52,6 +64,7 @@ def parse_conf(p):
5264

5365
return c
5466

67+
5568
def parseLintDef(level, comment, name):
5669
lint = {}
5770
lint['id'] = name
@@ -80,6 +93,7 @@ def parseLintDef(level, comment, name):
8093

8194
return lint
8295

96+
8397
def parse_file(d, f):
8498
last_comment = []
8599
comment = True
@@ -134,10 +148,13 @@ def parse_file(d, f):
134148
warn("Warning: Missing Lint-Name in", f)
135149
comment = True
136150

151+
137152
def main():
138153
lints = parse_path()
139154
info("got %s lints" % len(lints))
140-
with open("util/gh-pages/lints.json", "w") as file:
155+
156+
outdir = sys.argv[1] if len(sys.argv) > 1 else "util/gh-pages/lints.json"
157+
with open(outdir, "w") as file:
141158
json.dump(lints, file, indent=2)
142159
info("wrote JSON for great justice")
143160

0 commit comments

Comments
 (0)