Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 2

Is it possible to trigger a single workflow in GitHub Actions from two different events?

I have a GitHub Actions workflow that builds a static site. My content is hosted on Contentful. I would like to rebuild my static site on a normal repository push event, and also via the Contentful webhook whenever my content is updated. It seems like the best way to do this is to trigger a RepositoryDispatch event.

 

curl "https://api.github.com/repos/LandonSchropp/landonschropp.com/dispatches" \
  -X POST \
  --silent \
  --show-error \
  --fail \
  -H "Accept: application/vnd.github.everest-preview+json"  \
  -H "Content-Type: application/json" \
  -u "$GITHUB_USERNAME:$GITHUB_TOKEN" \
  --data '{"event_type": "build"}'

 

As far as I can tell, it's pretty easy to run multiple actions after an event in parallel, but I'm not sure how I can trigger a workflow with two separate events. I what I'm trying to do possible? If so, how can I manage it?

 

workflow "Main" {
  on = "push"
  resolves = ["Publish"]
}

action "Install" {
  uses = "docker://node:11"
  runs = "yarn"
  args = "install"
}

action "Lint" {
  needs = "Install"
  uses = "docker://node:11"
  runs = "yarn"
  args = "lint"
}

action "Master" {
  needs = "Lint"
  uses = "actions/bin/filter@master"
  args = "branch master"
}

action "Download Content" {
  needs = "Master"
  uses = "docker://node:11"
  runs = "yarn"
  args = "download-content"
  secrets = [
    "CONTENTFUL_SPACE_ID",
    "CONTENTFUL_ACCESS_TOKEN",
  ]
}

action "Build" {
  needs = "Download Content"
  uses = "docker://node:11"
  runs = "yarn"
  args = "build"
  env = {
    NODE_ENV = "production"
    PORT = "80"
    URL = "https://landonschropp.com"
  }
}

action "Validate HTML" {
  needs = "Build"
  uses = "docker://ruby"
  runs = "bin/validate-html"
}

action "Publish" {
  needs = "Validate HTML"
  uses = "maxheld83/ghpages@v0.2.1"
  env = {
    BUILD_DIR = "build"
  }
  secrets = ["GITHUB_TOKEN"]
}
1 Reply
Community Manager
Message 2 of 2

Re: Is it possible to trigger a single workflow in GitHub Actions from two different events?

Hi @LandonSchropp,

 

Thanks for being here and our apologies for the delayed response. You should be able to accomplish triggering a workflow with two separate events via: 

# Triggered by an issue comment on GitHub
workflow "One" {
  on = "issue_comment"
  resolves = ["Do The Thing"]
}

# Triggered by an issue being created on GitHub
workflow "Two" {
  on = "issues"
  resolves = ["Do The Thing"]
}

action "Some Other Thing" {
  uses = "user/another-action@master"
}

action "Do The Thing" {
  uses = "user/action@master"
  needs = ["Some Other Thing"]
}

  


Best,
AndreaG

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!