diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad5642d8..78ec992e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -249,27 +249,18 @@ jobs: - name: Build docs run: target/debug/xtask doc --deny-warnings - - - name: Deploy PR preview - id: deploy_preview + + - name: Compress docs if: github.event_name == 'pull_request' - continue-on-error: true - uses: dswistowski/surge-sh-action@v1.0.1 - with: - domain: pr-${{ github.event.number }}--ruma-docs.surge.sh - project: target/doc - login: ${{ secrets.SURGE_LOGIN }} - token: ${{ secrets.SURGE_TOKEN }} + run: | + tar --zstd -cf docs.tar.zstd -C target doc - - name: Comment deploy PR preview URL - if: steps.deploy_preview.outcome == 'success' - uses: Beakyn/gha-comment-pull-request@v1.0.2 - env: - GITHUB_TOKEN: ${{ github.token }} + - name: Upload docs as artifact + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@v3 with: - description-message: | - ---- - Preview: https://pr-${{ github.event.number }}--ruma-docs.surge.sh + name: docs + path: docs.tar.zstd - name: Deploy to docs repo if: github.event_name == 'push' && github.ref == 'refs/heads/main' diff --git a/.github/workflows/docs-preview.yml b/.github/workflows/docs-preview.yml new file mode 100644 index 00000000..c3b3a20f --- /dev/null +++ b/.github/workflows/docs-preview.yml @@ -0,0 +1,62 @@ +name: Docs Preview + +env: + CARGO_TERM_COLOR: always + +on: + workflow_run: + workflows: [CI] + types: + - completed + +jobs: + deploy: + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.pull_requests[0] != null + steps: + - name: Download artifact + uses: actions/github-script@v6 + with: + script: | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == "docs"; + })[0]; + let download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + let fs = require('fs'); + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/docs.zip`, Buffer.from(download.data)); + + - name: Unzip artifact + run: | + unzip docs.zip + tar -xf docs.tar.zstd + + - name: Deploy PR preview + continue-on-error: true + id: deploy_preview + uses: dswistowski/surge-sh-action@v1.0.1 + with: + domain: pr-${{ github.event.workflow_run.pull_requests[0].number }}--ruma-docs.surge.sh + project: doc + login: ${{ secrets.SURGE_LOGIN }} + token: ${{ secrets.SURGE_TOKEN }} + + - name: Comment PR preview URL + if: steps.deploy_preview.outcome == 'success' + uses: Beakyn/gha-comment-pull-request@v1.0.2 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + pull-request-number: ${{ github.event.workflow_run.pull_requests[0].number }} + description-message: | + ---- + Preview: https://pr-${{ github.event.workflow_run.pull_requests[0].number }}--ruma-docs.surge.sh diff --git a/.github/workflows/docs-remove-preview.yml b/.github/workflows/docs-remove-preview.yml new file mode 100644 index 00000000..30c35254 --- /dev/null +++ b/.github/workflows/docs-remove-preview.yml @@ -0,0 +1,57 @@ +name: Docs Remove Preview + +env: + CARGO_TERM_COLOR: always + +on: + workflow_run: + workflows: [PR Closed] + types: + - completed + +jobs: + teardown: + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' + steps: + - name: Get PR number + uses: actions/github-script@v6 + id: get_pr + continue-on-error: true + with: + script: | + let login = context.payload.workflow_run.head_repository.owner.login; + let branch = context.payload.workflow_run.head_branch; + let head = `${login}:${branch}`; + let prs = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: "closed", + head, + }); + if (prs.data.length > 0) { + core.setOutput("prnumber", prs.data[0].number); + } else { + core.setFailed("Could not find PR"); + } + + - name: Teardown preview + if: steps.get_pr.outcome == 'success' + continue-on-error: true + uses: adrianjost/actions-surge.sh-teardown@v1.0.3 + with: + regex: pr-${{ steps.get_pr.outputs.prnumber }}--ruma-docs.surge.sh + env: + SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }} + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + + - name: Remove PR preview URL + if: steps.get_pr.outcome == 'success' + uses: Beakyn/gha-comment-pull-request@v1.0.2 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + pull-request-number: ${{ steps.get_pr.outputs.prnumber }} + description-message: | + ---- + Preview Removed diff --git a/.github/workflows/pr-closed.yml b/.github/workflows/pr-closed.yml index fcb75098..c1973e4a 100644 --- a/.github/workflows/pr-closed.yml +++ b/.github/workflows/pr-closed.yml @@ -7,20 +7,7 @@ on: jobs: docs: - name: Remove Docs Preview + name: Trigger runs-on: ubuntu-latest steps: - - name: Teardown - uses: adrianjost/actions-surge.sh-teardown@v1.0.3 - with: - regex: pr-${{ github.event.number }}--ruma-docs.surge.sh - env: - SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }} - SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} - - - name: Remove preview URL - uses: Beakyn/gha-comment-pull-request@v1.0.2 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - description-message: Preview removed + - run: 'echo "PR number: ${{ github.event.number }}"'