Calling a sibling composite action using the same ref #41927
Replies: 9 comments 1 reply
-
To @oblivioncth's point on the workaround, this is possible but not ideal. From an experience standpoint, I think I would want This is possible with the outer action doing the following step: - name: Symlink current Actions repo
env:
GH_ACTION_REPO: ${{ github.action_repository }}
GH_ACTION_REF: ${{ github.action_ref }}
shell: bash
run: ln -s /home/runner/work/_actions/$GH_ACTION_REPO/$GH_ACTION_REF/ /home/runner/work/_actions/current There is a Additional actions can then be called like the following: - name: Do something
uses: ./../../_actions/current/my-action Where |
Beta Was this translation helpful? Give feedback.
-
I did identify a slightly cleaner way to do the same thing: - name: Symlink current Actions repo
working-directory: ${{ github.action_path }}
shell: bash
run: ln -fs $(realpath ../) /home/runner/work/_actions/current |
Beta Was this translation helpful? Give feedback.
-
It'd be really good to see github improve this by supporting
or
|
Beta Was this translation helpful? Give feedback.
-
To summarize the answer from @mbrancato and some github documentation, here is the code that I used at my work.
then the code in - name: Symlink current action repo
env:
action_path: ${{ github.action_path }}
run: ln -fs ${{ env.action_path }}/.. .github/.action_repo.my-cool-repo
shell: bash
- name: Call the root action
uses: ./.github/.action_repo.my-cool-repo
- name: Call the sibling action
uses: ./.github/.action_repo.my-cool-repo/subfolder2
- name: Unlink the action repository
run: rm -f .github/.action_repo.my-cool-repo
shell: bash Of course |
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.
-
Any news? |
Beta Was this translation helpful? Give feedback.
-
Probably shouldn't have let this closed/changed it to a suggestion, but I just noticed that reusable-workflows already support being called from the same repository using the current commit, so I don't see why composite actions shouldn't be. |
Beta Was this translation helpful? Give feedback.
-
Still not as ideal as native support, but I just stumbled upon something pretty dang close: https://github.com/marketplace/actions/dynamic-uses The example they show is for doings something slightly more complex, but the tl;dr is that essentially with this you can use context variables in the "uses" key when calling a dynamic action! |
Beta Was this translation helpful? Give feedback.
-
Just to summarize, and to point out a few details that weren't pointed out: The basic ideaGitHub Actions doesn't let us use dynamic This means that the only way to use a sibling action from the same ref as the currently running ref is to 1) put its files in a fixed location in the runner, and 2) point to it using a relative path: - name: Link to sibling actions in a fixed location
shell: bash
run: |
# find the root path of your sibling actions by referencing the path of the current action on disk
SIBLINGS_PATH=$(realpath "${ACTION_PATH}/..")
# and store it somewhere that we know the relative path to
SYMLINK_PATH='.github/.action-siblings'
ln -fs "${SIBLINGS_PATH}" "${SYMLINK_PATH}"
env:
ACTION_PATH: "${{ github.action_path }}"
- name: Use sibling action
uses: .github/.action-siblings/my-sibling-action ProblemsThis... works? Unfortunately it runs into trouble relatively quickly:
|
Beta Was this translation helpful? Give feedback.
-
Select Topic Area
Suggestion
Body
NOTE: I completely worked this question to be a suggestion, as after some investigation I don't believe there is anyway to do this currently (at least in a sensible way).
If you have a repository dedicated to holing (composite) actions, like so:
a common scenario is having the actions leverage other composite actions within the same repository.
The problem with doing this as shown, is that since the path/ref for the sub-action is hardcoded, that version will obviously always be used. This has the major downside of picking between two evils:
ref
/branch
(and therefore you must essentially give up versioning)or
ref
for all nested calls, leading to the need for consumers to checkout multiple copies of your repository even if they intended to just use one version, potentially to a seriously inefficient degree if the size of the repository and variety of "inner" tags used grow large enough.A more sensible design pattern would be to have any nested calls to composite actions within the same repository use the same
ref
that the outer most call received.So in the above example, if 'cp_action01' was used from an external repository like so:
uses: oblivioncth/repo_cactions/cp_action01@v1.0
then the use of 'cp_action02' within would also be via tag
v1.0
.You would think you could do this by doing the following in the outer action
but you can't because
steps.uses
cannot access thegithub
context.It is technically possible to work around this by having the outer action checkout the repository with the same ref (redundantly) to a hard-coded path and then invoke the action as a local one, but this adds a ton of extra boilerplate to each composite action and pollutes the consumers workspace.
Please let the
uses
value for step access the github context or enable sibling composite actions to be called with the same ref as the current composite action some other way.Beta Was this translation helpful? Give feedback.
All reactions