github action
The concept is introduced
Ability to introduce
- Support branches build, test, package, Release, or deploy
- Support end-to-end Continuous integration (CI) and Continuous Deployment (CD)
- Supports building on third-party cloud platforms, Github platforms, and developers’ own servers
- There are three types of actions supported: Same-Repository Action, Public Action Repository, and Github Action Market
- Support for events to trigger specific builds
- Supports sending health status notifications by email
- Only github servers have restrictions
The term is introduced
- Action: Minimum execution unit of Workflow
- Artifact: An intermediate file produced by a workflow run, including logs, test results, and so on
- Continuous Integration (CI) : Automated build and test
- Continuous Deployment (CD) : Automatic deployment
- Event: the trigger workflow
- GitHub- Hosted Runner: A VM on the Githut platform
- Job: Decomposition of Workflow, serialized dependencies; Can be parallel
- Runner: Running environment
- Self-hosted Runner: The developer’s own new environment
- Step: Job decomposition
Github platform server restrictions
- A REPO can run up to 20 workflows simultaneously. If the number exceeds 20, wait in line
- Each job in a Workflow can run for a maximum of six hours. Over, straight to the end
- Jobs in all branches have different restrictions based on the Github level. If exceeded, enter the queue and wait.
- A maximum of 1000 requests per hour is 1.5 API /1m
- If you use any action, you may get your account banned from Github
GitHub plan | Total concurrent jobs | Maximum concurrent macOS jobs |
---|---|---|
Free | 20 | 5 |
Pro | 40 | 5 |
Team | 60 | 5 |
Enterprise | 180 | 15 |
- Github generates usage statistics
The action yml file
Grammatical structure
name: Greet Everyone
# This workflow is triggered on pushes to the repository.
on: [push]
jobs:
build:
# Job name is Greeting
name: Greeting
# This job runs on Linux
runs-on: ubuntu-latest
steps:
# This step uses GitHub's hello-world-javascript-action: https://github.com/actions/hello-world-javascript-action
- name: Hello world
uses: actions/hello-world-javascript-action@v1
with:
who-to-greet: 'Mona the Octocat'
id: hello
# This step prints an output (time) from the previous step's action.
- name: Echo the greeting's time
run: echo 'The time was ${{ steps.hello.outputs.time }}.'
Copy the code
How do I create yML files
*. Github /workflows Created. Yml or. Yaml variable names that were prefixed with * GITHUB_. * Environment variables are case sensitive * Action Secrets must be placed in environment variables or as input,Copy the code
step secret
steps:
- name: Hello world
run: echo Hello world $FIRST_NAME $middle_name $Last_Name!
env:
FIRST_NAME: Mona
middle_name: The
Last_Name: Octocat
Copy the code
steps:
- name: My first action
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FIRST_NAME: Mona
LAST_NAME: Octocat
Copy the code
steps:
- name: Hello world action
with: # Set the secret as an input
super_secret: ${{ secrets.SuperSecret }}
env: # Or as an environment variable
super_secret: ${{ secrets.SuperSecret }}
Copy the code
Yml syntax rules
Express grammatical
Use skills
step
steps:
- uses: actions/setup-node@74bc508 # Reference a specific commit
- uses: actions/setup-node@v1 # Reference the major version of a release
- uses: actions/[email protected] # Reference a minor version of a release
- uses: actions/setup-node@master # Reference a branch
Copy the code
trigger
# push
name: descriptive-workflow-name
on: push
Copy the code
# per hour on: schedule: -cron: '0 * * * *'Copy the code
-master tags: -v1 # File paths to consider in the event. Optional; defaults to all. paths: - 'test/*'Copy the code
Github host Operating environment
runs-on: ubuntu-latest
Copy the code
The github server uses the following unified configuration:
* 2-core CPU
* 7 GB of RAM memory
* 14 GB of SSD disk space
Copy the code
Linux is recommended. The resource consumption varies with the ratio.
* Linux :1, * Window :2 * MAC :10.Copy the code
self-host
runs-on: [self-hosted, linux, ARM32]
Copy the code
Refer to the action
- public repo
{owner}/{repo}@{ref} or {owner}/{repo}/{path}@{ref}.
Copy the code
- same repo
@ {owner} / {'} {ref} the or. / path/to/dir | - hello - world (repository) | | __. Making | └ ─ ─ workflows | └ ─ ─ My - first - workflow. Yml | └ ─ ─ the actions | | __ hello world - action | └ ─ ─ action. Yml jobs: build: runs - on: ubuntu-latest steps: # This step checks out a copy of your repository. - uses: actions/checkout@v1 # This step references the directory that contains the action. - uses: .. /github/actions/hello-world-actionCopy the code
- docker container
docker://{image}:{tag}
Copy the code
According to the workflow status
! [](https://github.com/actions/hello-world/workflows/Greet%20Everyone/badge.svg)Copy the code
Using the command line
jobs:
my_first_job:
steps:
- name: My first step
uses: docker://gcr.io/cloud-builders/gradle
- name: Install Dependencies
run: npm install
shell: bash
Copy the code
With the reference
jobs:
my_first_job:
steps:
- name: My first step
uses: actions/hello_world@master
with:
first_name: Mona
middle_name: The
last_name: Octocat
Copy the code
First_name will be converted to INPUT_FIRST_NAME
If GITHUB_TOKEN is not met, you can use personal Accesss_token
The action management
Read permission Allows you to view logs
You can stop an action only with write permission
step debug
ACTIONS_STEP_DEBUG = true
Copy the code
runner debug
ACTIONS_RUNNER_DEBUG = true
Copy the code