Skip to content

Commit ffb1fcc

Browse files
authored
Move website deploy from Travis to GH Actions (#887)
* Moves all GH publish steps out of the publish script, and updates the built directory structure to better mirror the final output. * Since this script is now safe to run locally, rename to `build.sh` and update the npm script to use this directly. * Add actions-gh-pages to the github actions workflow, renaming to CI. * Removes references to Travis CI. See also: https://twitter.com/peter_szilagyi/status/1437646118700175360
1 parent dbfa258 commit ffb1fcc

File tree

7 files changed

+150
-234
lines changed

7 files changed

+150
-234
lines changed

.github/workflows/ci.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-node@v1
15+
with:
16+
node-version: '16.x'
17+
- run: npm ci
18+
- run: npm test
19+
publish:
20+
if: github.ref == 'refs/heads/main'
21+
needs: test
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
with:
26+
fetch-depth: 0
27+
- uses: actions/setup-node@v1
28+
with:
29+
node-version: '16.x'
30+
- run: npm ci
31+
- run: npm run build
32+
- uses: peaceiris/actions-gh-pages@v3
33+
with:
34+
github_token: ${{ secrets.GITHUB_TOKEN }}
35+
keep_files: true
36+
cname: spec.graphql.org
37+
user_name: 'github-actions[bot]'
38+
user_email: 'github-actions[bot]@users.noreply.github.com'

.github/workflows/test.yml

-12
This file was deleted.

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
.DS_Store
55
npm-debug.log
66
/build
7-
/out
7+
/public
88
/gh-pages
99
/node_modules

.travis.yml

-25
This file was deleted.

publish.sh renamed to build.sh

+9-36
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,16 @@
44
# Determine if this is a tagged release
55
GITTAG=$(git tag --points-at HEAD)
66

7-
# Build the specification document into publishable form
8-
echo "Building spec"
9-
mkdir -p out
10-
if [ -n "$GITTAG" ]; then
11-
spec-md --githubSource "https://github.com/graphql/graphql-spec/blame/$GITTAG/" spec/GraphQL.md > out/index.html
12-
else
13-
spec-md --githubSource "https://github.com/graphql/graphql-spec/blame/main/" spec/GraphQL.md > out/index.html
14-
fi
15-
npm run build > /dev/null 2>&1
16-
17-
# Check out gh-pages locally.
18-
echo "Cloning gh-pages"
19-
rm -rf gh-pages
20-
git clone -b gh-pages "https://${GH_TOKEN}@github.com/graphql/graphql-spec.git" gh-pages > /dev/null 2>&1
7+
# Build the specification draft document
8+
echo "Building spec draft"
9+
mkdir -p public/draft
10+
spec-md --githubSource "https://github.com/graphql/graphql-spec/blame/main/" spec/GraphQL.md > public/draft/index.html
2111

22-
# Replace /draft with this build.
23-
echo "Publishing to: /draft"
24-
rm -rf gh-pages/draft
25-
cp -R out/ gh-pages/draft
26-
27-
# If this is a tagged commit, publish to a permalink and index.
12+
# If this is a tagged commit, also build the release document
2813
if [ -n "$GITTAG" ]; then
29-
echo "Publishing to: /$GITTAG"
30-
cp -R out/ "gh-pages/$GITTAG"
14+
echo "Building spec release $GITTAG"
15+
mkdir -p "public/$GITTAG"
16+
spec-md --githubSource "https://github.com/graphql/graphql-spec/blame/$GITTAG/" spec/GraphQL.md > "public/$GITTAG/index.html"
3117
fi
3218

3319
# Create the index file
@@ -116,17 +102,4 @@ HTML="$HTML
116102
</body>
117103
</html>"
118104

119-
echo $HTML > "gh-pages/index.html"
120-
121-
echo "Pushing update"
122-
cd gh-pages
123-
git config user.name "Travis CI"
124-
git config user.email "[email protected]"
125-
git add -A .
126-
if git diff --staged --quiet; then
127-
echo "Nothing to publish"
128-
else
129-
git commit -a -m "Deploy to GitHub Pages"
130-
git push > /dev/null 2>&1
131-
echo "Pushed"
132-
fi
105+
echo $HTML > "public/index.html"

0 commit comments

Comments
 (0)