wiki/.github/workflows/deploy-preview.yml

71 lines
2.3 KiB
YAML
Raw Normal View History

2023-08-25 03:52:09 -07:00
# 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:
2023-08-25 04:39:49 -07:00
issues: write
2023-08-25 03:52:09 -07:00
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));
2023-08-25 03:58:10 -07:00
- run: unzip build.zip -d build
2023-08-25 03:52:09 -07:00
- name: Deploy preview to Cloudflare Pages
2023-08-25 04:20:54 -07:00
id: deploy
2023-08-25 03:52:09 -07:00
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: wiki
directory: build
2023-08-25 04:06:26 -07:00
gitHubToken: ${{ secrets.GITHUB_TOKEN }} # GitHub Deployments
2023-09-14 13:19:57 -07:00
wranglerVersion: "3"
2023-08-25 04:20:54 -07:00
2023-09-14 13:19:57 -07:00
- name: "Comment on PR"
2023-08-25 04:20:54 -07:00
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
try {
const issue_number = Number(fs.readFileSync('./build/PR_NR'));
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: "Preview URL: ${{ steps.deploy.outputs.alias }}"
});
} catch (err) {
console.log(err);
}