Github Action Basics

GitHub Actions allow you to automate workflows directly from your GitHub repository. It enables you to build, test, and deploy your code based on specific events (such as code pushes, pull requests, and more).

Key Concepts of GitHub Actions

  • Workflows: Automated processes that you define in your repository.

  • Jobs: A workflow is composed of one or more jobs that can run sequentially or in parallel.

  • Steps: Jobs contain steps that run commands in the job's virtual environment.

  • Actions: The individual tasks that you can combine to create jobs and customize your workflow. You can use actions defined in the GitHub marketplace or create your own.

Adding a GitHub Action to Your Repository

Create a Workflow File:

  • Workflow files are stored in the .github/workflows directory of your repository.

  • Workflow files use YAML syntax and have a .yml extension.

Example WorkFlow File:

name: AI Search - Correctness Check

on:
  push:
    paths:
      - copilot/search


jobs:
  run-script:
    runs-on: ubuntu-latest
    env:
      OPENAI_KEY: ${{ secrets.OPENAI_KEY }}  

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

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

    - name: Install dependencies
      run: |
        pip install -q arize==7.19.0 arize-phoenix==4.21.0 nest_asyncio packaging openai 'gql[all]'
    - name: Run script
      run: python ./copilot/experiments/ai_search_test.py

Breakdown:

  • name: The name of the workflow.

  • on: The events that trigger the workflow. In this case, it's triggered on any push to the main branch.

  • jobs: The jobs that will run as part of the workflow.

  • runs-on: Specifies the virtual environment to run the job (e.g., ubuntu-latest).

  • steps: The steps to run within the job.

    • name: A descriptive name for the step.

    • uses: Specifies an action to use (from the GitHub Actions marketplace).

    • run: Runs a command in the virtual environment.

Common on Event Options:

  1. push: Triggers the workflow when code is pushed to the repository.

    on:
      push:
        branches:
          - main
  2. pull_request: Triggers the workflow when a pull request is opened, updated, or closed.

    on:
      pull_request:
        branches:
          - main
  3. schedule: Triggers the workflow on a scheduled time, using cron syntax.

    on:
      schedule:
        - cron: "0 0 * * *" # Runs every day at midnight
  4. workflow_run: Triggers the workflow when another workflow completes.

    on:
      workflow_run:
        workflows: ["Build"]
        types:
          - completed
  5. check_suite: Triggers the workflow when a check suite is completed.

    on:
      check_suite:
        types: [completed]
  6. check_run: Triggers the workflow when a check run is created or completed.

    on:
      check_run:
        types: [completed]
  7. Combining Multiple Events You can combine multiple events, filter by branch, tags, or specify types for more granular control over when a workflow runs.

    on:
      push:
        branches:
          - main
      pull_request:
        branches:
          - main
      schedule:
        - cron: "0 0 * * 0"  # Run on Sundays
  8. Filtering Events by Tags

    on:
      push:
        tags:
          - "v1.*"

Last updated

Copyright © 2023 Arize AI, Inc