Skip to content

PR Preview Deploy #2294

PR Preview Deploy

PR Preview Deploy #2294

name: PR Preview Deploy
on:
workflow_run:
workflows: ["PR Preview Build"]
types:
- completed
jobs:
deploy-pr-preview:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Download dist
uses: actions/github-script@v6
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 == "dist"
})[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}}/dist.zip', Buffer.from(download.data));
- name: Download PR number
uses: actions/github-script@v6
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"
})[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 dist.zip -d dist/
- run: unzip pr.zip
- name: Generate issue_number
uses: actions/github-script@v6
id: issue_number
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
return Number(fs.readFileSync('./NR'));
result-encoding: string
- name: Generate Surge URL
uses: actions/github-script@v6
id: surge-url
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = ${{steps.issue_number.outputs.result}};
return `trustification-spog-pr-${issue_number}-preview.surge.sh`;
result-encoding: string
- name: Install Surge
run: npm install -g surge
- name: Deploy to Surge
run: surge ./dist/ "${{steps.surge-url.outputs.result}}" --token ${{ secrets.SURGE_TOKEN }}
- name: Post URL as PR comment
uses: mshick/add-pr-comment@v2
with:
message: "🚀 Deployed Preview: https://${{steps.surge-url.outputs.result}} ✨"
repo-token: ${{ secrets.PREVIEW_BOT_TOKEN }}
issue: ${{steps.issue_number.outputs.result}}