chore: updated workflow #105
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: Build & Deploy to Cloudflare | |
on: | |
push: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
environment: ${{ github.ref == 'refs/heads/main' && 'main' || 'development' }} | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- uses: oven-sh/setup-bun@v2 | |
- name: Run setup script | |
run: | | |
bun install | |
bun setup-kv | |
env: | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
- name: Update wrangler.toml Name Field | |
run: | | |
branch_name=$(echo '${{ github.event.ref }}' | sed 's#refs/heads/##' | sed 's#[^a-zA-Z0-9]#-#g') | |
# Extract base name from wrangler.toml | |
base_name=$(grep '^name = ' wrangler.toml | sed 's/^name = "\(.*\)"$/\1/') | |
# Concatenate branch name with base name | |
new_name="${base_name}-${branch_name}" | |
# Truncate the new name to 63 characters for RFC 1035 | |
new_name=$(echo "$new_name" | cut -c 1-63) | |
# Update the wrangler.toml file | |
sed -i "s/^name = .*/name = \"$new_name\"/" wrangler.toml | |
echo "Updated wrangler.toml name to: $new_name" | |
- uses: cloudflare/wrangler-action@v3 | |
id: wrangler_deploy | |
with: | |
wranglerVersion: "3.86.0" | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
secrets: | | |
APP_ID | |
APP_PRIVATE_KEY | |
APP_WEBHOOK_SECRET | |
ENVIRONMENT | |
OPENAI_API_KEY | |
env: | |
APP_WEBHOOK_SECRET: ${{ secrets.APP_WEBHOOK_SECRET }} | |
APP_ID: ${{ secrets.APP_ID }} | |
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} | |
ENVIRONMENT: ${{ secrets.ENVIRONMENT }} | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
- name: Write Deployment URL to Summary | |
run: | | |
echo "### Deployment URL" >> $GITHUB_STEP_SUMMARY | |
echo "${{ steps.wrangler_deploy.outputs.deployment-url }}" >> $GITHUB_STEP_SUMMARY |