github动作:如何自动化标签构建工件?
我目前有以下YAML文件可以安装构建依赖关系,构建和创建构建工件,只要主部门更新或将提交推向拉请请求。每当我创建一个新标签时,我想添加将构建工件添加到发行版中的功能。我已经看过创建版本行动似乎合理。我知道我可以制作一个运行的新YAML文件
on:
push:
tags:
,但我不想复制逻辑以安装构建依赖项和构建。有什么方法可以重新利用逻辑进行设置和构建以实现这一目标?
name: CI
on:
push:
branches: [ master ]
pull_request:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.CI_PAT }}
submodules: recursive
fetch-depth: 0
- name: install dependencies
run: |
sudo apt install gcc-arm-none-eabi srecord clang-format
pip install cmake cmake-format
- name: compile
run: cmake --preset default && cmake --build --preset default
- name: lint
run: |
find . \( -name *.c -o -name *.h \) -not -path "*/ext/*" -not -path "*/build/*" -exec clang-format -style=file --dry-run --Werror {} +
find . \( -name CMakeLists.txt -o -name *.cmake \) -not -path "*/ext/*" -not -path "*/build/*" -exec cmake-format --check {} +
- name: upload binaries
uses: actions/upload-artifact@v3
with:
name: binaries
path: build/bin
I currently have the following yaml file to install build dependencies, build, and create build artifacts whenever the master branch is updated or a commit is pushed to a pull request. I want to add the ability to add build artifacts to a release whenever I create a new tag. I've seen the create release action that seems reasonable. I understand that I could make a new yaml file that runs
on:
push:
tags:
but I don't want to have to duplicate the logic to install build dependencies and build. Is there a way I can re-use the logic to setup and build to achieve this?
name: CI
on:
push:
branches: [ master ]
pull_request:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.CI_PAT }}
submodules: recursive
fetch-depth: 0
- name: install dependencies
run: |
sudo apt install gcc-arm-none-eabi srecord clang-format
pip install cmake cmake-format
- name: compile
run: cmake --preset default && cmake --build --preset default
- name: lint
run: |
find . \( -name *.c -o -name *.h \) -not -path "*/ext/*" -not -path "*/build/*" -exec clang-format -style=file --dry-run --Werror {} +
find . \( -name CMakeLists.txt -o -name *.cmake \) -not -path "*/ext/*" -not -path "*/build/*" -exec cmake-format --check {} +
- name: upload binaries
uses: actions/upload-artifact@v3
with:
name: binaries
path: build/bin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论