Skip to content

Preview Deploy

Preview Deploy #6

name: Preview Deploy
on:
workflow_run:
workflows:
- "Preview Build"
types:
- completed
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Download Artifact
# For some reason we can't use the actions/download-artifact across workflows
# https://github.com/actions/download-artifact/issues/60
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
uses: actions/github-script@v3.1.0
with:
script: |
var fs = require('fs');
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
for (const artifact of artifacts.data.artifacts) {
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
fs.writeFileSync(`./${artifact.name}.zip`, Buffer.from(download.data));
}
- run: unzip web_demo.zip && unzip meta.json.zip
- name: Parse meta.json
run: |
echo "PR_NUMBER=$(jq -r .pr_number meta.json)" >> $GITHUB_ENV
echo "PR_BRANCH=$(jq -r .pr_branch meta.json)" >> $GITHUB_ENV
- name: Url slug variable
run: |
echo "URL_SLUG=${{ env.PR_NUMBER }}-${{ env.PR_BRANCH }}" >> $GITHUB_ENV
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: web_demo
repository-name: egui-pr-preview/pr
branch: 'main'
clean: true
target-folder: ${{ env.URL_SLUG }}
ssh-key: ${{ secrets.DEPLOY_KEY }}
commit-message: "Update preview for PR ${{ env.URL_SLUG }}"
force: false
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
Preview available at https://egui-pr-preview.github.io/pr/${{ env.URL_SLUG }}