首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将多个(并行)文件上载到单个版本

将多个(并行)文件上载到单个版本
EN

Stack Overflow用户
提问于 2021-07-08 18:40:10
回答 1查看 52关注 0票数 0

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

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

示例:

代码语言:javascript
复制
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,我收到一个错误,说没有找到要上载的文件:( .

代码语言:javascript
复制
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

致以最好的敬意&继续编码!

EN

回答 1

Stack Overflow用户

发布于 2021-07-09 22:30:42

通过使用svenstaro/upload-release-action@2.2.1解决了这一问题,这允许我将资产上传到版本。唯一的缺点是我不得不为windows和ubuntu实现一个不同的步骤。

工作流操作:

代码语言:javascript
复制
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 }}"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68300066

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档