You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
GitHub Action
Cloudflare Build Log
0.1.4
Get your Cloudflare Build Logs in PRs.
Put this in your .github/workflows/action.yml
on:
pull_request:
types: [opened, synchronize]
jobs:
fetch-logs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set Environment Variables
id: setenv
run: |
echo "PROJECT_NAME=${{ secrets.CLOUDFLARE_PROJECT_NAME }}" >> $GITHUB_ENV
echo "CLOUDFLARE_API_TOKEN=${{ secrets.CLOUDFLARE_API_TOKEN }}" >> $GITHUB_ENV
echo "ACCOUNT_ID=${{ secrets.CLOUDFLARE_ACCOUNT_ID }}" >> $GITHUB_ENV
echo "PR_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV
- name: Poll for Cloudflare Pages Build and Fetch Logs
uses: JDeepD/cloudflare-build-log@latest
- name: Post build logs to PR
if: success()
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const buildLogs = process.env.logs || 'No logs available.';
const commentBody = `Cloudflare Pages build logs for **${{ github.head_ref }}** branch:\n\n${buildLogs}`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
- name: Post build status
if: always()
run: |
echo "Build status: ${{ job.status }}"
You need to put the following secrets in your repository:
SECRET NAME | SECRET VALUE |
---|---|
CLOUDFLARE_PROJECT_NAME | Your Cloudflare Project Name. Go to Cloudflare Dashboard > Workers and Pages > Overview. |
CLOUDFLARE_API_TOKEN | Generate a Cloudflare API Token (not API Key) if not generated already with Read Permissions on Pages. Make sure to set the expiration of the token properly. |
CLOUDFLARE_ACCOUNT_ID | You will find your Account ID on the Right Panel in Cloudflare Dashboard > Workers and Pages > Overview. |