Skip to content

Commit

Permalink
Move website deploy from Travis to GH Actions (#887)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
leebyron authored Sep 15, 2021
1 parent dbfa258 commit ffb1fcc
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 234 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '16.x'
- run: npm ci
- run: npm test
publish:
if: github.ref == 'refs/heads/main'
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-node@v1
with:
node-version: '16.x'
- run: npm ci
- run: npm run build
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
keep_files: true
cname: spec.graphql.org
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
12 changes: 0 additions & 12 deletions .github/workflows/test.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
.DS_Store
npm-debug.log
/build
/out
/public
/gh-pages
/node_modules
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

45 changes: 9 additions & 36 deletions publish.sh → build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,16 @@
# Determine if this is a tagged release
GITTAG=$(git tag --points-at HEAD)

# Build the specification document into publishable form
echo "Building spec"
mkdir -p out
if [ -n "$GITTAG" ]; then
spec-md --githubSource "https://github.com/graphql/graphql-spec/blame/$GITTAG/" spec/GraphQL.md > out/index.html
else
spec-md --githubSource "https://github.com/graphql/graphql-spec/blame/main/" spec/GraphQL.md > out/index.html
fi
npm run build > /dev/null 2>&1

# Check out gh-pages locally.
echo "Cloning gh-pages"
rm -rf gh-pages
git clone -b gh-pages "https://${GH_TOKEN}@github.com/graphql/graphql-spec.git" gh-pages > /dev/null 2>&1
# Build the specification draft document
echo "Building spec draft"
mkdir -p public/draft
spec-md --githubSource "https://github.com/graphql/graphql-spec/blame/main/" spec/GraphQL.md > public/draft/index.html

# 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 this is a tagged commit, also build the release document
if [ -n "$GITTAG" ]; then
echo "Publishing to: /$GITTAG"
cp -R out/ "gh-pages/$GITTAG"
echo "Building spec release $GITTAG"
mkdir -p "public/$GITTAG"
spec-md --githubSource "https://github.com/graphql/graphql-spec/blame/$GITTAG/" spec/GraphQL.md > "public/$GITTAG/index.html"
fi

# Create the index file
Expand Down Expand Up @@ -116,17 +102,4 @@ HTML="$HTML
</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
echo $HTML > "public/index.html"
Loading

0 comments on commit ffb1fcc

Please sign in to comment.