Replies: 4 comments 1 reply
-
|
This is a classic "chicken and egg" problem with testing Composite Actions. The reason your if: ${{ inputs.test }} workaround failed is that GitHub Actions performs static analysis on the entire workflow graph before execution starts. It verifies that all uses: references (like my-org/my-repo/...@master) are valid and accessible. If your new action hasn't been merged to master yet, the workflow crashes during this pre-flight check, ignoring your if condition entirely. The standard solution used by many maintainers is to keep your action.yml "pure" (pointing to production refs) and use a "Patch-on-Test" strategy. Instead of putting test logic inside the action, modify the action dynamically inside the test workflow. The "Sed" Strategy
jobs: Why this works
|
Beta Was this translation helpful? Give feedback.
-
|
Hi everyone 👋 We've been working on something that may help here. We're proposing a new - uses: $/path/to/action # same repo, same SHAThis gives you version-safe references without hardcoding. The I've posted the full proposal over in community#26245. We'd love your feedback there! — The GitHub Actions Team |
Beta Was this translation helpful? Give feedback.
-
|
Hello @rdgoite, It looks like you have hit one of the most persistent pain points in developing Composite Actions: Graph resolution happens before variable expansion. Because GitHub validates all uses references before looking at if conditions or context variables, your conditional workaround fails static analysis. Here is a summary of your options, ranging from the immediate workaround to the upcoming native solution.
You can streamline Marjuk's suggestion by adding a setup step to your reusable workflow tests: YAML
The proposed syntax: YAML This solves the two main problems: Versioning: It works in PRs (checks out the commit) and Production (checks out the tag/branch) automatically. Nesting: It resolves relative to the calling file, not the repository root. |
Beta Was this translation helpful? Give feedback.
-
|
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Why are you starting this discussion?
Question
What GitHub Actions topic or product is this about?
General
Discussion Details
I'm currently writing a set of actions for reuse, and I'm struggling a bit with writing the automated tests that sit alongside the actions themselves. At the moment, I have defined the tests as workflows themselves that sit inside
.github/workflows. They run as a suite every time changes are pushed. I think this works pretty well, however, I've run into limitations that are making the experience very difficult.Firstly, when I'm referring to reusable actions in their corresponding test workflows, I use relative paths. I do this because I want the tests to run against the current version of their target action every time. However, this is not how they are going to be consumed ultimately; they will be referred to using a fully qualified identifier (e.g.
my-org/my-repo/path/to/action). This would have been easy if theusesfield can be specified variably, but it has no access to any context. There's an older discussion about this (#25246).This is particularly a problem when the reusable actions refer to other reusable actions in the same repository. The relative paths in actions are relative to the repository they're running in, not relative to the repository that hosts them. I've worked around this by adding test run flags into my reusable actions, which, while hard to look at, seems to work. It looks like the following (very similar to a workaround described in the aforementioned discussion):
But yet again, I've run into another limitation. It looks like GitHub Actions are parsed and verified before being interpreted. If
path/to/actiondoes not exist in@masteryet (when it's still being developed), the test workflows fail verification. I was hoping it simply ignores the specification because the if condition resolves to false anyway, but it doesn't.I'm curious how people are approaching this, or is it common for people not to test reusable actions?
Beta Was this translation helpful? Give feedback.
All reactions