Khan/pull-request-comment-trigger

Alternative workflow in yaml without dependancies.

Opened this issue · 1 comments

Thank you for the inspiration.

I have written raw workflow without external dependencies in yaml.

https://github.com/kuvaldini/actions-trigger-when-pr-commented

name: on-pr-comment

on:
  push:
  pull_request:
  issue_comment:
    types: [created]
  workflow_dispatch:

jobs:
  rocket:
    ## Just to react to valid comment with rocket
    runs-on: ubuntu-latest
    if: ${{ github.event.comment &&
          github.event.issue.pull_request &&
          startsWith(github.event.comment.body, '/buildme') }}
    steps:
      - 
        name: Reaction
        run: |
          # send reaction to comment to show build was triggered
          curl ${{github.event.comment.url}}/reactions \
            -X POST \
            -d '{"content":"rocket"}' \
            -H "Accept: application/vnd.github.squirrel-girl-preview+json" \
            -H "Authorization: token ${{github.token}}"

  build:
    runs-on: ubuntu-latest
    ## Run on each event, but PR comment is checked for key phrase.
    if: ${{ github.event_name != 'issue_comment' ||
            ( github.event.issue.pull_request &&
            startsWith(github.event.comment.body, '/buildme') ) }}
    steps:
      - #&step_detect_commented_pr
        name: REF and SHA of commented PR to ENV
        if: github.event.comment
        run: >
            curl -fsSL ${{github.event.issue.pull_request.url}}
            -H "Authorization: token ${{github.token}}" |
            jq -r '
              "PR_REF="+.head.ref, 
              "PR_SHA="+.head.sha, 
              "PR_NUM="+(.number|tostring), 
              "PR_REPO="+.head.repo.full_name' >>$GITHUB_ENV
      - #&step_checkout
        name: Checkout
        uses: actions/checkout@v2
        with:
          ref:        ${{env.PR_REF}}  ## not empty on issue_comment, else default value GITHUB_REF
          repository: ${{env.PR_REPO}} ## not empty on issue_comment, else default value github.repository, required by forks

@kuvaldini Note that your job level if statements avoid round up minute pricing at the runner level, thank you very much