|
| 1 | +name: ChipFlow Libraray Github Pages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, reopened, closed] |
| 9 | + branches: |
| 10 | + - main |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + pages: write |
| 14 | + id-token: write |
| 15 | + issues: write |
| 16 | + pull-requests: write |
| 17 | + |
| 18 | +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
| 19 | +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
| 20 | +concurrency: |
| 21 | + group: "pages" |
| 22 | + cancel-in-progress: false |
| 23 | + |
| 24 | +jobs: |
| 25 | + build_and_deploy_docs: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + name: Build and Deploy Docs |
| 28 | + env: |
| 29 | + PR_PATH: pull/${{github.event.number}} |
| 30 | + steps: |
| 31 | + - name: Delete old doc PR comment |
| 32 | + if: ${{ github.event_name == 'pull_request' }} |
| 33 | + |
| 34 | + with: |
| 35 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + repository: ${{ github.repository }} |
| 37 | + number: ${{ github.event.number }} |
| 38 | + id: deploy-preview |
| 39 | + delete: true |
| 40 | + |
| 41 | + - name: Comment on PR |
| 42 | + if: ${{ github.event_name == 'pull_request' }} |
| 43 | + |
| 44 | + with: |
| 45 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + repository: ${{ github.repository }} |
| 47 | + number: ${{ github.event.number }} |
| 48 | + id: deploy-preview |
| 49 | + message: "Starting deployment of preview ⏳..." |
| 50 | + recreate: true |
| 51 | + |
| 52 | + - name: Get Site URL |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + run: | |
| 56 | + url=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq '.html_url' | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/') |
| 57 | + echo "DOMAIN=$url" >> $GITHUB_ENV |
| 58 | +
|
| 59 | + - name: Set production base URL |
| 60 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 61 | + run: echo "BASE_URL=https://${{ env.DOMAIN }}/" >> $GITHUB_ENV |
| 62 | + |
| 63 | + - name: Set base URL for preview if PR |
| 64 | + if: ${{ github.event_name == 'pull_request' }} |
| 65 | + run: echo "BASE_URL=https://${{ env.DOMAIN }}/${{ env.PR_PATH}}/" >> $GITHUB_ENV |
| 66 | + |
| 67 | + - uses: actions/checkout@v2 |
| 68 | + with: |
| 69 | + submodules: true |
| 70 | + |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + - name: Setup PDM |
| 73 | + uses: pdm-project/setup-pdm@v4 |
| 74 | + with: |
| 75 | + python-version: 3.12 |
| 76 | + cache: true |
| 77 | + |
| 78 | + - name: Install dependencies |
| 79 | + run: pdm install |
| 80 | + |
| 81 | + - name: Build docs |
| 82 | + run: pdm docs |
| 83 | + |
| 84 | + - name: Setup Pages |
| 85 | + uses: actions/configure-pages@v5 |
| 86 | + |
| 87 | + - name: Upload artifacts |
| 88 | + uses: actions/upload-artifact@v4 |
| 89 | + with: |
| 90 | + name: html-docs |
| 91 | + path: docs/_build |
| 92 | + |
| 93 | + - name: Deploy if this is the `main` branch |
| 94 | + uses: peaceiris/actions-gh-pages@v3 |
| 95 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 96 | + with: |
| 97 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + publish_dir: site |
| 99 | + cname: ${{ env.DOMAIN }} |
| 100 | + |
| 101 | + - name: Deploy to PR preview |
| 102 | + if: ${{ github.event_name == 'pull_request' }} |
| 103 | + uses: peaceiris/actions-gh-pages@v3 |
| 104 | + with: |
| 105 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + publish_dir: site |
| 107 | + destination_dir: ${{ env.PR_PATH }} |
| 108 | + |
| 109 | + - name: Update comment |
| 110 | + if: ${{ github.event_name == 'pull_request' }} |
| 111 | + |
| 112 | + with: |
| 113 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 114 | + repository: ${{ github.repository }} |
| 115 | + number: ${{ github.event.number }} |
| 116 | + id: deploy-preview |
| 117 | + message: "A preview of ${{ github.event.after }} is uploaded and can be seen here:\n\n ✨ ${{ env.BASE_URL }} ✨\n\nChanges may take a few minutes to propagate. Since this is a preview of production, content with `draft: true` will not be rendered. The source is here: https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/" |
| 118 | + recreate: true |
0 commit comments