Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Pilot Lvl 1
Message 11 of 19

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 }}' 

 

Highlighted
Ground Controller Lvl 1
Message 12 of 19

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 3
Message 13 of 19

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 14 of 19

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 15 of 19

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 16 of 19

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"

 

Copilot Lvl 3
Message 17 of 19

Re: GitHub Actions Manual Trigger / Approvals

Deliverybot (using github deployments) might be something that solves this issue. I let deliverybot automatically deploy to the staging server, check if everything is working and manually deploy to producting using deliverybot. 

Copilot Lvl 2
Message 18 of 19

Re: GitHub Actions Manual Trigger / Approvals

This definitely looks promising as a stop-gap, but I would love to see this as native GitHub functionality. Especially if DeliveryBot becomes a paid product once it is out of beta. I couldn't find any information on the beta / pricing status for DeliveryBot though.

 

However, it does look like this will meet our requirements for triggering deployments in the meantime. However, from what I can tell, the approval gate use case is still not covered by this tool.

Copilot Lvl 3
Message 19 of 19

Re: GitHub Actions Manual Trigger / Approvals

https://deliverybot.dev/docs/guide/6-promotion/
Documentation isn't great, it also doesn't work with caching yet, so I'm just using on: push again.