question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug in IF conditions on inputs for reusable workflows

See original GitHub issue

Problem:

When a reusable workflow (called workflow), contains if conditions (based on the input of the job) at job level, there is a observation that the if condition seems to execute and use value globally (causing jobs which are being skipped because of a check).

Example

Caller workflow: Simple workflow calling a reusable workflow passing in the github event (PR or push) to the reusable workflow

name: caller-workflow
on:
  pull_request:
  push:
    branches:
      - master
# 2
jobs:
  call-the-workflow:
    uses: action-foobar/action-testing/.github/workflows/called_workflow.yml@master
    with:
      TRIGGER_EVENT : ${{ github.event_name }}

Reusable workflow: Workflow with a sequence of job which has conditions based on the input (whether it is a pull_request or a push)

name: tf-app-dns-reusable

on:
  workflow_call:
    inputs:
      TRIGGER_EVENT:
        description: trigger event for the workflow
        required: true
        type: string

jobs:
  lint:
    runs-on: ubuntu-latest
    name: Validate terraform configuration

    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: debug
        run: |
          echo ${{ inputs.TRIGGER_EVENT }}
  plan-non-prod:
    if: ${{ inputs.TRIGGER_EVENT == 'pull_request' }}
    needs: lint
    runs-on: ubuntu-latest
    name: Plan Application DNS Non Prod
    steps:
      - name: debug
        run: |
          echo "triggered event"
          echo ${{ inputs.TRIGGER_EVENT }}
  plan-prod:
    if: ${{ inputs.TRIGGER_EVENT == 'pull_request' }}
    needs: "plan-non-prod"
    runs-on: ubuntu-latest
    name: Plan Application DNS Prod
    steps:
      - name: debug
        run: |
          echo "triggered event"
          echo ${{ inputs.TRIGGER_EVENT }}
  apply-non-prod:
    if: ${{ inputs.TRIGGER_EVENT == 'push' }}
    needs: lint
    runs-on: ubuntu-latest
    name: apply non prod
    steps:
      - name: debug
        run: |
          echo "triggered event"
          echo ${{ inputs.TRIGGER_EVENT }}

Observation

image

  • Job 3 gets the check skipped , even though the condition is valid and matches as Job 2 (Job 3 only depends on success of job 2 and the same IF condition as job2.

  • On removal of the IF condition on Job 4 , then Job 3 executes fine .

Which implies of some sort of “state” of the IF condition (since there is no relationship between Job 4 and Job 3).

The observation of runs can be found in this repository here -> https://github.com/action-foobar/action-testing/actions/runs/1682109402

PS:

This was working perfectly fine till 11PM GMT 10th Jan . (as we have a lot of jobs in our org on this setup)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:24
  • Comments:21

github_iconTop GitHub Comments

14reactions
thboopcommented, Jan 11, 2022

The root cause was a server side change we cannot quickly revert at this time, we are working on a fix that should rollout to all users over the next day or two.

Thank you everyone for your patience as we address this issue. This issue will be updated when the bug is fixed and rolled out to everyone.

13reactions
ericsciplecommented, Jan 12, 2022

👋 Hi folks, I’m sorry about this disruption.

The fix should finish rolling out in the next ~20 minutes. After that, all new runs going forward should work correctly.

Again, I’m sorry about the disruption. We’ll review this, and we’ll do better going forward.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to call a reusable workflow "conditionally" at the job ...
I'm seeing an issue where the "if: {{github.ref_type == 'tag'}}" is not being honored at the job level when the job calls into...
Read more >
Avoid Duplication! GitHub Actions Reusable Workflows
So, Reusable Workflows in GitHub Actions. ... Note: if a required input has not been passed to the reusable workflow, it will fail....
Read more >
7 Github Actions Tricks I Wish I Knew Before I Started
#1: How to Use Github Action Triggers; #2: Reusable Workflows with ... Another conditional can be to not trigger certain jobs for drafts...
Read more >
How to start using reusable workflows with GitHub Actions
Reusable workflows offer a simple and powerful way to avoid copying and pasting workflows across your repositories.
Read more >
Advanced GitHub Actions - Conditional Workflow - hungvu.tech
How can I create one GitHub workflow which uses different secrets based on a triggered branch? The conditional workflow will solve this problem....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found