How to modularize actions? #26320
-
There are multiple questions created long back and no response on them later. I have a github action workflow job steps containing 10 to 15 windows batch commands, which I am running in my self-hosted windows server. The same steps need to be repeated multiple times for different input files. Is there anyway to create a module of this and call this with the parameters changed? Please suggest. |
Beta Was this translation helpful? Give feedback.
Replies: 19 comments
-
Hi @ukreddy-erwin
Reusing workflows - GitHub DocsLearn how to avoid duplication when creating a workflow by reusing existing workflows.
Creating a composite action - GitHub DocsIn this guide, you'll learn how to build a composite action. or
How to start using reusable workflows with GitHub Actions | The GitHub BlogReusable workflows offer a simple and powerful way to avoid copying and pasting workflows across your repositories. Est. reading time: 6 minutes |
Beta Was this translation helpful? Give feedback.
-
I tried the steps in the second link composite action as is but. So, the workflow yaml changed as
But, it is failing as below error.
So, I changed the repo to public and tried and got below error. How to keep them working in private repo?
Even I added chmod +x command as one step in action but getting this, 12 echo “/home/runner/work/_actions/ukreddy-erwin/testactions/ffbd787a4b9f0752347c5f62f2137460961e5a83” >> $GITHUB_PATH 13 shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0} 14Run chmod +x goodbye.sh 15 chmod +x goodbye.sh
|
Beta Was this translation helpful? Give feedback.
-
Actions can be in internal repo (you need Enterprise GitHub org), but not private. So, unfortunately it is no easy way to have actions in private repo:s. |
Beta Was this translation helpful? Give feedback.
-
how to keep in the same repo as a sub folder and refer them? |
Beta Was this translation helpful? Give feedback.
-
You can take a look at this thread Path to action in the same repository as workflow - #2 by yanjingzhu |
Beta Was this translation helpful? Give feedback.
-
Also this one is good example Multiple github composite actions in one repo - #2 by mcaskill |
Beta Was this translation helpful? Give feedback.
-
Thanks @ViacheslavKudinov , I tried the steps but not working. Below is the steps I tried. I kept an action.yml in the root folder of repo and tried to reference it in the github workflow.
GitHub - ukreddy-erwin/testactionsContribute to ukreddy-erwin/testactions development by creating an account on GitHub. |
Beta Was this translation helpful? Give feedback.
-
@ukreddy-erwin, please, change step to
|
Beta Was this translation helpful? Give feedback.
-
Thank you it works, so we it would pick from the folder directly. Also, i tried referring the input variable in the bash file of the action, but it is not expanding.Can you guide that also.
ukreddy-erwin/testactions/blob/8a9c78356cf770ba32016d03b56e4d3b2fd46ab6/goodbye.sh
echo $userfulname Also, is there anyway to keep these main workflow, actions, everything in a separate repository? so that these changes won’t add new commits to main codebase. |
Beta Was this translation helpful? Give feedback.
-
ukreddy-erwin:
You can use subfolders if you wish and then it will be:
and it will pick up action.yaml from that subfolder.
ukreddy-erwin:
Yes, if you wish you can have one repo per one GitHub action and also utilise reusable workflow if you want to have workflow as separate code/repo. |
Beta Was this translation helpful? Give feedback.
-
In jenkins, say I have my source code in repoA. I can keep my pipeline file in repoB and in a separate branch say testB. Can we set similarly here? |
Beta Was this translation helpful? Give feedback.
-
It really depends what you want to achieve. |
Beta Was this translation helpful? Give feedback.
-
If you don’t have Enterprise account/org it will be more complex (or maybe even not everything is possible) if you want to use private repositories for GHA:s and reusable workflows. |
Beta Was this translation helpful? Give feedback.
-
can we set something like. Current repoA: .github/workflows/main.yml
this workflow.yml is complete workflow, not an action. |
Beta Was this translation helpful? Give feedback.
-
You have to use syntax eg: |
Beta Was this translation helpful? Give feedback.
-
Can you answer the input variables part also. It is not getting expanded in bash file. tried referring the input variable in the bash file of the action, but it is not expanding.Can you guide that also. ukreddy-erwin/testactions/blob/8a9c78356cf770ba32016d03b56e4d3b2fd46ab6/goodbye.sh |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I tried and got below error.
Update goodbye.sh
|
Beta Was this translation helpful? Give feedback.
-
Let me double-check and I will be back soon. |
Beta Was this translation helpful? Give feedback.
@ukreddy-erwin, please, change step to