Storybook PR Preview Deploy #36
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
name: Storybook PR Preview Deploy | |
on: | |
workflow_run: | |
workflows: ["Storybook - PR Preview Build"] | |
types: | |
- completed | |
jobs: | |
deploy-storybook-pr-preview: | |
runs-on: ubuntu-latest | |
if: > | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' | |
steps: | |
- name: Download storybook-static | |
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 == "storybook-static" | |
})[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}}/storybook-static.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 storybook-static.zip -d storybook-static/ | |
- 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 `trustify-ui-pr-${issue_number}-preview.surge.sh`; | |
result-encoding: string | |
- name: Install Surge | |
run: npm install -g surge | |
- name: Deploy to Surge | |
run: surge ./storybook-static/ "${{steps.surge-url.outputs.result}}" --token ${{ secrets.SURGE_TOKEN }} | |
- name: Post URL as PR comment | |
uses: mshick/add-pr-comment@v2 | |
with: | |
message: "🚀 Storybook Deployed Preview: https://${{steps.surge-url.outputs.result}} ✨" | |
repo-token: ${{ secrets.PREVIEW_BOT_TOKEN }} | |
issue: ${{steps.issue_number.outputs.result}} |