Add Deploy preview workflow

This commit is contained in:
Piotr Rogowski 2023-08-25 12:52:09 +02:00
parent 2dcf10a7d9
commit c719363065
No known key found for this signature in database
GPG Key ID: 4A842D702D9C6F8F
1 changed files with 51 additions and 0 deletions

51
.github/workflows/deploy-preview.yml vendored Normal file
View File

@ -0,0 +1,51 @@
# Deploy preview to Cloudflare Pages
name: Deploy preview
on:
workflow_run:
workflows: ["Build preview"]
types:
- completed
jobs:
deploy:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
permissions:
contents: read
deployments: write
steps:
- name: Download artifact
uses: actions/github-script@v3.1.0
with:
script: |
const artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "build"
})[0];
const download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('${{github.workspace}}/build.zip', Buffer.from(download.data));
- run: unzip build.zip
- name: Deploy preview to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: wiki
directory: build
wranglerVersion: '3'