Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly support previews in GitHub Actions #410

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "build"
on:
push:
pull_request_target:
pull_request:
branches: [ "main" ]
env:
cloudflare_project: noogle
Expand Down Expand Up @@ -31,31 +31,9 @@ jobs:
projectName: ${{ env.cloudflare_project }}
directory: ./result/lib/node_modules/noogle/out
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to Cloudflare Pages
id: publish
if: github.event_name == 'pull_request_target'
uses: cloudflare/pages-action@1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: noogle
directory: ./result/lib/node_modules/noogle/out
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
branch: pr-${{ github.event.pull_request.number }}
- uses: peter-evans/create-or-update-comment@v3
if: github.event_name == 'pull_request_target'
- name: Save output
if: github.event_name != 'push'
uses: actions/upload-artifact@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- DEPLOYMENT_COMMENT -->
<table><tr><td><strong>Latest commit:</strong> </td><td>
<code>${{ github.event.pull_request.head.sha }}</code>
</td></tr>
<tr><td><strong>Preview URL:</strong></td><td>
<a href='${{ steps.publish.outputs.url }}'>${{ steps.publish.outputs.url }}</a>
</td></tr>
<tr><td><strong>Branch Preview URL:</strong></td><td>
<a href='https://pr-${{ github.event.pull_request.number }}.${{ env.cloudflare_project }}.pages.dev'>https://pr-${{ github.event.pull_request.number }}.${{ env.cloudflare_project }}.pages.dev</a>
</td></tr>
</table>
edit-mode: replace
name: out
path: ./result/lib/node_modules/noogle/out
63 changes: 63 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: preview
on:
workflow_run:
workflows: ["build"]
types: ["completed"]
env:
cloudflare_project: noogle
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
steps:
- name: Fetch output
uses: actions/[email protected]
with:
script: |
var artifacts = await github.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 == "out"
})[0];
var download = await github.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}}/out.zip', Buffer.from(download.data));
- run: unzip out.zip
- name: Publish to Cloudflare Pages
id: publish
if: github.event_name == 'pull_request_target'
uses: cloudflare/pages-action@1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: noogle
directory: ./out
branch: pr-${{ github.event.pull_request.number }}
- uses: peter-evans/create-or-update-comment@v3
if: github.event_name == 'pull_request_target'
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- DEPLOYMENT_COMMENT -->
<table><tr><td><strong>Latest commit:</strong> </td><td>
<code>${{ github.event.pull_request.head.sha }}</code>
</td></tr>
<tr><td><strong>Preview URL:</strong></td><td>
<a href='${{ steps.publish.outputs.url }}'>${{ steps.publish.outputs.url }}</a>
</td></tr>
<tr><td><strong>Branch Preview URL:</strong></td><td>
<a href='https://pr-${{ github.event.pull_request.number }}.${{ env.cloudflare_project }}.pages.dev'>https://pr-${{ github.event.pull_request.number }}.${{ env.cloudflare_project }}.pages.dev</a>
</td></tr>
</table>
edit-mode: replace
Loading