Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to prevent creating multiple releases when using a build matrix? #14

Open
nukeop opened this issue Oct 30, 2019 · 5 comments
Open

How to prevent creating multiple releases when using a build matrix? #14

nukeop opened this issue Oct 30, 2019 · 5 comments

Comments

@nukeop
Copy link

@nukeop nukeop commented Oct 30, 2019

I have a matrix which results in 3 builds. Is there a way to ensure only the first one will draft a new release?

@kf6kjg

This comment has been minimized.

Copy link

@kf6kjg kf6kjg commented Nov 15, 2019

There does not appear to be. And yes, it's quite annoying to clean up afterwards.

In my case I'm not using a matrix, I'm instead using one job per OS - this is because each OS requires a fair amount of unique operations. I'd still like it to somehow detect that there was a pre-existing release or draft for that tag and name and skip.

However I'm torn between two ways this could be done:

  1. That the behavior be changed to skip the creation if it finds a match for both the given release name AND that exactly one of the release(s) thus found has the same tag. When skipping it should still determine and set the upload_url and any related outputs, thus allowing any downstream steps to proceed normally.
  2. That an option be added, such as allow_duplicates, which if true would behave as it currently does otherwise it would proceed as in the above. I'd rather the default state of this new option be false, but I'd understand if the maintainers would rather it be set true to keep the default behavior unchanged.
@nogic1008

This comment has been minimized.

Copy link

@nogic1008 nogic1008 commented Nov 19, 2019

Split "Create Release" job and "Build" job, and use upload-artifact and download-artifact to transfer URL.

  release:
    name: Create Github Release
    if: contains(github.ref, 'tags/v')
    needs: [test]
    runs-on: ubuntu-latest
    steps:
    - name: Create Release
      id: create_release
      uses: actions/create-release@v1.0.0
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ github.ref }}
        release_name: Release ${{ github.ref }}
        draft: false
        prerelease: false
    - name: Output Release URL File
      run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt
    - name: Save Release URL File for publish
      uses: actions/upload-artifact@v1
      with:
        name: release_url
        path: release_url.txt
    
  publish:
    if: contains(github.ref, 'tags/v')
    needs: [test, release]
    runs-on: ubuntu-latest
    strategy:
      matrix:
        version: [foo, bar, baz]
    steps:
    - uses: actions/checkout@v1
    - name: Load Release URL File from release job
      uses: actions/download-artifact@v1
      with:
        name: release_url
    - name: Build
      run: BUILD_COMMAND --version ${{ matrix.version }} --output ./${{ matrix.version }}
        zip -r ${{ matrix.version }} ./${{ matrix.version }}
    - name: Get Release File Name & Upload URL
      id: get_release_info
      run: |
        echo ::set-output name=file_name::${REPOSITORY_NAME##*/}-${TAG_REF_NAME##*/v} # RepositoryName-v1.0.0
        value=`cat release_url/release_url.txt`
        echo ::set-output name=upload_url::$value
      env:
        TAG_REF_NAME: ${{ github.ref }}
        REPOSITORY_NAME: ${{ github.repository }}
    - name: Upload Release Asset
      id: upload-release-asset 
      uses: actions/upload-release-asset@v1.0.1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.get_release_info.outputs.upload_url }}
        asset_path: ./${{ matrix.rid }}.zip
        asset_name: ${{ steps.get_release_info.outputs.file_name }}-${{ matrix.rid }}.zip
        asset_content_type: application/zip
@kf6kjg

This comment has been minimized.

Copy link

@kf6kjg kf6kjg commented Nov 19, 2019

I prefer to have the release created only if at least one of the builds succeeded. In fact I'd prefer that it only happened if all builds succeeded. But that's my preferred workflow and there might be a way to do it using a split build process like that, but these are workarounds that add additional time and load - but at least there are workarounds. Thank you @nogic1008 for the inspiration.

@nathanielatom

This comment has been minimized.

Copy link

@nathanielatom nathanielatom commented Nov 25, 2019

I have an alternative solution, that runs in a single (defined) job, which has worked well for me. The idea is to use an extra matrix variable on the build you want to upload the release, and use conditionals for any steps that should only get run for an upload.

Code

jobs:
  build:
    name: python ${{ matrix.python }} and ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        python: [3.6, 3.7]
        os: [ubuntu-latest, macOS-latest, windows-latest]
        include: # define single matrix case that performs upload
          - os: ubuntu-latest
            python: 3.7
            upload: true
...
    steps:
...
      - name: build distribution tarball
        if: matrix.upload
        run: echo 42
      - name: create github release
        id: create_release
        if: matrix.upload && github.event_name == 'pull_request' && github.base_ref == 'master'
        uses: actions/create-release@master # @v1 has no body arg
...

References

@nathanielatom

This comment has been minimized.

Copy link

@nathanielatom nathanielatom commented Nov 25, 2019

Another alternative, if you don't have a preference for which matrix build triggers upload, is to skip the matrix include thing and use step conditionals like if: strategy.job-index == 0; although I haven't tested this myself.

https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#contexts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.