gball个人知识库
首页
基础组件
基础知识
算法&设计模式
  • 操作手册
  • 数据库
  • 极客时间
  • 每日随笔
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • 画图工具 (opens new window)
关于
  • 网盘 (opens new window)
  • 分类
  • 标签
  • 归档
项目
GitHub (opens new window)

ggball

后端界的小学生
首页
基础组件
基础知识
算法&设计模式
  • 操作手册
  • 数据库
  • 极客时间
  • 每日随笔
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • 画图工具 (opens new window)
关于
  • 网盘 (opens new window)
  • 分类
  • 标签
  • 归档
项目
GitHub (opens new window)
  • 操作手册

  • maven

  • 部署

  • git

    • git指令
    • git本地上传项目
    • git问题总结
    • 解决github提交问题集合
    • github action学习总结
      • workflow流程
      • 组件
      • 工作流的流程图
      • 什么构成了action
        • Action metadata file 规则
        • Action metadata file内置参数解释
      • 教学包括:
      • 目前掌握
    • githubActionCICD实战
  • 工具包

  • 测试

  • docker

  • chatgpt

  • 工具与部署
  • git
ggball
2022-01-13

github action学习总结

# github actions总结

[toc]

github actions实验室 (opens new window)

Github在2019年底开放了内置的CI/CD工具GithubActions.这样使用Github托管的代码终于有了不借助外部服务自动化测试打包部署的能力. 同时由于后发优势,GithubActions几乎是目前最易用的CI/CD工具. GithubActions类似于传统的CI/CD工具,都是使用代码配置脚本,执行器执行脚本,页面管理执行过程的结构.

  • 在代码中配置脚本放在根目录的.github/workflow文件夹下,使用yaml格式描述配置.
  • Github默认给每个用户配置3个的执行器,我们也可以自己创建self-host执行器
  • 每个代码仓库的顶部标签页都有专门的actions按钮,进去就是当前仓库的执行过程管理页面.

对GithubActions的详细描述可以看官方文档本文只是介绍和划重点.

# workflow流程

根据事件触发对应的动作,顺序执行job, job需要在runner(GitHub provides Ubuntu Linux, Microsoft Windows, and macOS runners)上运行

工作流程概述

# 组件

Component Description
Action Individual tasks that you combine as steps to create a job. Actions are the smallest portable building block of a workflow. To use an action in a workflow, you must include it as a step.
Artifact Artifacts are the files created when you build and test your code. Artifacts might include binary or package files, test results, screenshots, or log files. Artifacts can be used by the other jobs in the workflow or deployed directly by the workflow.
Event A specific activity that triggers a workflow run.
Job A defined task made up of steps. Each job is run in a fresh instance of the virtual environment. Jobs can run at the same time in parallel or be dependent on the status of a previous job and run sequentially.
Runner Any machine with the GitHub Actions runner application installed. You can use a runner hosted by GitHub or host your own runner. A runner waits for available jobs. Runners run one job at a time reporting the progress, logs, and final result back to GitHub.
Step A step is a set of tasks performed by a job. Steps can run commands or actions.
Virtual Environment The virtual environment of a GitHub-hosted runner includes the virtual machine's hardware configuration, operating system, and installed software.
Workflow A configurable automated process that you can set up in your repository. Workflows are made up of one or more jobs and can be scheduled or activated by an event.
组件 描述
Action 一个可以你可以结合像steps来创建job。在工作流中,actions是最小,最轻便的模块。如果你想在工作流中使用actions,那么在action中必须要包含像step的组件。
Artifact 工件是工作流在编译代码或者测试代码时产生的文件
Event A specific activity that triggers a workflow run.
Job A defined task made up of steps. Each job is run in a fresh instance of the virtual environment. Jobs can run at the same time in parallel or be dependent on the status of a previous job and run sequentially.
Runner Any machine with the GitHub Actions runner application installed. You can use a runner hosted by GitHub or host your own runner. A runner waits for available jobs. Runners run one job at a time reporting the progress, logs, and final result back to GitHub.
Step A step is a set of tasks performed by a job. Steps can run commands or actions.
Virtual Environment The virtual environment of a GitHub-hosted runner includes the virtual machine's hardware configuration, operating system, and installed software.
Workflow A configurable automated process that you can set up in your repository. Workflows are made up of one or more jobs and can be scheduled or activated by an event.

# 工作流的流程图

image-20220113175906949

  • 代码提交到github仓库,
  • 触发push事件
  • 工作流开始工作,顺序执行job,job在runner上执行
  • job中step也是顺序执行的,step可以是actions或者command
  • 工作流完成,会生成一份报告

# 什么构成了action

