Skip to content

GitHub Actions

Is it free?

GitHub Actions is free for public repositories.

The components of GitHub Actions

GitHub Actions 工作流、Job 与 Step 的关系

.github/workflows/ci-cd.yml

name

yaml
name: "Tests of push & pull"

on

yaml
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs

yaml
jobs:
  tests:
    name: 'Validate README.md changes'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: '3.8'

      - name: Install dependencies
        run: python -m pip install -r scripts/requirements.txt

      - name: Validate Markdown format
        run: python scripts/validate/format.py ${FILENAME}

      - name: Validate pull request changes
        run: scripts/github_pull_request.sh ${{ github.repository }} ${{ github.event.pull_request.number }} ${FILENAME}
        if: github.event_name == 'pull_request'

      - name: Checking if push changes are duplicated
        run: python scripts/validate/links.py ${FILENAME} --only_duplicate_links_checker
        if: github.event_name == 'push'
yaml
jobs:
  unittest:
    name: 'Run tests of validate package'
    runs-on: ubuntu-latest

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.8'
    
    - name: Install dependencies
      run: python -m pip install -r scripts/requirements.txt

    - name: Run Unittest
      run: |
        cd scripts
        python -m unittest discover tests/ --verbose

env

yaml
env:
  FILENAME: README.md

GITHUB_TOKEN

yaml
# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write
env:
  GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Marketplace

Powered by VitePress