Coder Social home page Coder Social logo

github-action-manual-trigger-dispatch-another-workflow's Introduction

test-build

Step 1

Create a personal access token with repo and workflow permissions ready.

Step 2

Create a workflow with sample code below and add a file call index.js with console.log(main branch)

name: Build

on:
  repository_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: echo github actor
        run: echo ${{ github.actor }}

      - name: Checkout code
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.client_payload.branch || 'dev' }}

      - name: Run index.js
        run: node index.js
git add .
git commit -m "init"
git push origin main

Step 3

Create a branch call dev, then commit index.js to console.log(dev branch)

git add .
git commit -m "fix: dev"
git push origin dev

Step 4

Use curl to call dispatch action

## Example 1
curl --request POST \
  --url 'https://api.github.com/repos/ookangzheng/test-build/dispatches' \
  --header 'authorization: Bearer <PERSONAL_ACCESS_TOKEN>' \
  -d '{"event_type":"trigger", "client_payload": {"branch":"dev"}}'
  
## Example 2
curl -i -u <GITHUB_USERNAME>:<PERSONAL_ACCESS_TOKEN> --request POST \
  --url 'https://api.github.com/repos/ookangzheng/test-build/dispatches' \
  -d '{"event_type":"trigger", "client_payload": {"branch":"dev"}}'

References

  1. https://dev.to/rikurouvila/how-to-trigger-a-github-action-with-an-htt-request-545
  2. https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#repository_dispatch
  3. https://github.community/t/how-to-trigger-repository-dispatch-event-for-non-default-branch/14470/10
  4. https://github.com/actions-packages-examples/branch-builds
  5. https://dev.to/rikurouvila/how-to-trigger-a-github-action-with-an-htt-request-545
  6. https://github.com/octokit/request-action
  7. https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#workflow_dispatch
  8. https://github.com/peter-evans/repository-dispatch
  9. https://dev.to/s_abderemane/manual-trigger-with-github-actions-279e
  10. https://github.com/marketplace/actions/auto-approve

github-action-manual-trigger-dispatch-another-workflow's People

Contributors

zoonderkins avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.