Component Description
JavaScript source code files These files contain the logic of your action. This includes any dependencies or custom modules that your main logic may need.
Action metadata file This file contains information that the actions source code can use. An example of this is allowing a developer to specify an API key as an input variable for your action to consume. This file MUST be named action.yml
  • js源文件代码,用来执行逻辑,api调用
  • action元数据文件,也就是action.yml,用来配置输入输出变量,执行环境

以上两个组件在工作流是如何适应的

image-20220113163014093

# Action metadata file 规则

  • Filename must be action.yml
  • Required for both Docker container and JavaScript actions
  • Written in YAML syntax

  • 文件名必须是 action.yml
  • 是docker容器和js Actions
  • 内容符合YAML语法

# Action metadata file内置参数解释

Parameter Description Required
Name The name of your action. Helps visually identify the actions in a job. ✅
Description A summary of what your action does. ✅
Inputs Input parameters allow you to specify data that the action expects to use during runtime. These parameters become environment variables in the runner. ❌
Outputs Specifies the data that subsequent actions can use later in the workflow after the action that defines these outputs has run. ❌
Runs The command to run when the action executes. ✅
Branding You can use a color and Feather icon to create a badge to personalize and distinguish your action in GitHub Marketplace. ❌

# inputs的内置参数

To add inputs we need to add the inputs: parameter to the action.yml file. The inputs: parameter has a few parameters of its own.

Parameter Description Required
description: String describing the purpose of the input True
required: Boolean value indicating if the input parameter is required or not False (Default value is True)
default: String representing a default value for the input parameter False

# input参数引用方式

  • 在workflow.yml中可以使用with引入inputs参数
  • 在自定义js中可以利用@actions/core 引入inputs参数

示例

my-workflow.yml

name: "JS Actions"

on: [push]

jobs:
  action:
    runs-on: "ubuntu-latest"
    steps:
      - uses: actions/checkout@v1

      - name: "hello-action"
        uses: ./.github/actions/hello-world
        with:
          first-greeting: "Learning Lab User"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
main.js

const core = require("@actions/core");

const firstGreeting = core.getInput("first-greeting");
const secondGreeting = core.getInput("second-greeting");
const thirdGreeting = core.getInput("third-greeting");

console.log(`Hello ${firstGreeting}`);
console.log(`Hello ${secondGreeting}`);
if (thirdGreeting) {
    console.log(`Hello ${thirdGreeting}`);
}
1
2
3
4
5
6
7
8
9
10
11
12
13

action 可以提供api供外部应用使用,由此介绍什么是api?

举例子

那驾驶员驾驶汽车举例子

汽车组件

  • Gas pedal(加速器)
  • Brake pedal(刹车)
  • Steering wheel(方向盘)
  • Gear shift(换挡器)

驾驶员踩下加速器,加速器就会告诉汽车内部加快转速,驾驶员使用小小的力气转动方向盘,汽车内部是使用了成倍的力量来使汽车转向,这里汽车组件和汽车内部复杂的结构就构成了api,而驾驶员只需要熟练掌握api的使用,就可以轻松驾驶汽车。因为汽车组建的统一,即使不同的厂商生产的汽车,驾驶员也不需要在花费时间去学习新的驾车技术。

这里涉及到action 调用js代码,去请求接口数据,作为action的输出数据来源,然后最后调用方法,返回数据,从而封装成api

image-20220115020212909

# 教学包括:

Workflows Along the way you learned a little about workflows and how to configure them. You managed to accomplish all these things:

  • Define two different event triggers
  • Filter an event trigger to run only when a label is added to a pull request
  • You configured one unique job containing three unique steps within a workflow
  • You learned how to overwrite default action values by defining them in a workflow
  • One of your steps consumed a secret
  • One of your steps consumed the output of a previous step
  • That's quite a bit for a course that doesn't cover workflows!

Action metadata

  • You became familiar with over 1/2 of the syntax keywords that can be used in an action.yml file
  • Using inputs: and outputs: allowed you to create more dynamic and reusable metadata files for your actions.
  • You've mow written the metadata for three different actions

# 目前掌握

  • 执行逻辑代码

  • 设置入参

  • 利用action的outputs作为另外的action的入参

上次更新: 2025/06/04, 15:06:15
解决github提交问题集合
githubActionCICD实战

← 解决github提交问题集合 githubActionCICD实战→

最近更新
01
AIIDE
03-07
02
githubActionCICD实战
03-07
03
windows安装Deep-Live-Cam教程
08-11
更多文章>
Theme by Vdoing
总访问量 次 | 总访客数 人
| Copyright © 2021-2025 ggball | 赣ICP备2021008769号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×

评论

  • 评论 ssss
  • 回复
  • 评论 ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
  • 回复
  • 评论 ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
  • 回复
×