-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ea9e48
commit 00782ff
Showing
3 changed files
with
108 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Build PR Preview | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
|
||
- name: Build with Zola | ||
uses: shalzz/zola-deploy-action@v0.19.2 | ||
env: | ||
BUILD_ONLY: true | ||
BUILD_FLAGS: --base-url http://br-www-docs.s3-website-us-east-1.amazonaws.com/preview/cockpit/${{ github.event.number }} | ||
|
||
- name: Save PR number | ||
run: | | ||
mkdir -p ./pr | ||
echo ${{ github.event.number }} > ./pr/NR | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: pr-preview | ||
path: | | ||
pr/ | ||
public/ |
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,55 @@ | ||
name: Deploy PR Preview | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Build PR Preview"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
upload: | ||
runs-on: ubuntu-latest | ||
if: > | ||
github.event.workflow_run.event == 'pull_request' && | ||
github.event.workflow_run.conclusion == 'success' | ||
steps: | ||
- name: Download artifact | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
var artifacts = await github.rest.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-preview" | ||
})[0]; | ||
var download = await github.rest.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 | ||
|
||
- name: Retrieve PR Number | ||
run: | | ||
echo "PR=$(cat pr/NR)" >> $GITHUB_ENV | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: us-east-1 | ||
|
||
- name: Upload to AWS | ||
run: | | ||
# Delete the files from the previous iteration of this PR (if they exist) | ||
aws s3 rm --recursive s3://br-www-docs/preview/cockpit/${{ env.PR }} | ||
# Upload the new ones | ||
aws s3 cp --recursive public s3://br-www-docs/preview/cockpit/${{ env.PR }} | ||
echo "Preview at http://br-www-docs.s3-website-us-east-1.amazonaws.com/preview/cockpit/${{ env.PR }}" |
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,20 @@ | ||
name: Remove PR Preview | ||
|
||
on: | ||
pull_request_target: | ||
types: [closed] | ||
|
||
jobs: | ||
cleanup: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: us-east-1 | ||
|
||
- name: Remove proposal preview | ||
run: | | ||
aws s3 rm --recursive s3://br-www-docs/preview/cockpit/${{ github.event.pull_request.number }} |