GitHub Actions Reusable Workflows FULL TUTORIAL with Examples: Templates on Steroids

  Рет қаралды 27,442

CoderDave

CoderDave

Күн бұрын

No more duplication! You can now reuse entire GitHub Actions workflows as if they were a single action. Instead of copying and pasting workflow definitions across repositories, you can now reference an existing workflow with a single line of configuration.
Github Actions Reusable Workflows make workflows easier to maintain and allows you to create new workflows more quickly by building on the work of others
🌟EXCLUSIVE CONTENT🌟
Do you want to access exclusive content, live chats and Q&As, polls, and even 1:1 calls with me? Join my Patreon: / coderdave
🆘 NEED HELP? 🆘
Book a 1:1 Consultation with CoderDave: geni.us/cdconsult
🙏🏻SUPPORT THE CHANNEL🙏🏻
Buy me a coffee: www.buymeacoffee.com/CoderDave
PayPal me donation: paypal.me/dabenveg
🎥VIDEOS
► GitHub Actions Templates with Composite Actions: • Create Reusable GitHub...
► GitHub Actions FULL Course: • GitHub Actions Tutoria...
► Use GitHub Like a PRO: • Use GitHub like a PRO!...
💬JOIN THE COMMUNITY
► Discord: geni.us/cddiscord
► Newsletter: coderdave.io/newsletter
► Blog: dev.to/n3wt0n
► GitHub: github.com/n3wt0n
► Twitter: / davidebenvegnu
► Facebook: / coderdaveyt
⏲TIMESTAMPS
0:00 The new feature
0:40 Reusable Workflows in GitHub Actions
1:24 How to Create a Reusable Workflow
3:44 Creation Notes
4:11 Use a Reusable Workflow
6:39 Why Reusable Workflows
6:58 Reusable Workflows Caveats
7:36 Reusable Workflows Limitations
8:14 Final Notes
🎤PODCAST: geni.us/cdpodcast
❓QUESTIONS?
Have a question about DevOps, Cloud, Coding, or Anything Else? Post in comments section of this video!
🔴SUBSCRIBE to CoderDave here: kzbin.info?sub...
_______________
👕Get my MERCH: geni.us/cdmerch
🔮TOOLS I USE
► Twingate - Connect to your Private Resources SECURELY: geni.us/twingate
► TubeBuddy - #1 KZbin channel Management tool (FREE): www.tubebuddy.com/CoderDave
► Moosend - Free Newsletter and Automation Platform: geni.us/moosend
📸🖥️GEAR AND SOFTWARE
► Music - Epidemic Sound (Get 30 days free): epidemicsound.com/referral/zf...
► Editing - Adobe Premiere Pro: geni.us/AdobeVideo
► Gear I Use for KZbin: kit.co/CoderDave/gear-i-use-f...
► Gear I Use for Streaming: kit.co/CoderDave/gear-i-use-f...
► My Computer Setup: kit.co/CoderDave/main-compute...
► Full office setup: github.com/n3wt0n/work-from-h...
Disclaimer:
Some product links are affiliate links which means if you buy something I'll receive a small commission at no additional cost to you.
As an Amazon Associate, I earn from qualifying purchases.

