|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: master |
| 6 | + release: |
| 7 | + types: [created] |
| 8 | + |
| 9 | +env: |
| 10 | + TARGET_BRANCH: "gh-pages" |
| 11 | + |
| 12 | +jobs: |
| 13 | + deploy: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + |
| 19 | + - name: Checkout |
| 20 | + |
| 21 | + with: |
| 22 | + ref: ${{ env.TARGET_BRANCH }} |
| 23 | + path: 'out' |
| 24 | + - name: Deploy |
| 25 | + run: | |
| 26 | + set -ex |
| 27 | +
|
| 28 | + # Save some useful information |
| 29 | + SHA=${{ github.sha }} |
| 30 | + [email protected]:${{ github.repository }}.git |
| 31 | + TAG_NAME=${{ github.event.release.GITHUB_REF }} |
| 32 | +
|
| 33 | + echo "Removing the current docs for master" |
| 34 | + rm -rf out/master/ || exit 0 |
| 35 | +
|
| 36 | + echo "Making the docs for master" |
| 37 | + mkdir out/master/ |
| 38 | + cp util/gh-pages/index.html out/master |
| 39 | + python ./util/export.py out/master/lints.json |
| 40 | +
|
| 41 | + if [[ -n $TAG_NAME ]]; then |
| 42 | + echo "Save the doc for the current tag ($TAG_NAME) and point current/ to it" |
| 43 | + cp -r out/master "out/$TAG_NAME" |
| 44 | + rm -f out/current |
| 45 | + ln -s "$TAG_NAME" out/current |
| 46 | + fi |
| 47 | +
|
| 48 | + # Generate version index that is shown as root index page |
| 49 | + cp util/gh-pages/versions.html out/index.html |
| 50 | +
|
| 51 | + cd out |
| 52 | + cat <<-EOF | python - > versions.json |
| 53 | + import os, json |
| 54 | + print json.dumps([ |
| 55 | + dir for dir in os.listdir(".") if not dir.startswith(".") and os.path.isdir(dir) |
| 56 | + ]) |
| 57 | + EOF |
| 58 | +
|
| 59 | + # Now let's go have some fun with the cloned repo |
| 60 | + git config user.name "GHA CI" |
| 61 | + git config user.email "[email protected]" |
| 62 | +
|
| 63 | + if git diff --exit-code --quiet; then |
| 64 | + echo "No changes to the output on this push; exiting." |
| 65 | + exit 0 |
| 66 | + fi |
| 67 | +
|
| 68 | + git add . |
| 69 | + git commit -m "Automatic deploy to GitHub Pages: ${SHA}" |
| 70 | +
|
| 71 | + echo ${{ secrets.DEPLOY_KEY }} > .github/deploy_key |
| 72 | + eval "$(ssh-agent -s)" |
| 73 | + ssh-add .github/deploy_key |
| 74 | +
|
| 75 | + git push "$SSH_REPO" "$TARGET_BRANCH" |
0 commit comments