Workflow file for this run
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: Publish preview on CF Pages | |
on: | |
pull_request_target: | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
issues: write | |
pull-requests: write | |
jobs: | |
deploy-preview: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v4 | |
- name: Modified files | |
run: | | |
git fetch origin main:main | |
git diff --name-only --diff-filter=d main~ main | |
- name: Check access | |
if: ${{ github.event.pull_request.author_association != 'COLLABORATOR' && github.event.pull_request.author_association != 'OWNER' }} | |
run: | | |
echo "Event not triggered by a collaborator." | |
exit 1 | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Setup Deno environment | |
uses: denoland/setup-deno@v1 | |
with: | |
deno-version: v1.x | |
- name: Build site | |
run: deno task build | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
- name: Deploy to CF Pages | |
id: deploy-preview | |
uses: cloudflare/pages-action@v1 | |
env: | |
API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
GITHUB_TOKEN: ${{ secrets.GH_PAT }} | |
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | |
with: | |
apiToken: ${{ env.API_TOKEN }} | |
accountId: ${{ env.ACCOUNT_ID }} | |
projectName: ${{ github.event.repository.name }} | |
directory: 'target' | |
gitHubToken: ${{ env.GITHUB_TOKEN }} | |
branch: ${{ env.BRANCH_NAME }} | |
- name: Report preview environment in PR | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GH_PAT }} | |
script: | | |
let comments = await github.rest.issues.listComments({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
let previousComment = comments.data.find((i) => i.user.login === "probe-rs-bot"); | |
if(!previousComment) { | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: '# [Preview](${{ steps.deploy-preview.outputs.alias }})' | |
}) | |
} else { | |
await github.rest.issues.updateComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: previousComment.id, | |
body: '# [Preview](${{ steps.deploy-preview.outputs.alias }})' | |
}) | |
} | |