Skip to content

Make action more composable #181

@20k-ultra

Description

@20k-ultra

The goal of this action was to use draft releases but that requires this action only run on specific events. If we make the action more composable, people can use it for more workflows (events) than just push to master and pull requests.

The following is a solution that should allow people to make workflows that push final releases on any event and still allow you to make draft releases than finalize on another event...right now this is hard coded to only work on pull requests but below I outline how we can do it with any event.

By adding a new input finalize: boolean and not enforcing which events cause the action to finalize the user can craft a workflow to make a draft and than finalize on any combination of events. You can make a workflow file to:

  • push to master -> make a finalized release
  • tag commit -> make a finalized release
  • workflow_dispatch -> make a finalized release
  • open/sync PR -> make a draft release
    • push to master -> finalize the draft release built
  • push to master -> make a draft release
    • tag commit -> finalize the draft release built

Using expressions in your workflow, you can run the action with finalize: false if event.type == pr_opened or event.type == pr_sync. Than, have another step that only runs on merge to master with finalize: true. This works because when building a finalized release, the action already checks if it exists. If it finds a draft release it would just mark as final. If it found a finalized release than nothing happens. Else, new final release is built.

Here is an example workflow file that would mimic the draft PR workflow we want to keep:

on:
 pull_request:
    types: [opened, synchronize]
    branches:
      - master
 push:
    branches:
      - master

jobs:
  balena_cloud_build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: balena-io/deploy-to-balena-action@master
        if: ${{ github.event_name == 'pull_request' }}
        id: draft 
        with:
          balena_token: ${{ secrets.BALENA_TOKEN }}
          fleet: my_org/sample_fleet
          finalize: false
      - uses: balena-io/deploy-to-balena-action@master
        if: ${{ github.event_name == 'push' }}
        id: finalize
        with:
          balena_token: ${{ secrets.BALENA_TOKEN }}
          fleet: my_org/sample_fleet
          finalize: true

To just build a final release on push to master remove the expressions and put finalize: true. Swap the events for push to master and tag commit if you want to make releases on those events as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions