How do I prevent a given GitHub Workflow from being launched twice from two almost simultaneous events?

I have a repo, in which there is one folder at the root with a Makefile to build a C library. In the same repo, there is another folder at the root with a folder with another Makefile for building a node C addon via Node-API, and a small JS/TS API using said addon. The NAPI addon is dependent on the C library.

I have a workflow file for the C which runs when there is a commit on the C folder, and runs with any push or PR. I have another workflow file that runs when there is a commit+push/PR to the JS/TS folder, OR when the C workflow has completed successfully.

My goal is (of course) to only have the minimal amount of workflows run, depending on “how high in the stack the commits were”. If commits touch only the C, I want both the C and NAPI addon to be checked. If commits touch only the NAPI addon, I want only the NAPI addon to be checked. If commits touch both the C and NAPI addon, I want both the C and NAPI to be checked; but for NAPI to only be checked once.

For now, when the commits touch both the C and NAPI addon, the CI for the NAPI addon is launched twice: once for the commits affecting the NAPI folder, once for the successful completion of the C workflow.

How do I fix this ?

NB: I’ve tried using fkirc/skip-duplicate-actions@master, but it didn’t do the job.

NB: I first asked this question here: How do I prevent a given GitHub Workflow from being launched twice from two almost simultaneous events? - DevOps Stack Exchange
But didn’t receive any reply.

Can you share the workflow? It’s hard to guess what the options are without a look at how your CI is implemented. Why is the CI started twice, for C and NAPI, for instance?

Hey @Simran-B, thanks for the reply

Here’s the event launcher (on) for the workflow for the NAPI addon. Note that the C is referred to as “C client” and the NAPI addon is referred to as “TypeScript binding”.

Long story short, it’s launched once because of the push to the relevant directory; and once because of the success of the C client CI.

name: CI_TS_Binding

on:
  workflow_run:
    workflows: ["CI_C_Client"]
    branches: [master]
    types:
      - completed
  push:
    branches: [master]
    paths:
      - 'TypeScript_binding/**'
      - '!C_client/**'
      - '.github/workflows/ci_ts_binding.yml'
  pull_request:
    branches: [master]
    paths:
      - 'TypeScript_binding/**'
      - '!C_client/**'
      - '.github/workflows/ci_ts_binding.yml'

I also add the following condition to only run the NAPI/TS CI when the C_client workflow is completed successfully, and not when it fails. This line works as expected.

if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }} && ${{ github.event.workflow_run.conclusion == 'success'}}