【问题标题】:Upload Multiple (Parallel) Files to a Single Release将多个(并行)文件上传到单个版本
【发布时间】:2021-09-18 19:52:24
【问题描述】:

我对 github 操作很陌生。我已经设法使用 CMAKE 为 ubuntu-latest 和 windows-latest 构建了我的 C++ 程序,现在我在将其上传到版本时遇到了问题。 我使用的是策略矩阵,因此不同的操作系统作业并行运行。

我的目标是将构建文件上传到单个发布标签,其中每个文件都有一个基于操作系统平台的自定义名称。

例如:

Release Tag: V0.2.0
      Files: main_0.2.0_windows.exe
             main_0.2.0_ubuntu
                      ...
             main_0.2.0_other-OS.ext

有人可以帮我这样做吗?以下是我当前的工作流程 yml。

** 我已经设法将单个文件上传到 ubuntu-latest 的单个发布标签。对于 windows-latest,我收到一条错误消息,提示找不到要上传的文件 :( .

name: CMake

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]
  workflow_dispatch:
    inputs:
      trigger:
        required: false
        default: 'workflow_dispatcher'
  
env:
  # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
  BUILD_TYPE: Release
  VERSION: 0.2.0

jobs:
  build:
    strategy:
      matrix:
        platform: [ ubuntu-latest, windows-latest ]
        python-version: ['2.7', '3.6']
  
    # The CMake configure and build commands are platform agnostic and should work equally
    # well on Windows or Mac.  You can convert this to a matrix build if you need
    # cross-platform coverage.
    # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
    runs-on: ${{ matrix.platform }}
    
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
      
    - name: Upgrade pip & setuptools
      run: python -m pip install --upgrade pip setuptools
      
    - name: Install matplotlib & numpy
      run: python -m pip install matplotlib numpy 
      
    - name: Copy numpy core to include folder
      run: python ${{github.workspace}}/cp-numpy-core.py
      
    - name: Configure CMake
      # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
      # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
      run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
      
    - name: Build
      # Build your program with the given configuration
      run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target main
      
    - name: Test
      working-directory: ${{github.workspace}}/build
      # Execute tests defined by the CMake configuration.  
      # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
      run: ctest -C ${{env.BUILD_TYPE}}
      
    - name: Rename Ubuntu Files
      if: ${{ matrix.platform == 'ubuntu-latest' }}
      run: mv ${{github.workspace}}/build/main ${{github.workspace}}/build/main_${{ env.VERSION }}_${{ matrix.platform }}_${{ matrix.python-version }}
    
    - name: Rename Windows Files
      if: ${{ matrix.platform == 'windows-latest' }}
      run: Ren "${{github.workspace}}\build\${{ env.BUILD_TYPE }}\main.exe" "${{github.workspace}}\build\${{ env.BUILD_TYPE }}\main_${{ env.VERSION }}_${{ matrix.platform }}_${{ matrix.python-version }}.exe"
      
    - name: Upload Artifacts
    - uses: "marvinpinto/action-automatic-releases@latest"
      with:
        repo_token: "${{ secrets.GITHUB_TOKEN }}"
        automatic_release_tag: "${{ env.BUILD_TYPE }}${{ env.VERSION }}/${{ matrix.platform }}/Python${{ matrix.python-version }}"
        prerelease: true
        title: "${{ env.BUILD_TYPE }} V${{ env.VERSION }} - OS: ${{ matrix.platform }} - Python: ${{ matrix.python-version }}"
        files: |
          ${{github.workspace}}/build/main_${{ env.VERSION }}_${{ matrix.platform }}_${{ matrix.python-version }}
          ${{github.workspace}}\build\${{ env.BUILD_TYPE }}\main_${{ env.VERSION }}_${{ matrix.platform }}_${{ matrix.python-version }}.exe

最好的问候并继续编码!

【问题讨论】:

    标签: github cmake github-actions


    【解决方案1】:

    已通过使用 svenstaro/upload-release-action@2.2.1 解决,这使我可以将资产上传到版本。唯一的缺点是我必须为 windows 和 ubuntu 实现不同的步骤。

    工作流程操作:

    name: Build and Publish Pre Release
    
    on:
      push:
        branches: [ master ]
      workflow_dispatch:
        inputs:
          trigger:
            required: false
            default: 'workflow_dispatcher'
      
    env:
      # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
      BUILD_TYPE: Release
      
    jobs:
      build-source:
        # Environment where to build
        strategy:
          matrix:
            platform: [ ubuntu-latest, windows-latest ]
            python-version: ['2.7', '3.6', '3.7', '3.8', '3.9' ]
        
        # The CMake configure and build commands are platform agnostic and should work equally
        # well on Windows or Mac.  You can convert this to a matrix build if you need
        # cross-platform coverage.
        # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
        runs-on: ${{ matrix.platform }}
        
        steps:    
        - uses: actions/checkout@v2
        - uses: actions/setup-python@v2
          with:
            python-version: ${{ matrix.python-version }}
          
        - name: Upgrade Pip & Setuptools
          run: python -m pip install --upgrade pip setuptools
          
        - name: Install Matplotlib & Numpy
          run: python -m pip install matplotlib numpy 
          
        - name: Copy Numpy Core to Include Folder
          run: python ${{github.workspace}}/cp-numpy-core.py
          
        - name: Configure CMake
          # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
          # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
          run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
          
        - name: Build Source
          # Build your program with the given configuration
          run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target main
          
        - name: Test Build
          working-directory: ${{github.workspace}}/build
          # Execute tests defined by the CMake configuration.  
          # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
          run: ctest -C ${{env.BUILD_TYPE}}
        
        - name: Upload Files to a GitHub Release (Ubuntu)
          if: ${{ matrix.platform == 'ubuntu-latest' }}
          uses: svenstaro/upload-release-action@2.2.1
          with:
            repo_token: ${{ secrets.GITHUB_TOKEN }}
            file: build/main
            asset_name: main-linux_amd64-python${{ matrix.python-version }}
            tag: latest
            overwrite: true
            prerelease: true
            body: "${{ env.BUILD_TYPE }} for ${{ matrix.platform }}"
    
        - name: Upload Files to a GitHub Release (Windows)
          if: ${{ matrix.platform == 'windows-latest' }}
          uses: svenstaro/upload-release-action@2.2.1
          with:
            repo_token: ${{ secrets.GITHUB_TOKEN }}
            file: build\${{ env.BUILD_TYPE }}\main.exe
            asset_name: main-windows_amd64-python${{ matrix.python-version }}.exe
            tag: latest
            overwrite: true
            prerelease: true
            body: "${{ env.BUILD_TYPE }} for ${{ matrix.platform }}"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-17
      • 2011-02-02
      • 2012-01-01
      • 1970-01-01
      • 2012-10-27
      • 2013-08-28
      • 1970-01-01
      • 2014-11-07
      相关资源
      最近更新 更多