Skip to content

fix: add master and main branches as a fallback to base ref when the workflow triggered out of PRs scope#107

Merged
buger merged 2 commits into
mainfrom
fix/add-fallback-logic-to-git-baseref
Apr 6, 2026
Merged

fix: add master and main branches as a fallback to base ref when the workflow triggered out of PRs scope#107
buger merged 2 commits into
mainfrom
fix/add-fallback-logic-to-git-baseref

Conversation

@vladzabolotnyi

Copy link
Copy Markdown

Issue

When we run the workflow not on PRs the BASE_REF env variable becomes empty and fails the git fetch.
Example:
https://github.com/TykTechnologies/tyk-analytics-ui/actions/runs/23936302416/job/69813293630

By adding fallback we will resolve it without changing other repos where the deps workflow is used

@probelabs

probelabs Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

This pull request addresses a bug in the dependency-guard.yml workflow that caused it to fail when triggered outside of a pull request context. The issue stemmed from the BASE_REF environment variable being empty in such scenarios, leading to a failed git fetch command.

The fix introduces a robust fallback mechanism. If github.event.pull_request.base.ref is not available, it now uses github.repository.default_branch. This ensures the workflow correctly identifies the base for comparison, whether it's running on a PR or triggered by other events like a push to the default branch.

Files Changed Analysis

  • .github/workflows/dependency-guard.yml: Modified to provide a dynamic fallback for the BASE_REF environment variable, ensuring the workflow's stability across different trigger events.

Architecture & Impact Assessment

  • What this PR accomplishes: It makes the dependency-guard.yml reusable workflow more resilient by ensuring it can run successfully even when not in a pull request context.
  • Key technical changes introduced: The expression for setting the BASE_REF variable was updated from ${{ github.event.pull_request.base.ref }} to ${{ github.event.pull_request.base.ref || github.repository.default_branch }}. This change leverages the || operator to dynamically use the repository's default branch as a fallback, which is more robust than hardcoding branch names like main or master.
  • Affected system components: The primary component affected is the dependency-guard reusable workflow. Consequently, any repository or workflow that utilizes this shared workflow will benefit from this fix, as it prevents a potential failure point without requiring changes on the consumer's side.

Scope Discovery & Context Expansion

  • The change is confined to a single line within one workflow file. However, as dependency-guard.yml is a reusable workflow (as implied by its purpose and location in a shared actions repository), the scope of this fix extends to all its consumers. This centralized solution enhances the reliability of the dependency checking process across multiple projects that depend on this action.
Metadata
  • Review Effort: 1 / 5
  • Primary Label: bug

Powered by Visor from Probelabs

Last updated: 2026-04-06T09:41:23.389Z | Triggered by: pr_updated | Commit: f660381

💡 TIP: You can chat with Visor using /visor ask <your question>

@probelabs

probelabs Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

✅ Security Check Passed

No security issues found – changes LGTM.

✅ Architecture Check Passed

No architecture issues found – changes LGTM.

✅ Performance Check Passed

No performance issues found – changes LGTM.

Quality Issues (1)

Severity Location Issue
🟠 Error .github/workflows/dependency-guard.yml:29
The fallback logic for `BASE_REF` is flawed due to how the `||` operator works in GitHub Actions expressions. The expression `... || 'master' || 'main'` will always resolve to `'master'` if `github.event.pull_request.base.ref` is empty. This is because `||` returns the first truthy value, and the string `'master'` is always truthy. As a result, the `'main'` branch will never be used as a fallback, which will cause the workflow to fail in repositories that use `main` as their default branch but do not have a `master` branch.
💡 SuggestionTo fix the immediate issue, you can reorder the fallbacks to prioritize the more common default branch name, for example: `... || 'main' || 'master'`. However, a more robust and reliable solution would be to use a small script to dynamically determine the repository's default branch rather than relying on hardcoded names.

Powered by Visor from Probelabs

Last updated: 2026-04-06T09:41:13.700Z | Triggered by: pr_updated | Commit: f660381

💡 TIP: You can chat with Visor using /visor ask <your question>

@vladzabolotnyi

Copy link
Copy Markdown
Author

/visor fallback logic is fixed with github.repository.default_branch context variable

@probelabs

probelabs Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Powered by Visor from Probelabs

Last updated: 2026-04-06T09:55:06.245Z | Triggered by: vladzabolotnyi | Commit: 42304ed

💡 TIP: You can chat with Visor using /visor ask <your question>

@buger
buger merged commit f867e50 into main Apr 6, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants