|
| 1 | +name:Delete docs built with PR |
| 2 | + |
| 3 | +on: |
| 4 | +pull_request: |
| 5 | +branches:[ "3.8" ] |
| 6 | +types: |
| 7 | + -closed# PR closed |
| 8 | + |
| 9 | +jobs: |
| 10 | +delete_pr_docs |
| 11 | +runs-on:ubuntu-latest |
| 12 | + |
| 13 | +steps: |
| 14 | + -name:Prepare environment variables |
| 15 | +run:| |
| 16 | + ref=${GITHUB_REF#refs/pull/} |
| 17 | + pr_num=${ref%/merge} |
| 18 | +
|
| 19 | + echo "::set-env name=PR_NUM::${pr_num}" |
| 20 | + echo "::set-env name=PR_BUILD_ID::${GITHUB_BASE_REF}/${pr_num}" |
| 21 | + echo "::set-env name=DOCS_BASE_DIR::build/html" |
| 22 | + echo "::set-env name=DOCS_OUTPUT_DIR::build/html/${GITHUB_BASE_REF}/${pr_num}" |
| 23 | +
|
| 24 | + -name:Checkout GitHub Pages |
| 25 | +uses:actions/checkout@v2 |
| 26 | +with: |
| 27 | +ref:gh-pages |
| 28 | +path:build/html |
| 29 | + |
| 30 | + -name:Delete docs |
| 31 | +run:| |
| 32 | + cd ${GITHUB_WORKSPACE}/${DOCS_BASE_DIR} |
| 33 | + git config --local user.name "Autobuild bot on GitHub Actions" |
| 34 | + git config --local user.email "githubaction-build-bot@example.com" |
| 35 | + git add . |
| 36 | + if [ $(git status -s | wc -l) -eq 0 ]; then echo "nothing to commit"; exit 0; fi |
| 37 | + git commit -m "Delete docs, branch: ${GITHUB_BASE_REF} pr_num: ${PR_NUM}" |
| 38 | + git push --quiet "https://${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" gh-pages:gh-pages |
| 39 | +
|