Trying to work out why action is triggered three times for release?

I am trying to put together an action to create artefacts to attach to a new release, but I am running into an issue. If I create a new release in the GitHub UI of the form ‘v3.1.5’, then I find the action is fired off three times, but I am not sure why. Can anyone tell me what I am doing wrong:

on:
  release:
    type: [created]
    # Sequence of patterns matched against refs/tags
    tags:
    - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Upload Release Asset

jobs:
  release:
    name: Upload Release Asset
    runs-on: macos-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v1
      - name: Get dependencies
        run: git submodule update --init --recursive
      - name: Build the project
        run: xcodebuild -derivedDataPath ./build -workspace Boxer.xcworkspace -scheme "Boxer CI" -configuration "Release"
      - name: Package the release artefacts
        run: |
          hdiutil create -volname Boxer -srcfolder build/Build/Products/Release/Boxer.app -ov -format UDZO Boxer.dmg
      - name: Create 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: false
          prerelease: false
      - name: Upload Release Asset
        id: upload-release-asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
          asset_path: ./Boxer.dmg
          asset_name: Boxer.dmg
          asset_content_type: application/x-apple-diskimage

Well two makes sense, not sure about the third, likely a chain reaction that some Github Actions control is stopping.

Your workflow triggers on Release creation but then creates a release itself via actions/create-release@v1.

I hadn’t noticed that. I have changed that code block in mine.

A closer look shows that three are triggered by ‘published’, ‘prereleased’ and ‘created’. I would have thought the ‘type’ field above would have limited the condition to ‘created’ only?

My config is here: https://github.com/ajmas/Boxer/tree/worflow-test

Update: it turns out it was a question of ‘type’ vs ‘types’.

1 Like

Is this action supposed to be fired when both a release event is created and the tag starts with ‘v’?

I use the same syntax in my script, but it is triggered regardless of the tag name.

The release event doesn’t support filtering by tag name according to the docs. Only push and pull_request do:
on.<push|pull_request>.<branches|tags>

The correct name for the event filter is types:
on.<event_name>.types
If you specify type instead, then it’s simply ignored and all default event types will trigger the workflow.