marian.vladoi
marian.vladoi

Reputation: 8066

Trigger GitHub workflow only on the release/tag event AND specific path

I am deploying 3 GCP cloud functions and 3 GCP cloud run services using GitHub Actions. At the moment, when I run a release, all the resources are deployed to the cloud.

on:
  release:
    types:
      - released

Assuming that I make some code changes only for a specific cloud function, I would like to avoid redeploying the entire infrastructure.

Is it possible on release/tag to trigger only the workflow for that specific function code update filtered on the path?

Can I trigger GitHub workflow only on the release/tag event AND specific path?

Something like this:

name: ABC
on:
  release:
    branches:
      - master
    paths:
      - my-directory/**

Upvotes: 1

Views: 1764

Answers (1)

Grzegorz Krukowski
Grzegorz Krukowski

Reputation: 19802

You cannot do it in workflow definitions and you cannot prevent workflow from running straight away.

But you can filter out events on first steps on your workflow and you can return from it early in firsts steps.

When workflow will be triggered from release, you can access payload in your steps using:

${{ github.event.release }}

You get access to release object

This will allow you do for example things like:

jobs:
  runForMasterBranch:
    name: Run for master branch only
    if: github.event.release.target_commitish == 'master'
    runs-on: ubuntu-latest
    steps:
      - name: Do something
        run: echo "Master release ${{ github.event.release.name }}"

As for changed files I am not sure about what you would like to achieve there, but if you want to check all files changed between latest release and current one, you can use this action: https://github.com/marketplace/actions/get-all-changed-files

Then you have to find a previous release SHA and find a diff between them using this action.

Upvotes: 2

Related Questions