Skip to content

Deploy to Cloudflare Pages #80

Deploy to Cloudflare Pages

Deploy to Cloudflare Pages #80

Workflow file for this run

name: Deploy to Cloudflare Pages
on:
workflow_run:
workflows: ["Build"]
types:
- completed
jobs:
deploy-to-cloudflare:
name: Automatic Cloudflare Deploy
runs-on: ubuntu-22.04
steps:
- name: Verify Runner's Identity
id: verify-runner
run: |
echo "Runner name: $RUNNER_NAME"
if [[ "$RUNNER_NAME" != *"GitHub Actions"* ]]; then
echo "This workflow must run on a GitHub Actions runner. (github-actions[bot])"
exit 1
fi
- name: Deploy to Cloudflare
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: ubiquity/cloudflare-deploy-action@main
with:
repository: ${{ github.repository }}
production_branch: ${{ github.event.repository.default_branch }}
build_artifact_name: "full-stack-app"
output_directory: "full-stack-app"
current_branch: ${{ github.event.workflow_run.head_branch }}
cloudflare_account_id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
cloudflare_api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
commit_sha: ${{ github.event.workflow_run.head_sha }}
workflow_run_id: ${{ github.event.workflow_run.id }}
statics_directory: "static"
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20.10.0
- name: Generate Claimable Permit
id: permit_generation
# The sed command is used to remove color characters that are present in the output of the script
run: |
yarn
output=$(yarn "start:sign")
url=$(echo $output | grep -o "https://[^ ]*" | sed -n '2p' | sed 's/\x1B\[[0-9;]*[JKmsu]//g')
echo $output
echo "Permit available at the address:"
echo $url
echo "CLAIMABLE_URL=$url" >> $GITHUB_ENV
env:
BENEFICIARY_ADDRESS: "0xefC0e701A824943b469a694aC564Aa1efF7Ab7dd"
PAYMENT_TOKEN_ADDRESS: "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d"
AMOUNT_IN_ETH: 0
CHAIN_ID: 100
FRONTEND_URL: "${{ env.DEPLOYMENT_URL }}"
RPC_PROVIDER_URL: "https://rpc.ankr.com/gnosis"
UBIQUIBOT_PRIVATE_KEY: ${{ secrets.UBIQUIBOT_APP_PRIVATE_KEY_TEST }}
- uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const sha = "${{ github.event.workflow_run.head_sha }}";
const response = await github.rest.search.issuesAndPullRequests({
q: `repo:${owner}/${repo} is:pr sha:${sha}`,
per_page: 1,
});
const items = response.data.items;
if (items.length < 1) {
console.error('No related PRs found, skipping.');
return;
}
const issue_number = items[0].number;
console.info('Pull request number is', issue_number);
if (!issue_number) {
console.log('Action not triggered from an issue, skipping.');
return;
}
// Fetch existing comments on the issue
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});
// Look for an existing "Preview Deployment" comment
let previewComment = comments.data.find(comment =>
comment.body.startsWith("| Preview Deployment |")
);
const body = `| Preview Deployment |\n| ------------------ |\n| [${sha}](${{ env.CLAIMABLE_URL }}) |\n`;
if (previewComment) {
// Update the existing "Preview Deployment" comment
await github.rest.issues.updateComment({
owner,
repo,
comment_id: previewComment.id,
body
});
} else {
// Create a new "Preview Deployment" comment if not found
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body
});
}