Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Ground Controller Lvl 1
Message 11 of 29

Re: GitHub Actions Manual Trigger / Approvals

I'm surprised this wasn't included with the initial offering. I imagine a lot of people will want to follow the same track in using Actions for deployment. I'm trying to figure out a nicer alternative for the time being, but this would be a useful and much needed addition.

Highlighted
Ground Controller Lvl 1
Message 12 of 29

Re: GitHub Actions Manual Trigger / Approvals

I was really surprised when I found out there was no way to trigger an action manually from the repo.

Coming from GitLab's CI, this is an important feature for us. We find it cumbersome to use an API to trigger our deployments.

 

I hope this feature is gonna make it in the initial release of GitHub actions.

Pilot Lvl 2
Message 13 of 29

Re: GitHub Actions Manual Trigger / Approvals

There should be a button for this in the interface, yes. In the meantime you should be able to trigger a build manually by sending a Repository Dispatch Event to the GitHub API. If you use something like PostMan you can save a request that does that, or simply create a small curl script that you can run from your machine.

 

You can then attach your workflow to the `repository_dispatch` event to have it triggered when you POST to the API:

 

on: repository_dispatch

jobs:
  manual_deploy:
    steps:
      - name: Checkout master
        uses: actions/checkout@v1
        with:
          ref: master
      - <and so on>

It's not ideal, but it should allow you to trigger manual builds until official support is added to the UI.

Pilot Lvl 1
Message 14 of 29

Re: GitHub Actions Manual Trigger / Approvals

Deployment as been mentioned above.

If you are doing a deployment, do not use repository_dispatch. GitHub has first class support for deployment workflows:

https://developer.github.com/v3/repos/deployments/

Trigger a deployment via the API (we have internal tooling to ease this)

 

curl POST -H "Authorization: token $GITHUB_TOKEN" \
          -H "Accept: application/vnd.github.ant-man-preview+json"  \
          -H "Content-Type: application/json" \
          https://api.github.com/repos/org/repo/deployments \
          --data '{"ref": "master", "environment": "production"}'

 

Then have a workflow to do your deployment:

 

name: 'Deploy'
on: ['deployment']

jobs:
  deployment:

    runs-on: 'ubuntu-latest'

    steps:
    - name: 'Checkout'
      uses: 'actions/checkout@v1'

    - name: 'Deployment pending'
      uses: 'deliverybot/status@master'
      with:
        state: 'pending'
        token: '${{ secrets.GITHUB_TOKEN }}'

# do your deployment here, using whatever tooling you like:
- name: 'Deploy ${{ github.event.deployment.environment }}' run: | echo "task - ${{ github.event.deployment.task }}" echo "environment - ${{ github.event.deployment.environment }}" echo "payload - ${{ toJson(github.event.deployment.payload) }}" - name: 'deployment success' if: success() uses: 'deliverybot/status@master' with: state: 'success' token: '${{ secrets.GITHUB_TOKEN }}' - name: 'deployment failure' if: failure() uses: 'deliverybot/status@master' with: state: 'failure' token: '${{ secrets.GITHUB_TOKEN }}' 

 

Ground Controller Lvl 1
Message 15 of 29

Re: GitHub Actions Manual Trigger / Approvals

Minor: The curl command looks like this. You need to pass an empty array to required_contexts or create a status for a commit sha. 

 

curl \
-X POST \
-H "Authorization: token $GIT_PERSONAL_ACCESS_TOKEN" \
-H "Accept: application/vnd.github.ant-man-preview+json" \
-H "Content-Type: application/json" \
https://api.github.com/repos/bqh-kaiserhl/all/deployments \
--data '{"ref": "master", "required_contexts": [], "environment": "production"}'

 

Copilot Lvl 2
Message 16 of 29

Re: GitHub Actions Manual Trigger / Approvals

As mentioned in https://github.community/t5/GitHub-Actions/repository-dispatch-not-triggering-actions/m-p/33845/high..., `repository_dispatch` will only trigger on default (master) branch.

Copilot Lvl 3
Message 17 of 29

Re: GitHub Actions Manual Trigger / Approvals

As someone trying to move from Azure DevOps Pipelines to GitHub actions, having no manual triggers/approvers is a step back 🙁 Hope to see this feature added very soon.

Pilot Lvl 2
Message 18 of 29

Re: GitHub Actions Manual Trigger / Approvals


@SeanFeldman wrote:

having no manual triggers/approvers is a step back


 

You can have manual approvers if you have a workflow that is attached to the issue_comment type.

For example, the following workflow would run whenever someone would comment "OK to test" in a PR (which is internally seen as a type of issue by GitHub):

 

name: Run on demand

on:
  issue_comment:
    types: [created, edited]

jobs:
  ondemand:
    runs-on: ubuntu-latest
    if: github.event.comment.body == 'OK to test'
    
    steps:
      - name: Hello world
        run: echo Hello world, I was run on demand by ${GITHUB_ACTOR}

Additionally, you can also restrict which users are allowed to trigger a workflow this way, by doing checks against the github.event.comment.user.login variable or the GITHUB_ACTOR environment variable.

Copilot Lvl 3
Message 19 of 29

Re: GitHub Actions Manual Trigger / Approvals

does this still work for you? i've attempted to use this solution and my workflows are not being triggered by posting a comment anywhere - issue or PR, even while not including the "conditional" statement

 

e.g.:

name: deploy_to_channel_on_demand

on:
  pull_request_review_comment:
    types: [created, edited]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: logging
        run: echo "$GITHUB_REF"
Pilot Lvl 1
Message 20 of 29

Re: GitHub Actions Manual Trigger / Approvals

Hi @uladkasach , you have to use issue_comment for posting a Pull Request comment instead of using pull_request_review_comment to trigger the workflow when there is a pull request comment. 

name: deploy_to_channel_on_demand

on:
  issue_comment:
    types: [created, edited]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: logging
        run: echo "$GITHUB_REF"