Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Alternative workflow in yaml without dependancies. #13

Open
kuvaldini opened this issue May 22, 2021 · 1 comment
Open

Alternative workflow in yaml without dependancies. #13

kuvaldini opened this issue May 22, 2021 · 1 comment

Comments

@kuvaldini
Copy link

kuvaldini commented May 22, 2021

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
@tiny-dancer
Copy link

tiny-dancer commented Apr 26, 2022

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants