If you do not have a GitHub account you can sign up for one here. We can now create a new repository here. It should be an empty repository with no README, .gitignore, or license. You will be dropped off at a screen like the one below. Make sure you copy the following commands to use locally:
git remote add origin [email protected]:<username>/<repository-name>.git
git push -u origin production # this will be "main"
Once the repository has been created we can add the following secrets to the repository:
CLOUDFLARE_ACCOUNT_ID
CLOUDFLARE_API_TOKEN
To do that we will need to go to:
Settings > Secrets & Variables > Actions > New repository secret
We can now create a new qwik-city
project:
pnpm create qwik@latest
Select the basic app option that will give us a wokring template with qwik-city
integrated into it. Once the project has been created we can add the Cloudflare Pages integration:
pnpm run qwik add cloudflare-pages
To add GitHub Actions to our repository we will need to create a new file in the .github/workflows
directory called publish.yml
. We can then add the following workflow to the file:
mkdir -p .github/workflows
touch .github/workflows/publish.yml
Cloudflare actually has and maintains there own GitHub Action for deploying to Cloudflare Pages. We will be using that in our workflow. You can find the GitHub Action here.
name: Publish
on:
push:
branches:
- production # this will be "main"
- staging # development branch
pull_request:
branches:
- staging
types:
- edited
- opened
- synchronize
jobs:
publish:
name: Publish to Cloudflare Pages
# This is very important don't miss it!
permissions:
contents: read
deployments: write
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
node-version: [18.x]
pnpm-version: [8.x]
timeout-minutes: 10
steps:
- uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v3
with:
fetch-depth: 2
- uses: pnpm/[email protected]
with:
version: ${{ matrix.pnpm-version }}
- uses: actions/setup-node@v3
with:
cache: 'pnpm'
node-version: ${{ matrix.node-version }}
- run: pnpm install --frozen-lockfile
- run: pnpm run build
env:
NODE_ENV: production
- uses: cloudflare/[email protected]
with:
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
directory: dist
gitHubToken: ${{ github.token }}
projectName: qwik-blog-test # your project name
We can now add the GitHub remotes and push to GitHub:
git remote add origin [email protected]:<username>/<repository-name>.git
git push -u origin production # this will be "main"
After pushing to GitHub we can either navigate to the repository on GitHub and click on the "Actions"
tab or we can navigate to our Cloudflare Pages Dashboard and see the deployment in progress. Once the deployment has finished we can click on the "Visit Site"
button in the Cloudflare Pages Dashboard to see our application live.
We have now successfully deployed a Qwik-City application to Cloudflare Pages via GitHub Actions. You can find the repository for this blog post here.
Hey! I'm Cody, a Christian, US Navy Veteran, Jayhawk, and an American expat living outside of Bogotá, Colombia. I am currently searching for my next role in the industry. In my free time, you can find me in the gym, teaching myself guitar, or smoking some brisket or ribs.