GitHub Action is a CI CD service launched by GitHub in November 2019.

Some explanations of CI/CD

What is CI/CD? How to understand continuous integration, continuous delivery and continuous deployment.

CI/CD is a way to frequently deliver applications to customers by introducing automation during the application development phase. The core concepts of CI/CD are continuous integration, continuous delivery, and continuous deployment. As a solution for development and operations teams, CI/CD addresses the problems that arise when integrating new code (also known as “integration hell”).

Specifically, CI/CD enables continuous automation and continuous monitoring throughout the life cycle of an application, from the integration and test phases through delivery and deployment. These associated transactions are often collectively referred to as the “CI/CD pipeline” and are supported collaboratively by development and operations teams in an agile manner.

Writing in the front

If you just want to get a taste of the Github Action, read the following steps (and you may need some Github basics).

You are strongly advised to visit the official website for details of the official document

Deploy scheduled Tasks for Python

1. Create projects on GitHub

The creation steps can be searched by themselves, with no special requirements

Project directory

Note here. Making/workflows/run. The yaml file contains the definition of environmental tasks for specific task trigger condition, etc

├─.github ├─ workflows ├── run.yaml ├─ readme.md ├─ main.py ├─ requeirments.txtCopy the code
Main Document Contents
  1. run.yaml
name: Python package

on:
  push:
    branches:
      - main
  schedule:
    - cron: 00 02 * * *

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: '3.x'
      - name: Install dependencies
        run: | python -m pip install --upgrade pip pip install -r requeirments.txt      - name: execute py script
        env:
          FM_USERNAME: The ${{ secrets.USERNAME }}
        
        run: | python main.py
Copy the code
  1. main.py

def main() :
    print("Execute github Action")


if __name__ == "__main__":
    main()

Copy the code

2. Configure environment variables

If no configuration is required, skip it

3. Upload code and view Actions

. Because I’m making/workflows/run. The yaml file configured in the main branch push will perform the task, there will be automated

4. View the result

Here you can click on each step to view the execution of each step; If there is an error, the specific error content is displayed

5. My execution results

Because I configure automatic task execution at 2 o ‘clock every day, there will be a lot of tasks on my side

6. Some explanation

  • Name: Name of the job (displayed later on GitHub Actions)
  • On.push. branches: The current job is automatically executed after code is merged/pushed to this branch
  • On. schedule: Indicates that scheduled tasks conform to cron expressions
  • Jobs.build.runs -on: Select the running environment
  • Jobs.build. steps: Detailed job execution steps. You can define multiple steps to be executed in sequence
  • Jobs.build. steps: Detailed job execution steps. You can define multiple steps to be executed in sequence
  • Jobs.build.steps. Env: Get configured environment variables corresponding to github. Settings. Secrets (note not environment secrets)

Detailed configuration Check the workflow syntax of GitHub Actions only common explanations are shown here

7. Problem thinking

  1. Refer to the link for the difference between Environment secrets and Repository secrets

    Simply put, Repository secrets are variables that can be used anywhere. Environment secrets needs to be used in conjunction with Environment variables in yamL files.

  2. If you’re smart enough to think of white whoring, check out GitHub Actions for more information on using billing

    The following picture shows some restricted content (if you have a suitable collocation method, please recommend it to me)

  1. Cron expression time problem

    Because the Github Action standard time is UTC, you need to manually process the corresponding time if you need to comply with Beijing time.

Other possible uses

  • Publish static web Pages to GitHub Pages
  • Automatically deploy your code to the server
  • Perform scheduled tasks to obtain weather information
  • Perform scheduled tasks to chat with your little one
  • The crawler performs sign-in and task clocking

The resources

  • The official documentation
  • GitHub Action official marketplace
  • GitHub Actions Tutorial by Ruan Yifeng