Deploy to Cloudflare Pages #53
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: Deploy to Cloudflare Pages | |
on: | |
workflow_run: | |
workflows: ["Conventional Commits"] | |
types: | |
- completed | |
jobs: | |
deploy-to-cloudflare: | |
name: Deploy to Cloudflare Pages | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "20.10.0" | |
- name: Install Bun | |
run: npm install -g bun | |
- name: Build the project | |
run: bun build | |
- name: Wrangler Install | |
run: bun add wrangler | |
- name: Publish to Cloudflare | |
env: | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
REPOSITORY: ${{ github.repository }} | |
PRODUCTION_BRANCH: "main" | |
OUTPUT_DIRECTORY: "dist" | |
run: | | |
IFS='/' read -ra fields <<< "$REPOSITORY" | |
projectName="${fields[1]}" | |
echo $projectName | |
bun wrangler pages project list > project_list.txt | |
if grep -q $projectName project_list.txt; then | |
echo "Project found" | |
else | |
echo "Project not found" | |
bun wrangler pages project create "$projectName" --production-branch "$PRODUCTION_BRANCH" | |
fi | |
bun wrangler pages publish "$OUTPUT_DIRECTORY" --project-name "$projectName" |