github动作:如何自动化标签构建工件?

发布于 2025-02-10 20:17:49 字数 1428 浏览 0 评论 0原文

我目前有以下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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文