GitHub action best practics

Github Actions

Github action makes it easier to build test and deploy your project on any platform. In this article, we would look into a few Github action best practices on running a hosted runner.

By following these best practices would not only improve the speed of our workflow run time also save our billing :).

let’s look into these steps

  1. Caching dependencies to speed up our workflow by - using: actions/cache@v2. This helps save those extra minutes. Find more detail https://github.com/actions/cache. Let’s look at an example
- name: Cache multiple paths
uses: actions/cache@v2
with:
path: |
~/cache
!~/cache/exclude
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

2. The maximum number of minutes to let a job run before GitHub automatically cancels it. Default: 360. Time is the money it is literally true if you are running your Github action workflow in hosted running as Gitub would charge you for the duration of your workflow run.

During our last few month's observation, we found some time the workflow runs more than an hour before it stops abnormally while we are not sure what really causes this issue is important to have an expected timeout before the end of our workflow. We can found more information here.

my-job:
runs-on: ubuntu-latest
timeout-minutes: 30

3. We would have to make sure not to commit raw secrets inside our workflow file. Always use secrets stores like Github secret. This is the best place to store and use the credential. To find more information can be found here.

using Github Secret in Github action workflow.

4. Validate and run your newly created or updated workflow file using https://github.com/nektos/act or similar tools for quick confirmation.

--

--

--

full-time learner

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Top 8 Most Popular Web Development Frameworks in 2021

How I began my coding journey

Yield Farming Completed, What now?

Creating an Android App with React Native, NativeBase and WatermelonDB

Garbage Collection(GC) in Java

[GUIDE for Minting] Sunmiya Club 민팅 가이드(SIX/KLAY)

Java Date Time data types

Open CV :- Basic Image Processing Functions and Detection

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
pravanjan palai

pravanjan palai

full-time learner

More from Medium

LockAjar — A dive into embedded linux IoT Part 1.5

Using hardware tokens for two-factor authentication: how does it work?

NGINX/OpenResty Reverse Proxy versus Identity Provider integrations

How to install simultaneously Docker and Podman on RHEL 8/CentOS 8