ci: Fix deploying previews for forked repositories
This commit is contained in:
parent
2dacaf2ea0
commit
96155915fe
27
.github/workflows/ci.yml
vendored
27
.github/workflows/ci.yml
vendored
@ -249,27 +249,18 @@ jobs:
|
|||||||
|
|
||||||
- name: Build docs
|
- name: Build docs
|
||||||
run: target/debug/xtask doc --deny-warnings
|
run: target/debug/xtask doc --deny-warnings
|
||||||
|
|
||||||
- name: Deploy PR preview
|
- name: Compress docs
|
||||||
id: deploy_preview
|
|
||||||
if: github.event_name == 'pull_request'
|
if: github.event_name == 'pull_request'
|
||||||
continue-on-error: true
|
run: |
|
||||||
uses: dswistowski/surge-sh-action@v1.0.1
|
tar --zstd -cf docs.tar.zstd -C target doc
|
||||||
with:
|
|
||||||
domain: pr-${{ github.event.number }}--ruma-docs.surge.sh
|
|
||||||
project: target/doc
|
|
||||||
login: ${{ secrets.SURGE_LOGIN }}
|
|
||||||
token: ${{ secrets.SURGE_TOKEN }}
|
|
||||||
|
|
||||||
- name: Comment deploy PR preview URL
|
- name: Upload docs as artifact
|
||||||
if: steps.deploy_preview.outcome == 'success'
|
if: github.event_name == 'pull_request'
|
||||||
uses: Beakyn/gha-comment-pull-request@v1.0.2
|
uses: actions/upload-artifact@v3
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
|
||||||
with:
|
with:
|
||||||
description-message: |
|
name: docs
|
||||||
----
|
path: docs.tar.zstd
|
||||||
Preview: https://pr-${{ github.event.number }}--ruma-docs.surge.sh
|
|
||||||
|
|
||||||
- name: Deploy to docs repo
|
- name: Deploy to docs repo
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
62
.github/workflows/docs-preview.yml
vendored
Normal file
62
.github/workflows/docs-preview.yml
vendored
Normal file
@ -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
|
57
.github/workflows/docs-remove-preview.yml
vendored
Normal file
57
.github/workflows/docs-remove-preview.yml
vendored
Normal file
@ -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
|
17
.github/workflows/pr-closed.yml
vendored
17
.github/workflows/pr-closed.yml
vendored
@ -7,20 +7,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docs:
|
docs:
|
||||||
name: Remove Docs Preview
|
name: Trigger
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Teardown
|
- run: 'echo "PR number: ${{ github.event.number }}"'
|
||||||
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
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user