Skip to content

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/CD

What are Workflows?

Workflows are configurable automated processes defined in your repository.

  • Config File Location: Must be stored in the .github/workflows/ directory.
  • Format: .yml or .yaml.

Core Concepts

  1. Workflow: The entire automated process, consisting of one or more Jobs.
  2. Event: The behavior that triggers the Workflow to run (such as push, pull_request).
  3. Job: A set of steps running on the same runner. Runs in parallel by default.
  4. Step: Specific execution instructions, can run Shell commands or use ready-made Actions.
  5. Action: Encapsulated reusable code blocks (such as actions/checkout for 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 build

Common 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.

  1. Set Secret: Go to repository Settings -> Secrets and variables -> Actions -> New repository secret.
  2. 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 .yml files (unless you have extremely complex customization needs).

For more detailed integration tutorials, please refer to the Cloudflare and Vercel sections of this site.

All resources are from the open-source community. Disclaimer