Home > OS >  Why choose github action when we can just run bash script in github workflow?
Why choose github action when we can just run bash script in github workflow?

Time:08-26

Just completed a GitHub workflow using more of them are actions, but also with one bash script.

When writing the workflow, it seems much quicker use bash script than actions.(since some actions are just do one thing. ) Why are the some reasons that we just need GitHub actions rather than bash script or python script trigger?

Or we are just supposed to use script languages for most part, then use GitHub actions for small portion of the whole workflow?

CodePudding user response:

Interesting but not easy to answer with more information about what your goal is. The right answer might depend on your use case.

I have not used GitHub actions yet. Let me try to explain it anyway, starting pretty high level. Unfortunately, there's no option to add a table of contents ;) Please let me know if this helps.

1. What are GitHub Actions for?

From this "What is GitHub Actions? Benefits and examples" PDF file

GitHub Actions is a CI/CD tool for the GitHub flow. You can use it to integrate and deploy code changes to a third-party cloud application platform as well as test, track, and manage code changes. GitHub Actions also supports third-party CI/CD tools, the container platform Docker, and other automation platforms.

From docs.github.com

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository or deploy merged pull requests to production. [...] GitHub Actions goes beyond just DevOps and lets you run workflows when other events happen in your repository.

2. Continuous Integration/Continuous Deployment (CI/CD)

Usually, people run CI/CD tools to build, deploy, test, and run other tasks while doing that. We use another 3rd party CI/CD pipeline using Rake to build, test, and check links. Our pipeline invokes these small scripts you mention.

3. GitHub actions and scripts

From Essential features of GitHub Actions

If your job generates files that you want to share with another job in the same workflow, or if you want to save the files for later reference, you can store them in GitHub as artifacts. Artifacts are the files created when you build and test your code. For example, artifacts might include binary or package files, test results, screenshots, or log files. Artifacts are associated with the workflow run where they were created and can be used by another job. All actions and workflows called within a run have write access to that run's artifacts.

Here's the key point, I guess. You can really do a lot of crazy stuff within a workflow. All is related/specific to GitHub. Workflows are event-driven, meaning that you can run a series of commands after a specified event has occurred. For example, every time someone creates a pull request, you can automatically run a command that executes a test or other script.

4. GitHub action workflow and scripts

You can include different scripts in your workflow, e.g. using

5. (Complex) Examples

You can check out the repository for docs.github.com for some more complex examples, see action-scripts and workflow folders. GitHub themselves seems to use it pretty heavily.

6. Advantages/Disadvantages of GitHub actions

OR: Differences to other CI tools

It took some time to find something not marketing-ish. Key points are:

  • beginner-friendly using YAML config files
  • no need to set up your own CI pipeline

You can check out this SO post from 2019 for a list of what's good and bad about GitHub actions.

CodePudding user response:

In short - for readability and the DRY ("Don't repeat yourself") principle. It's more or less the same as using functions in programming. I can agree that some trivial actions are useless. But "actions/checkout" for example is priceless!

  • Related