Пікірлер: 82
@CoderDave
@CoderDave 2 жыл бұрын
✨ Question of the day ✨: Do you have any use case for Reusable Workflows? GET EXCLUSIVE CONTENT: Join my Patreon: www.patreon.com/CoderDave SUPPORT THE CHANNEL : Buy me a coffee: www.buymeacoffee.com/CoderDave PayPal me donation: paypal.me/dabenveg
@RajabNatshah
@RajabNatshah 2 жыл бұрын
Yes .. Having a workflow for products ( or project templates ).. then in each project could reuse the workflow .. not have a copy of the product workflow.. only reuse
@KennethRrvik
@KennethRrvik 2 жыл бұрын
Great little snippet, helped me getting a quick test in action ;)
@CoderDave
@CoderDave 2 жыл бұрын
Great to hear!
@adamsebetich9290
@adamsebetich9290 2 жыл бұрын
Huge! Finally this comes out. I’ll wait for it to not be in beta to use
@CoderDave
@CoderDave 2 жыл бұрын
True, we were waiting for this for a while. I think you can start using it already, it seems pretty stable. I believe (but this is just my idea) that if anything will change from beta to GA will be added features, not removing anything 😄
@koodauskanava9096
@koodauskanava9096 2 жыл бұрын
Thanks for this, very nice introduction video
@CoderDave
@CoderDave 2 жыл бұрын
Glad you liked it!
@AleksandarIvanov69
@AleksandarIvanov69 2 жыл бұрын
It's good to have both CAs and RWs as an option, cause even tho they largely overlap, each one fits very specific different use cases. We are fiddling internally with both right now and we are fascinated by the potential for elegant solutions they both provide :)
@CoderDave
@CoderDave 2 жыл бұрын
I agree, there is an overlap and you can do similar things with both. But I think the “philosophy“ behind them is different.
@kumarsaroj18
@kumarsaroj18 2 жыл бұрын
loved this video.. crisp, but still very informative. I was looking for a way to optimize and reduce the number of similar workflow files.
@CoderDave
@CoderDave 2 жыл бұрын
Thanks 🙏🏻 always happy to know I’m helping ☺️
@Only_Good_Trip
@Only_Good_Trip 11 ай бұрын
Really helpful :-) thanks a lot
@CoderDave
@CoderDave 11 ай бұрын
Glad you found it helpful ☺️
@RajabNatshah
@RajabNatshah 2 жыл бұрын
Thank you :)
@CoderDave
@CoderDave 2 жыл бұрын
Welcome 😀
@subhajitsarkar7515
@subhajitsarkar7515 2 жыл бұрын
this was really helpful , t hanks
@CoderDave
@CoderDave 2 жыл бұрын
Glad it was helpful!
@iimnurdiansyah53
@iimnurdiansyah53 Жыл бұрын
Nice info, thanks
@CoderDave
@CoderDave Жыл бұрын
More than welcome ☺️
@AleksandarIvanov69
@AleksandarIvanov69 2 жыл бұрын
Seeing how we are both looking at the same things, but you being way down the path we are on and the fact that everything I've seen from you so far has been great, I would love to see the following videos on your channel: - Tutorial: How to run a GiHA workflow inside a container with non-root context - Recurring series: Reviewing GiHA Ci/CD pipelines
@CoderDave
@CoderDave 2 жыл бұрын
First of all, thanks for the compliments :) Second, for Actions in container it is a little tricky, because Actions in Docker won't support running other Docker Actions (and there are a lot)... I'm waiting for the team to support that natively, I don't want to endorse "sketchy workarounds" :) For the last point, what do you mean by "Reviewing Actions CI?CD Pipelines"? You mean the workflows I have, or some viewer workflow, or...? I think this could be interesting, thanks for the suggestion! PS: if you want, join our Discord server: geni.us/cddiscord
@AleksandarIvanov69
@AleksandarIvanov69 2 жыл бұрын
@@CoderDave I mean reviewing other people's pipelines, to point out mistakes, what could be improved and how. Something like that :)
@CoderDave
@CoderDave 2 жыл бұрын
Sounds like a great idea!
@AleksandarIvanov69
@AleksandarIvanov69 2 жыл бұрын
@@CoderDave I have a submission at hand already, so whenever you are :)
@CoderDave
@CoderDave 2 жыл бұрын
Let's see if we get enough interest on this, but I love the idea. Thanks! Check this out and submit your application ;) kzbin.infoUgkxJ0P46PUBTAXcuh8VmbvTBJaNQsjckn0W
@vishnuvardhan-dg6xm
@vishnuvardhan-dg6xm 2 жыл бұрын
Hi Dave, I have two repos consisting projects in one and dependecy poms in another. Selfhosted runner is being used. To build the services i need to install the dependencies in maven local repo and resolve them while building. How could i build the dependencies to maven local repo prior to building services in another repo using reusable workflows.?
@lucsegers6931
@lucsegers6931 8 ай бұрын
really loved this video, thank you. Did the reusable workflows changed a lot since this video? I understand the use of composite actions and reusable workflows, but what about templates? How does templates compare to reusable workflows and composite actions. Is templates being deprecated?
@CoderDave
@CoderDave 8 ай бұрын
Thanks for the comment! AFAIK, Actions has never had templates (like for example Azure Pipelines has). Reusable workflows are the "de facto" templates in GitHub Actions. Them, and Composite Actions. Both can be considered sort-of templates. You may wanna check my video about that: kzbin.info/www/bejne/sJSUaqCIaLRnl5Y
@user-yc6lg1co5q
@user-yc6lg1co5q 7 ай бұрын
Excellent Tutorial! If the reusable workflow is in a different repository, is it possible, in the caller workflow and under the job calling the reusable workflow, to checkout that second repository holding the reusable workflow? Also it seems performing the checkout (of the second repo) within the reusable workflow itself, never take effect; rather the checked-out caller workflow repo persists all through the entire job run.
@CoderDave
@CoderDave 7 ай бұрын
Thanks :) No it is not possible, not directly anyway. If you use the checkout step in the reusable workflow, it will always checkout the caller repo. If you want to checkout the repo where the reusable workflow is (let's call it "myuser/reusables") then you can use the `repository` parameter of the checkout action (under `with`) and hardcode the "myuser/reusables" repo name there
@fellifel147
@fellifel147 Жыл бұрын
Do u have any videos on workflow_run?
@moustafa6006
@moustafa6006 2 жыл бұрын
now you can reference a reusable workflow just like composite action. Meaning, it will use the file in the same branch with a path instead of using the repot and a ref.
@CoderDave
@CoderDave 2 жыл бұрын
Yes, you can host them in either another repo or in the same repo, it is neat :) I talked about this in last week's video :)
@a2zbabysteps
@a2zbabysteps 11 ай бұрын
@CoderDave Can we call the reusable workflow via curl - asynchronously (like fire and forget calls to these steps). i.e. our progress of main workflow should not be waiting for output from this reusable workflow?
@CoderDave
@CoderDave 11 ай бұрын
No, unfortunately that is not possible. I can see the usefulness of that tho
@MichaelRainabbaRichardson
@MichaelRainabbaRichardson 2 жыл бұрын
Is there a plan to see the environment variables translated into the shared workflow? Is there a reason that isn't currently done? Outstanding video and exactly what I needed. Thank you.
@CoderDave
@CoderDave 2 жыл бұрын
Thanks! unfortunately I don't have an answer on your questions... I;m sure there is a technical reason why the env variables are not expanded to the reusable workflow, but I'm not sure why...
@gagikmirzoyan9884
@gagikmirzoyan9884 Жыл бұрын
I"m not sure if there was this method during the time this comment posted, but alongside parameters of reusable workflow under "with:" you can have "secrets: inherit" so reusable workflow will inherit caller workflow secrets.
@fromhereandthere460
@fromhereandthere460 Жыл бұрын
@@CoderDave then if you have a repo that needs an environment variable exclusive to it, then you can't use the reusable workflow because it won't be referenced in the re-usable-workflow right?
@NunoMaiaNM
@NunoMaiaNM 2 жыл бұрын
I've setup two workflows in the same repository, and the called workflow does not receive any inputs passed from the caller :( . Do you have any sugestion?
@CoderDave
@CoderDave 2 жыл бұрын
Uhm that’s very hard to understand without seeing the workflows… perhaps you can join our discord server and ask there so we can take a look at it ☺️
@iceboxbob
@iceboxbob 2 жыл бұрын
Do you think I can run specific jobs from the called workflow in a caller workflow?
@CoderDave
@CoderDave 2 жыл бұрын
Yes, but you’d need to implement the logic by yourself. For example, having some IF conditions in the template and then passing the variable from the caller to the reusable workflow to control the execution
@iceboxbob
@iceboxbob 2 жыл бұрын
@@CoderDave cool, thanks for the response. Your video was helpful.
@suhaskulkarni5857
@suhaskulkarni5857 Жыл бұрын
How can we use org secrets in the workflow call? The workflow call always accepts secrets from called workflow by using inherit. Is there a workaround to use the secrets from workflow call repo or org secrets?
@CoderDave
@CoderDave Жыл бұрын
Hi, afaik there is no way to be consume a secret directly from the reusable workflow. All has to be passed from the caller using the secret parameters
@ShyamKumar-yn2jw
@ShyamKumar-yn2jw 2 жыл бұрын
how to call a workflow in a private repo. it says it private reusable workflow can be used only in the same repo. but didnt worked for me. Thanks in advance.
@CoderDave
@CoderDave 2 жыл бұрын
You can call them in private repo from the same repo, using the "normal" syntax: jobs: your-job-name: uses: username-or-org/repository-name/.github/workflows/worflows_file-name.yml@your-version-tag-or-branch
@ShyamKumar-yn2jw
@ShyamKumar-yn2jw 2 жыл бұрын
@@CoderDave Thanks :) , it worked, I missed the branch/tag
@sahilchaudhry08
@sahilchaudhry08 Жыл бұрын
Are the reusable workflow similar to templates in Azure DevOps YAML pipelines?
@CoderDave
@CoderDave Жыл бұрын
They are somewhat similar, they can be used more or less for the same scanarios
@sahilchaudhry08
@sahilchaudhry08 Жыл бұрын
@@CoderDave I have already built some Azure devops YAML templates to build and deploy dotnet applications so I want to build similar stuff for Github Actions. What do you suggest?
@CoderDave
@CoderDave Жыл бұрын
Yes, that is definitely a good use case. I'd create a repo with all the reusable workflows and you're good to go :)
@vishnuvardhan-dg6xm
@vishnuvardhan-dg6xm 2 жыл бұрын
I have multiple workflow files for different services in one repo configured for same event. How can i stop all the workflows getting triggered except the service wish to run if committed?
@CoderDave
@CoderDave 2 жыл бұрын
It is difficult to answer this without knowing how your repo is structured. I'd go with one of those 2 solutions. If your different services are in different folders, you can add the branch filter to your triggers... something like: on: push: branches: - main paths: - service1/ more docs here: docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-paths if instead they are not in different folders, you could use the job conditionals to check for specific conditions (like file names, comments in the commit, etc)
@vishnuvardhan-dg6xm
@vishnuvardhan-dg6xm 2 жыл бұрын
@@CoderDave Thank you Dave 😀
@AnilKumar-qh5gz
@AnilKumar-qh5gz Жыл бұрын
I was able to create a reusable workflow (reusable.yml) and a caller workflow (caller-reusable.yml), which works fine. Thank you for the great video. Now my requirement is to pass a JSON file/data from caller workflow to the reusable workflow for some processing. I tried passing the JSON file/data from caller workflow to reusable workflow and then process the JSON file in reusable workflow by calling a PS script. But I am not able to refer to my PS script file (test.ps1) which has been created in reusable workflow. It simply throws below error, thought the path is correct: The term '/test.ps1' is not recognized as a | name of a cmdlet, function, script file, or executable | program. Check the spelling of the name, or if a path was | included, verify that the path is correct and try again. Any pointers please?
@CoderDave
@CoderDave Жыл бұрын
When a reusable workflow is executed, the “context” is set to the caller workflow… this is why you cannot find your file. You could create a Composite action for the step where you need the ps file (in that case it is used), and reference that in the reusable workflow
@kalirajaramasamy1248
@kalirajaramasamy1248 2 жыл бұрын
Thanks for awesome video. I tried this approach and getting the below error. No steps defined in `steps` for the following jobs: docker. I tried in enterprise github account. Could you please help me on this error?
@CoderDave
@CoderDave 2 жыл бұрын
It looks like GitHub doesn’t recognize your reusable workflow. It’s difficult to say without seeing your setup, but I’d double check the syntax in both files and see if everything is correct… with YAML just a small thing missing and everything stops working 😁
@kalirajaramasamy1248
@kalirajaramasamy1248 2 жыл бұрын
@@CoderDave I just followed your videos and double cheked the indentation as well. Everything looks correct. One thing to note here is, In our project github account composite action also does not work. Composite action is not yet available for enterprise github account.
@CoderDave
@CoderDave 2 жыл бұрын
Uhm that is very strange. Both composite actions and reusable workflows are available in GitHub Enterprise. I’ve use them in GHEC already with clients. But it doesn’t work if they are hosted on private repos. They must be in public repos or internal repos with the proper settings
@yankee-in-london
@yankee-in-london 2 жыл бұрын
Great video but being a bit of a newbie I am struggling to get this to work where the Parent and Child workflows are in the same repo. I figured the parent workflow could run a conditional statement and then reference the other workflow with "./.github/workflows/my-workflow" but it says it can't find it and I've been in a spin cycle since.
@yankee-in-london
@yankee-in-london 2 жыл бұрын
steps: - name: Check if NPM Release (commit msg) if: contains(github.event.head_commit.message, 'release v') uses: ./.github/workflows/release
@yankee-in-london
@yankee-in-london 2 жыл бұрын
I think part of my confusion is how to separate Actions and Workflows ... your example seemed to point to actions/my-workflow but you defined a workflow.
@CoderDave
@CoderDave 2 жыл бұрын
On the phone right now so I can’t test, but I believe for local workflows you need to use the full path, including “.yaml” extension
@yankee-in-london
@yankee-in-london 2 жыл бұрын
@@CoderDave I eventually got it to work ... you not only need the '.yaml' but you also seem to need to self-reference the repo name and branch ... a bit awkward but it works
@akankshayadav7575
@akankshayadav7575 2 жыл бұрын
What is the difference between composite action and reusable workflows
@CoderDave
@CoderDave 2 жыл бұрын
Great question, there are many differences, in fact too many for just an answer to the comment. But you can see composite actions as a subset of feature of reusable workflows. In general, composite actions are simpler, cannot use conditionals or multiple jobs, and have limited logs. Reusable workflows, on the other hand, are much more feature-rich, and can be seen as actual templates. I will make a video about the comparison soon, stay tuned.
@akankshayadav7575
@akankshayadav7575 2 жыл бұрын
@@CoderDave Thank you so much
@akankshayadav7575
@akankshayadav7575 2 жыл бұрын
Is shared libraries concept of GitHub Actions = reusable workflows ?
@CoderDave
@CoderDave 2 жыл бұрын
More or less, yes
@ovididubois1612
@ovididubois1612 Жыл бұрын
Hi
@CoderDave
@CoderDave Жыл бұрын
Hello 😁
@ashu9103
@ashu9103 6 ай бұрын
when I call reusable workflow, it does not checkout reusable workflow repo but it checks out calling workflow. your example is not helpful.
@CoderDave
@CoderDave 4 ай бұрын
That is how it’s designed to work… if you don’t like it , talk to GitHub… nothing I can do about it
@dannyv12
@dannyv12 Жыл бұрын
So why do you have to rebuild your app for every job this is pretty lame. 😢
@CoderDave
@CoderDave Жыл бұрын
You don't have to... that was just an example... you can make the job(s) and workflow(s) do whatever you need them to
@dannyv12
@dannyv12 Жыл бұрын
@@CoderDave so how can i reuse a job build and use that in the new run-as for the new job because I can't find it?
@CoderDave
@CoderDave Жыл бұрын
You mean building your app on Job A and reusing the build artifact on job B? That is not what reusable templates are for. To do that you can use the “upload artifact” action in job A and the “download artifact” action on job B
Climbing to 18M Subscribers 🎉
00:32
Matt Larose
Рет қаралды 36 МЛН
I wish I could change THIS fast! 🤣
00:33
America's Got Talent
Рет қаралды 70 МЛН
GitHub Reusable Workflows and Invocation from other repos
8:42
OutOfDevOps
Рет қаралды 2,5 М.
GitHub Actions - Calling Reusable Workflows
13:03
Mickey Gousset
Рет қаралды 9 М.
GitHub Actions (Branch Protection, Automated Testing) - Full Tutorial
29:56
Securing Self-Hosted GitHub Actions with Kubernetes & Actions-Runner-Controller - Natalie Somersall
40:53
CNCF [Cloud Native Computing Foundation]
Рет қаралды 2,2 М.
How GitHub Actions 10x my productivity
8:18
Beyond Fireship
Рет қаралды 391 М.
GitHub Actions Self Hosted Runner (Autoscaling with Kubernetes)
18:30
Git Tutorial - Git Crash Course using BitBucket
36:03
Emad Zaamout
Рет қаралды 185 М.
GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker
32:31
TechWorld with Nana
Рет қаралды 1,4 МЛН
How To Unlock Your iphone With Your Voice
0:34
요루퐁 yorupong
Рет қаралды 27 МЛН
сюрприз
1:00
Capex0
Рет қаралды 1,7 МЛН
iOS 18 vs Samsung, Xiaomi,Tecno, Android
0:54
AndroHack
Рет қаралды 88 М.