DEV Community

Manual trigger with Github Actions

Sarah Abd on January 28, 2020

Hi there, this blog post explains how to manually trigger builds of GitHub actions. Why would you want to do that? Instead of just wait...
Collapse
 
m157q profile image
M157q

GitHub has added workflow_dispatch event for manually trigger.
FYI: github.blog/changelog/2020-07-06-g...

Collapse
 
jefftriplett profile image
Jeff Triplett (he/him)

Another alternative is to add an event hook for the on: respository_dispatch event which should let you trigger builds. See the docs here: help.github.com/en/actions/automat...

Collapse
 
sabderemane profile image
Sarah Abd

Oh yes, thanks !
My solution use simplicity with the star button which already here and nothing to implement more than the workflow.
The repository_dispatch event has advantage to target other branch than master contrary to the watch event with the star.
Spot on.

Collapse
 
drewmullen profile image
drewmullen

thanks @jefftriplett i put together an easy example repo based on this: github.com/drewmullen/actions-play...

Collapse
 
neilime profile image
Emilien Escalle • Edited

Get a solution to allows to all repository collaborators:

jobs:

  authorize: 
    runs-on: ubuntu-latest

    steps:
    - uses: octokit/request-action@v2.0.0
      with:
        route: GET /repos/:repository/collaborators/${{ github.actor }}
        repository: ${{ github.repository }}
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  build:
    needs: [authorize]

    runs-on: ubuntu-latest

   steps: 
     - ...
Collapse
 
sabderemane profile image
Sarah Abd • Edited

Nice ! I add it on the post :)

Collapse
 
karfau profile image
Christian Bewernitz

Thx, even though I'll most likely not use the "star method", your article is a good reference collection regarding github action triggers.

Do you have a reference/example at hand how to write the condition to check if the stargazer is in the team of an org (or in a list of users?)

Collapse
 
sabderemane profile image
Sarah Abd • Edited

Thanks, my article hasn't vocation to deliver the best method and as I said, it's really hacky, but good to know and also there are other options.

I haven’t an example right now but you can easily do a step with the logic of checking if the user is part of a list of the users in the language you prefer.
Execute the file and save the result as variable and return a boolean if it's true or false. And the following steps will be conditioned according to the result.

Maybe this example can helps you :

name: Extract branch name
      id: extract_github
      run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"

In this case, in your workflow, you will be able to reuse the name of the branch if you want to do a step only on this branch :

if: steps.extract_github.outputs.branch == ’staging'
Collapse
 
abatilo profile image
Aaron Batilo • Edited

Hi all!

I'm hoping posting here won't be a problem.

I wanted to share a small project that I've been working on with a buddy that solves this problem.

actionspanel.app/

ActionsPanel uses this same repository_dispatch API but does so with a GitHub App token so that you don't need to worry about managing your own PAT. This also makes it much easier to trigger your actions across teams with multiple people. Then you don't need to share the PAT with each other or each create your own PATs.

You configure your buttons with a declarative yaml file that you leave in the repo, and ActionsPanel will read that file and dynamically create your UI for you to trigger your actions.

We'd love to get your feedback on this project. It's very simple still but solves the core problem of triggering your actions.

If you do have feedback or any questions, feel free to post in this thread, or email us directly at support (at) actionspanel (dot) app

Looking forward to your feedback!

Collapse
 
hugojgoncalves profile image
Hugo José Gonçalves

Is it open source?
Asking for repo write permissions from a closed source code project is a little too much for me.

Collapse
 
doggie52 profile image
Douglas Stridsberg

I needed to add : to the end of watch to get this to work.

on:
  watch:
    types: [started]

Did nobody actually try this code, or is there some stricter Action language interpretation on my end?

Collapse
 
sabderemane profile image
Sarah Abd • Edited

It was already tested by me because I add a gif demo of the watch event. GitHub Actions is based on yaml language. It's a typo, I update the article thanks.

Collapse
 
gautamkrishnar profile image
Gautam Krishna R

Looks good but it will spam your followers feed, if you have a large amount of followers right?

Collapse
 
sabderemane profile image
Sarah Abd • Edited

Good question, in fact no, because it's only notifying on discussions about :

  • Issues and their comments
  • Pull Requests and their comments
  • Comments on any commits

of the starred repository.

Further details just here :)