Github Actions
概览
可以创建工作流程来构建和测试存储库的每个拉取请求,或将合并的拉取请求部署到生产环境。
GitHub Actions 不仅仅是 DevOps,还允许您在存储库中发生其他事件时运行工作流程。 例如,您可以运行工作流程,以便在有人在您的存储库中创建新问题时自动添加相应的标签。
GitHub 提供 Linux、Windows 和 macOS 虚拟机来运行工作流程,或者您可以在自己的数据中心或云基础架构中托管自己的自托管运行器。
创建示例工作流程
GitHub Actions 使用 YAML 语法来定义工作流程。 Each workflow is stored as a separate YAML file in your code repository, in a directory named .github/workflows.
您可以在仓库中创建示例工作流程,只要推送代码,该工作流程就会自动触发一系列命令。 In this workflow, GitHub Actions checks out the pushed code, installs the bats testing framework, and runs a basic command to output the bats version: bats -v.
1、在您的仓库中,创建 .github/workflows/ 目录来存储工作流程文件。
2、在 .github/workflows/ 目录中,创建一个名为 learn-github-actions.yml 的新文件并添加以下代码
name: learn-github-actions
on: [push]
jobs:
check-bats-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '14'
- run: npm install -g bats
- run: bats -v
3、提交这些更改并将其推送到您的 GitHub 仓库。
您的新 GitHub Actions 工作流程文件现在安装在您的仓库中,每次有人推送更改到仓库时都会自动运行。 To see the details about a workflow's execution history, see "Viewing the activity for a workflow run."
Viewing the activity for a workflow run
触发工作流后,将创建执行工作流的工作流运行。工作流运行启动后,您可以在GitHub上看到运行进度的可视化图形,并查看每个步骤的活动。
1、在 GitHub.com 上,导航到仓库的主页面。
2、在仓库名称下,单击 Actions(操作)。
3、在左侧边栏中,单击您想要查看的工作流程。
4、在“Workflow runs(工作流程运行)”下,单击您想要查看的运行的名称。
5、在 Jobs(作业)下或可视化图中,单击您要查看的作业。
6、View the results of each step.

demo
demo1
** demo1.yml **
name: Build and Deploy
on:
push:
branches:
- main
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.1
- name: Install and Build
run: |
yarn
yarn build
- name: Deploy
uses: JamesIves/github-pages-deploy-action@4.1.1
with:
branch: gh-pages
folder: build
clean: true
demo2
** demo2.yml **
name: Build and Deploy
on:
push:
branches:
- master
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.1
- name: Install and Build
run: |
yarn
yarn build
- name: Deploy
uses: s0/git-publish-subdir-action@develop
env:
REPO: git@github.com:ovim/ovim.github.io.git
BRANCH: master
FOLDER: build
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_PRIVATE_KEY }}