使用GitHub Actions在存储库中自定义和执行软件开发工作流程
Actions 的文件后缀为 yml 或 yaml

Actions 语法

name : action 简介

用于介绍此 action 的用途

on: action 触发条件

单个触发条件 on: push

多个触发条件 on: [push, pull_request]

复合触发条件

  1. on:
  2. # Trigger the workflow on push or pull request,
  3. # but only for the main branch
  4. push:
  5. branches:
  6. - main
  7. pull_request:
  8. branches:
  9. - main
  10. # Also trigger on page_build, as well as release created events
  11. page_build:
  12. release:
  13. types: # This configuration does not affect the page_build event above
  14. - created

手动触发条件

on: workflow_dispatch

jobs: action 相关配置

  1. name: Android CI
  2. on: [push]
  3. jobs:
  4. # job
  5. build:
  6. # 运行环境: ubuntu-latest, window-latest, macos-latest
  7. runs-on: ubuntu-latest
  8. # job 执行步骤
  9. steps:
  10. # 拷贝代码
  11. - uses: actions/checkout@v2
  12. # 配置 jdk
  13. - name: set up JDK 1.8
  14. uses: actions/setup-java@v1
  15. with:
  16. java-version: 1.8
  17. # 初始化子仓库
  18. - name: init submodule
  19. run: git submodule update --init
  20. # 添加 gradlew 执行权限
  21. - name: Grant execute permission for gradlew
  22. run: chmod +x gradlew
  23. - name: Build with Gradle
  24. run: ./gradlew build
  25. # - name: upload artifacts
  26. # uses: actions/upload-artifact@v2
  27. # with:
  28. # name: app-apk
  29. # path: app/build/outputs
  30. - name: Cache
  31. uses: actions/cache@v2
  32. with:
  33. path: app/build/outputs
  34. key: outputs

上传 artifact

  1. - name: upload artifact
  2. uses: actions/upload-artifact@v2
  3. with:
  4. # artifact name 用于下载 artifact
  5. name: app-apk
  6. path: app/build/outputs

下载 artifact

  1. # 注意:您只能下载在同一工作流程运行期间上传的工件(同一个 yml 文件内的流程)
  2. - name: Download artifact
  3. uses: actions/download-artifact@v2
  4. with:
  5. name: app-apk

缓存文件(可跨 yml 文件)

  1. - name: Cache
  2. uses: actions/cache@v2
  3. with:
  4. path: app/build/outputs
  5. key: outputs

参考

Github Actions 语法