Skip to content

Instantly share code, notes, and snippets.

@justinsantoro
Last active May 9, 2020 16:57
Show Gist options
  • Save justinsantoro/65ab611a625c222017bd259693172d10 to your computer and use it in GitHub Desktop.
Save justinsantoro/65ab611a625c222017bd259693172d10 to your computer and use it in GitHub Desktop.
Trigger github workflow on pattern match in newly opened issue title - with ACKs
name: issue title trigger
on:
# this workflow tests triggering a workflow via matching a pattern
# in a newly opened issue's title
# it then uses the github-script action to notify on the state
# of the workflow
issues:
types: [opened]
jobs:
#ack trigger and do stuff in parallel
Ack-doing-stuff:
runs-on: ubuntu-latest
if: startsWith(github.event.issue.title, '[/do-stuff]')
steps:
- name: Ack request
uses: actions/github-script@0.9.0
with:
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '🆗 doing stuff...⏳'
})
Do-stuff:
runs-on: ubuntu-latest
if: startsWith(github.event.issue.title, '[/do-stuff]')
steps:
- name: Do-stuff
run: |
echo doing stuff...
sleep 3
# if Do stuff is successful, the next step will not run
# and the job will be marked as a success
- name: Notify-failure
if: failure()
uses: actions/github-script@0.9.0
with:
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '💀 failed to do stuff'
})
Ack-Success:
runs-on: ubuntu-latest
# will only run if Do-stuff succeeds. Unless we add the conditional: if: always()
needs: Do-stuff
steps:
- name: Ack-success
uses: actions/github-script@0.9.0
with:
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '✔ did stuff successfully'
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment