2024-03-31 07:10:46 -04:00
|
|
|
name: 📦 PR Preview
|
2024-03-28 22:30:13 -04:00
|
|
|
|
|
|
|
on:
|
2024-04-10 16:18:32 -04:00
|
|
|
workflow_run:
|
|
|
|
workflows: [🛠️ Build PR Preview]
|
|
|
|
types:
|
|
|
|
- completed
|
2024-03-30 20:12:48 -04:00
|
|
|
|
2024-03-28 22:30:13 -04:00
|
|
|
permissions:
|
2024-04-10 16:18:32 -04:00
|
|
|
actions: read
|
2024-03-28 22:30:13 -04:00
|
|
|
contents: read
|
2024-04-10 16:18:32 -04:00
|
|
|
pull-requests: write
|
2024-03-28 22:30:13 -04:00
|
|
|
|
|
|
|
jobs:
|
2024-04-10 16:18:32 -04:00
|
|
|
metadata:
|
|
|
|
if: >
|
|
|
|
github.event.workflow_run.event == 'pull_request' &&
|
|
|
|
github.event.workflow_run.conclusion == 'success'
|
2024-03-28 22:30:13 -04:00
|
|
|
|
2024-04-10 16:18:32 -04:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
outputs:
|
|
|
|
pr_number: ${{ steps.metadata.outputs.pr_number }}
|
|
|
|
sha: ${{ steps.metadata.outputs.sha }}
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Download Website Build Artifact
|
|
|
|
uses: actions/github-script@v7.0.1
|
|
|
|
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 == "site-build-combined"
|
|
|
|
})[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}}/site-build-combined.zip', Buffer.from(download.data));
|
|
|
|
|
|
|
|
- name: Unpack Website
|
|
|
|
run: |
|
|
|
|
mkdir -p site
|
|
|
|
unzip site-build-combined.zip -d site
|
|
|
|
tar -czvf site-build-combined.tar.gz site
|
|
|
|
|
|
|
|
- name: Upload Combined Build Artifact
|
|
|
|
uses: actions/upload-artifact@v4
|
|
|
|
with:
|
|
|
|
name: site-build-combined.tar.gz
|
|
|
|
path: site-build-combined.tar.gz
|
|
|
|
retention-days: 5
|
|
|
|
|
|
|
|
- name: Download Metadata Artifact
|
|
|
|
uses: actions/github-script@v7.0.1
|
|
|
|
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 == "metadata"
|
|
|
|
})[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}}/metadata.zip', Buffer.from(download.data));
|
|
|
|
|
|
|
|
- name: Set Metadata
|
|
|
|
id: metadata
|
|
|
|
run: |
|
|
|
|
mkdir -p metadata
|
|
|
|
unzip metadata.zip -d metadata
|
|
|
|
echo "pr_number=$(cat metadata/NR)" >> "$GITHUB_OUTPUT"
|
|
|
|
echo "sha=$(cat metadata/SHA)" >> "$GITHUB_OUTPUT"
|
2024-03-28 22:30:13 -04:00
|
|
|
|
|
|
|
deploy:
|
2024-04-10 16:18:32 -04:00
|
|
|
needs: metadata
|
2024-03-30 20:12:48 -04:00
|
|
|
permissions:
|
|
|
|
contents: read
|
2024-04-10 16:18:32 -04:00
|
|
|
|
2024-04-03 03:06:38 -04:00
|
|
|
uses: privacyguides/webserver/.github/workflows/deploy-netlify-preview.yml@main
|
2024-03-28 22:30:13 -04:00
|
|
|
with:
|
2024-04-10 16:18:32 -04:00
|
|
|
netlify_alias: ${{ needs.metadata.outputs.pr_number }}
|
2024-03-31 07:10:46 -04:00
|
|
|
netlify_site_id: ${{ vars.NETLIFY_SITE }}
|
2024-03-28 22:30:13 -04:00
|
|
|
secrets:
|
|
|
|
NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }}
|
|
|
|
|
|
|
|
comment:
|
|
|
|
permissions:
|
|
|
|
pull-requests: write
|
2024-04-10 16:18:32 -04:00
|
|
|
needs: [deploy, metadata]
|
2024-03-28 22:30:13 -04:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
env:
|
2024-04-03 03:06:38 -04:00
|
|
|
address: ${{ needs.deploy.outputs.address }}
|
2024-03-28 22:30:13 -04:00
|
|
|
steps:
|
2024-03-30 20:12:48 -04:00
|
|
|
- uses: thollander/actions-comment-pull-request@v2.5.0
|
2024-03-28 22:30:13 -04:00
|
|
|
with:
|
2024-04-10 16:18:32 -04:00
|
|
|
pr_number: ${{ needs.metadata.outputs.pr_number }}
|
2024-03-28 22:30:13 -04:00
|
|
|
message: |
|
2024-03-30 20:12:48 -04:00
|
|
|
### <span aria-hidden="true">✅</span> Your preview is ready!
|
|
|
|
|
|
|
|
| Name | Link |
|
|
|
|
| :---: | ---- |
|
2024-04-10 16:18:32 -04:00
|
|
|
| <span aria-hidden="true">🔨</span> Latest commit | ${{ needs.metadata.outputs.sha }} |
|
2024-03-30 20:12:48 -04:00
|
|
|
| <span aria-hidden="true">😎</span> Preview | ${{ env.address }} |
|
2024-03-28 22:30:13 -04:00
|
|
|
comment_tag: deployment
|