GitHub Actions (GitWork) Automation Workflow Guide
GitHub Actions is a Continuous Integration/Continuous Deployment (CI/CD) service provided by GitHub. By writing simple YAML scripts, you can achieve a fully automated process of code submission triggering automatic testing, packaging, and deployment.
GitHub CI/CDWhat are Workflows?
Workflows are configurable automated processes defined in your repository.
- Config File Location: Must be stored in the
.github/workflows/directory. - Format:
.ymlor.yaml.
Core Concepts
- Workflow: The entire automated process, consisting of one or more Jobs.
- Event: The behavior that triggers the Workflow to run (such as
push,pull_request). - Job: A set of steps running on the same runner. Runs in parallel by default.
- Step: Specific execution instructions, can run Shell commands or use ready-made Actions.
- Action: Encapsulated reusable code blocks (such as
actions/checkoutfor pulling code).
Basic Syntax Example
Create a .github/workflows/main.yml file:
yaml
name: CI Automated Build # Workflow Name
# Trigger condition: Triggered when there is a push to the main branch
on:
push:
branches: [ "main" ]
jobs:
build-and-test: # Job ID
runs-on: ubuntu-latest # Execution Environment
steps:
# 1. Checkout code
- name: Checkout code
uses: actions/checkout@v4
# 2. Setup Node.js environment
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
# 3. Install dependencies
- name: Install Dependencies
run: npm install
# 4. Run test/build
- name: Build
run: npm run buildCommon GitHub Actions
You can find thousands of ready-made Actions in the GitHub Marketplace.
actions/checkout: Checkout repository code.actions/setup-node: Install Node.js.cloudflare/wrangler-action: Deploy Cloudflare Workers.peaceiris/actions-gh-pages: Deploy static web pages to GitHub Pages.
Environment Variables and Secrets
Do not hardcode passwords in the code! Use GitHub Secrets to store sensitive information.
- Set Secret: Go to repository
Settings->Secrets and variables->Actions->New repository secret. - Use in YAML:
${{ secrets.MY_API_KEY }}.
yaml
- name: Deploy to Cloudflare
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}Using with Cloudflare or Vercel
GitWork (GitHub Actions) can actively trigger deployment from the code repository side:
- Cloudflare Workers: Usually requires configuring an Action to actively push code.
- Vercel / Cloudflare Pages: These two usually provide Integration modes, meaning after you bind your GitHub account in the Vercel/Cloudflare dashboard, they will automatically listen to GitHub Push events and pull builds. You do not need to manually write
.ymlfiles (unless you have extremely complex customization needs).
For more detailed integration tutorials, please refer to the Cloudflare and Vercel sections of this site.
