如何将 Travis CI 工件发布到 GitHub 从几个工作中发布

How to publish Travis CI artifacts to GitHub Release from several jobs

我有三个 Travis CI 作业来为不同的操作系统构建我的应用程序。
每个操作系统都有一个单独的作业:OS X 代表 osx-x64,Linux 代表 linux-x64,Windows 代表 win-x64。

构建后,我得到了我的应用程序的一个文件,它位于路径 ImagePoster4DTF/ImagePoster4DTF/bin/Release/netcoreapp3.1/{win-x64,linux-x64,osx-x64}/publish/ImagePoster4DTF{.exe,}.

如何将来自不同作业的三个文件上传到一个 GitHub 版本?

我当前的 .travis.yml 文件不起作用:

language: csharp
mono: none
dotnet: 3.1.301

git:
  depth: 2
  quiet: true
  symlinks: true

script:
  - dotnet restore

jobs:
  include:
    - os: linux
      script: dotnet publish -r linux-x64 --configuration Release -p:PublishSingleFile=true
    - os: osx
      script: dotnet publish -r osx-x64 --configuration Release -p:PublishSingleFile=true
    - os: windows
      script: dotnet publish -r win-x64 --configuration Release -p:PublishSingleFile=true
    - stage: Publish GitHub release
      before_deploy:
        # Set up git user name and tag this commit
        - git config --local user.name "Artoria Pendragon"
        - git config --local user.email "saber-nyan@ya.ru"
        - export TRAVIS_TAG=${TRAVIS_TAG:-$(date +'%Y%m%d%H%M%S')-$(git log --format=%h -1)}
        - git tag $TRAVIS_TAG
      deploy:
        provider: releases
        api_key:
          secure: SOME_ENCRYPTED_KEY
        file_glob: true
        file: "ImagePoster4DTF/bin/Release/netcoreapp3.1/**/publish/*"
        skip_cleanup: true

似乎适用于此配置:

language: csharp
mono: none

branches:
  except:
    - /^untagged/
    - /^nightly/

git:
  depth: 2
  quiet: true
  symlinks: true

jobs:
  include:
    - stage: "Compile for amd64 Windows"
      os: windows
      script:
        - choco install dotnetcore-sdk
        - dotnet --version
        - dotnet restore
        - dotnet publish -r win-x64 --configuration Release -p:PublishSingleFile=true
      deploy: &deploy_base
        provider: releases
        api_key:
          secure: SOME_ENCRYPTED_KEY
        file: "ImagePoster4DTF/bin/Release/netcoreapp3.1/win-x64/publish/ImagePoster4DTF.exe"
        draft: true
        tag_name: $TRAVIS_TAG
        target_commitish: $TRAVIS_COMMIT
        name: $TRAVIS_TAG
        overwrite: true
        skip_cleanup: true
    - stage: "Compile for amd64 macOS"
      os: osx
      osx_image: xcode11.5
      dotnet: 3.1.301
      script:
        - dotnet restore
        - dotnet publish -r osx-x64 --configuration Release -p:PublishSingleFile=true
        - "cp ./ImagePoster4DTF/bin/Release/netcoreapp3.1/osx-x64/publish/ImagePoster4DTF ./ImagePoster4DTF_macOS"
      deploy:
        <<: *deploy_base
        file: "ImagePoster4DTF_macOS"
    - stage: "Compile for amd64 GNU/Linux and deploy GitHub Release"
      os: linux
      dist: bionic
      dotnet: 3.1.301
      script:
        - dotnet restore
        - dotnet publish -r linux-x64 --configuration Release -p:PublishSingleFile=true
        - "cp ./ImagePoster4DTF/bin/Release/netcoreapp3.1/linux-x64/publish/ImagePoster4DTF ./ImagePoster4DTF_linux"
      deploy:
        <<: *deploy_base
        draft: false
        file: "ImagePoster4DTF_linux"

before_deploy:
  - git config --local user.name "Artoria Pendragon"
  - git config --local user.email "saber-nyan@ya.ru"
  - export TRAVIS_TAG="nightly-$TRAVIS_BUILD_NUMBER"
  - echo "Tagging commit ${TRAVIS_COMMIT} with tag ${TRAVIS_TAG}"
  - git tag "$TRAVIS_TAG" "$TRAVIS_COMMIT"