I have a workflow which I want to run as a schedule job. But its also run based on another workflow is success or not. As now its not running as schedule but it works if the other workflow is success.
My workflow:
name: Security
on:
workflow_run:
workflows: ["My other workflow"]
types:
- completed
schedule:
- cron: '0 3 * * *'
env:
IMAGE: ghcr.io/${{ github.repository }}:${{ github.sha }}
GITHUB_USERNAME: x-access-token
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
jobs:
app-dependencies-vulnerabilities:
name: Scan for vulnerability
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Running snyk
uses: snyk/actions/gradle@master
with:
command: monitor
args: --org=myorg --project-name=${{ github.repository }} --remote-repo-url=https://github.com/${{ github.repository }}.git
json: true
I think this workflow is not running as excepted schedule job because I have this conditon? if: github.event.workflow_run.conclusion == 'success'
, am I right? How can I make it run as schedule AND based on the other workflow is success or not?
Thank you!
Your assumption is correct. To check if your workflow is being triggered via a cron job (scheduled event), you may do:
if: ${{ github.event_name == 'schedule' }}
In your case, your if condition should look:
if: ${{ (github.event.workflow_run.conclusion == 'success') || (github.event_name == 'schedule') }}