-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR preview not building for members without write access
Fixes #121
- Loading branch information
Showing
4 changed files
with
165 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,19 @@ | ||
name: Deploy PR preview | ||
name: Build PR preview | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- labeled | ||
- opened | ||
- reopened | ||
- synchronize | ||
- closed | ||
|
||
concurrency: | ||
group: preview-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
permissions: | ||
actions: write | ||
checks: write | ||
contents: write | ||
deployments: write | ||
issues: write | ||
packages: write | ||
pull-requests: write | ||
pages: write | ||
repository-projects: write | ||
security-events: write | ||
statuses: write | ||
|
||
jobs: | ||
deploy-preview: | ||
build-preview: | ||
runs-on: ubuntu-latest | ||
if: contains(github.event.pull_request.labels.*.name, 'safe to test') | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
@@ -45,7 +31,20 @@ jobs: | |
run: | | ||
mkdocs build -f mkdocs.yml -d site | ||
- name: Deploy preview | ||
uses: access-nri/[email protected] | ||
- name: Save PR number | ||
run: | | ||
mkdir -p ./pr | ||
echo ${{ github.event.number }} > ./pr/NB | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: pr | ||
path: pr/ | ||
|
||
- name: Save built site | ||
run: | | ||
mkdir -p ./pr_site | ||
mv site ./pr_site/. | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
source-dir: site | ||
name: pr_site | ||
path: pr_site/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Clean PR preview | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Close PR"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
close-preview: | ||
runs-on: ubuntu-latest | ||
if: > | ||
github.event.workflow_run.event == 'pull_request' && | ||
github.event.workflow_run.conclusion == 'success' | ||
steps: | ||
- name: "Download PR number" | ||
uses: actions/[email protected] | ||
with: | ||
script: | | ||
var artifacts = await github.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: ${{github.event.workflow_run.id }}, | ||
}); | ||
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "prnumber" | ||
})[0]; | ||
var download = await github.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
var fs = require('fs'); | ||
fs.writeFileSync('${{github.workspace}}/prnumber.zip', Buffer.from(download.data)); | ||
- run: | | ||
unzip prnumber.zip | ||
echo "pr-number=$(cat prnumber.txt)" >> "$GITHUB_ENV" | ||
shell: bash | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.x | ||
|
||
- name: Clean preview | ||
uses: access-nri/pr-preview-action@v2 | ||
with: | ||
action: remove | ||
pr-number: ${{ env.pr-number }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Close PR | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
|
||
jobs: | ||
send-number: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Save PR number | ||
run: | | ||
mkdir -p ./prnumber | ||
echo ${{ github.event.number }} > ./prnumber/prnumber.txt | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: prnumber | ||
path: prnumber/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: Deploy PR preview | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Build PR preview"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
deploy-preview: | ||
runs-on: ubuntu-latest | ||
if: > | ||
github.event.workflow_run.event == 'pull_request' && | ||
github.event.workflow_run.conclusion == 'success' | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.x | ||
|
||
- name: "Download PR number" | ||
uses: actions/[email protected] | ||
with: | ||
script: | | ||
var artifacts = await github.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: ${{github.event.workflow_run.id }}, | ||
}); | ||
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "pr" | ||
})[0]; | ||
var download = await github.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
var fs = require('fs'); | ||
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); | ||
- run: | | ||
unzip pr.zip | ||
echo "pr-number=$(cat NB)" >> "$GITHUB_ENV" | ||
shell: bash | ||
- name: "Download built site" | ||
uses: actions/[email protected] | ||
with: | ||
script: | | ||
var artifacts = await github.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: ${{github.event.workflow_run.id }}, | ||
}); | ||
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "pr_site" | ||
})[0]; | ||
var download = await github.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
var fs = require('fs'); | ||
fs.writeFileSync('${{github.workspace}}/pr_site.zip', Buffer.from(download.data)); | ||
- run: unzip pr_site.zip | ||
|
||
- name: Deploy preview | ||
uses: access-nri/pr-preview-action@v2 | ||
with: | ||
source-dir: site | ||
action: deploy | ||
pr-number: ${{ env.pr-number }} |