How to tune automatic deployment
Is there any way to only auto build and deploy when only the folder web-app changes
9 Replies
I can't claim there isn't a better way but one option that comes to mind is using deploy hooks:
https://developers.cloudflare.com/pages/platform/deploy-hooks/
I think you would need to disable automatic branch deployments and in a GitHub action, probably on push, you can have your logic for deciding when to deploy and make a curl request to trigger the deploy as appropriate.
The deploy hook URL should be kept in a repository secret if you take this approach.
You’d have to switch to using direct uploads for your project and upload via GitHub actions.
I did that but I saw that in the next major version cloudflare action via wrangler publish is going to be deprecated
The command "publish" is deprecated in favour of "deploy". As far as I'm aware there are no functional differences, it's just renamed
Which action are you using the pages action or the wrangler action?
The pages action
name: Publish Web App to Cloudflare Pages
on:
push:
branches:
- master
- staging
- dev
paths:
- "web-app/"
jobs:
publish:
env:
NEXT_PUBLIC_SUPABASE_URL: ${{ github.ref == 'refs/heads/master' && secrets.SUPABASE_URL_PROD secrets.SUPABASE_URL_DEV }}
NEXT_PUBLIC_SUPABASE_ANON_KEY:
${{ github.ref == 'refs/heads/master' && secrets.SUPABASE_ANON_KEY_PROD secrets.SUPABASE_ANON_KEY_DEV }}
# NEXT_PUBLIC_NEXSCRIPT_API_URL: ${{ github.ref == 'refs/heads/master' && secrets.NEXSCRIPT_API_URL_PROD secrets.NEXSCRIPT_API_URL_DEV }}
NEXT_PUBLIC_NEXSCRIPT_API_KEY: ${{ github.ref == 'refs/heads/master' && secrets.NEXSCRIPT_API_KEY_PROD secrets.NEXSCRIPT_API_KEY_DEV }}
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
name: Publish to Cloudflare Pages
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/cache@v2
with:
path: web-app/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm install
working-directory: web-app
- name: Build
run: npm run build
working-directory: web-app
- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: nexscript
directory: out
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
workingDirectory: web-app
wranglerVersion: "3"
There is an open pull request on
cloudflare/pages-action
for this but I don't think it can be merged as-is, it would fail if someone uses it with wranglerVersion: "2"
. I've added a comment about that.