Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Upload to a release created in a different job #56

Open
monocasual opened this issue Jul 22, 2020 · 2 comments
Open

Upload to a release created in a different job #56

monocasual opened this issue Jul 22, 2020 · 2 comments

Comments

@monocasual
Copy link

monocasual commented Jul 22, 2020

I'm setting up a CI environment for a C++ application on three different platforms - Linux, macOS and Windows. My idea is the following:

  1. job A creates a release (with actions/create-release) once;
  2. jobs B, C and D build the app each platform and then upload the three binaries as release assets (one asset per platform).

Is there a way to pass the upload_url variable from job A to the other three jobs? The example in the README file only shows how to do that across steps in the same job.

@infalmo
Copy link

infalmo commented Jul 28, 2020

Here's what I did:

name: Release (checkers)

on:
  push:
    tags:
    - 'v*'

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

  job2:
    name: Build
    needs: job1
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os:
          - windows-latest
          - ubuntu-latest
          - macOS-latest
    steps:
      - uses: actions/checkout@v2
      - name: make all
        run: |
          cd checkers
          mkdir build
          make all
      
      - name: Create tarball
        uses: master-atul/tar-action@v1.0.2
        run: |
          cd checkers/build
          tar -czvf ${{ matrix.os }}.tar.gz *
      
      - name: Upload assets
        id: upload-release-asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ needs.job1.outputs.upload_url }}
          asset_path: checkers/build/${{ matrix.os }}.tar.gz
          asset_name: ${{ matrix.os }}.tar.gz
          asset_content_type: application/gzip

@leafac
Copy link

leafac commented Jan 30, 2021

And here’s my version:

Configuration: https://github.com/courselore/courselore/blob/6e1311a852360475714614fa67b94cc4bf38bb1a/.github/workflows/main.yml
Example release: https://github.com/courselore/courselore/releases/tag/v0.0.5

It’s similar, but it fixes some small issues that I ran into, for example, the following didn’t work for me:

- name: Create tarball
  uses: master-atul/tar-action@v1.0.2
  run: |
    cd checkers/build
    tar -czvf ${{ matrix.os }}.tar.gz *

First, GitHub complained that a step can’t have both uses and run. But even if you separate it in two steps, tar -czvf ${{ matrix.os }}.tar.gz * didn’t work for me on Windows; it complained about file permissions.

In any case, thanks @infinitepr0 for getting me very close to the solution.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants