How to upload release assets from multiple OSes into one release?

I am using CMake to build OS-specific builds for my (test) software. I already have an action deployed that activates on push. It uses Get CMake and other related actions to accomplish this.

Now I want to take it to the next step: use the builds generated using CMake and upload them as assets for a release. This is the attempt I made. While it does upload the executables, it seems to be creating a release for every OS. I want one release for all OSes.

I find the syntax to be a bit daunting. I wonder if there is a simple way to have “nested” steps. Or if it’s even possible to upload once.

Let me know if more details are required; I’ll be happy to provide them.

The build job is executed for every OS, including the creation of a GitHub release. You should only create the release once, and then let each build job upload the release assets to the same release. Maybe like this:

name: Create Release Builds

on:
  push:
    tags:
      - "v*" # matches v1.0.1, v1.2, v2, etc

jobs:
  once:
    name: Create GitHub release
    runs-on: ubuntu-latest
    outputs:
      upload_url: ${{ steps.create_release.outputs.upload_url }}
    steps:
      - name: Create a release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: Release ${{ github.ref }}
          draft: true
          prerelease: true

  build:
    name: Create cross-platform release build, tag and upload binaries
    needs: once
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - uses: actions/checkout@v1
        with:
          submodules: true

      - name: Install latest CMake
        uses: lukka/get-cmake@latest

      - name: Run CMake (generation and build)
        uses: lukka/run-cmake@v2
        with:
          cmakeListsOrSettingsJson: "CMakeListsTxtBasic"
          cmakeBuildType: Release
          buildDirectory: "${{ github.workspace }}/${{ matrix.os }}"

      - name: Upload Release Asset
        id: upload-release-asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ needs.once.outputs.upload_url }}
          asset_path: ${{ github.workspace }}/${{ matrix.os }}/xtest
          asset_name: xtest-${{ matrix.os }}
          asset_content_type: application/octet-stream
1 Like

Thank you @Simran-B! I got it to work. Here’s the updated config.

1 Like