Skip to content

GitHub Actions

Access Server through GitHub Actions

name: Access Server via GitHub Actions
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: SSH to server and running some commands.
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd /var/www/my-project && git pull origin main
# Add another commands here

Deploy Static Site to Cloudflare Pages

First Scenario

Deploy directly from GitHub Actions to Cloudflare Pages and using wrangler-action for authentication & deployment.

name: Deploy to Cloudflare Pages
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Run build
run: pnpm build
- name: Deploy to Cloudflare Pages
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: "frontend-pages"
directory: "< dist_or_out>"

Another Scenario

Deploys from a VPS/server that has a public IP, then uploads from the server to Cloudflare Pages. Useful for custom processing (e.g., caching, logs, pre-processing).

name: CF | Upload Static Site from Server
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: SSH to server, run pnpm commands and upload static site to CF Pages
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd /var/www/frontend && git pull origin main
export PATH=/root/.local/share/pnpm:/root/.nvm/versions/node/v20.18.0/bin:$PATH
pnpm install --frozen-lockfile && pnpm build
CLOUDFLARE_API_TOKEN="${{ secrets.CLOUDFLARE_API_TOKEN }}" npx wrangler pages deploy /var/www/frontend/<dist_or_out> \
--project-name=frontend-pages

Workflow output

out: Uploading... (100/126)
out: Uploading... (109/126)
out: Uploading... (117/126)
out: Uploading... (126/126)
out: ✨ Success! Uploaded 26 files (100 already uploaded) (1.92 sec)
out: 🌎 Deploying...
out: ✨ Deployment complete! Take a peek over at https://xxyyzz.pages.dev

Deploy Laravel API to AWS Lambda

This workflow automates the deployment of a Laravel API to AWS Lambda using the Serverless Framework. It installs necessary dependencies, sets up PHP, and runs serverless deploy to push the application to AWS Lambda.

name: Deploy Laravel API to AWS Lambda
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Install dependencies
run: composer install
- name: Install Serverless Framework
run: npm install -g serverless
- name: Deploy to Lambda
run: serverless deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: <your_best_region>