My Workflow
There is a process that gets repeated most of the time across your workflow, a process that is expensive in time speaking; it takes 25 seconds to complete. This process is essential, and without it, you can not do almost anything.
I'm talking about installing the dependencies for your project, npm install
for node projects. Without it, you can not build, test, lint or do almost any other operation on your workflow.
We can do something straightforward to downgrade those 25 seconds to 14.3 (an improvement of almost 60%!😮). You only need to apply cache to the dependency installation (npm install
). Those 10 seconds saved across all your jobs will add up to 32% improvement.
The secret of achieving an execution improvement of 32% is to be consistent, apply DRY. Every time you need to perform the dependency installation, you need to be sure to use the same set of steps.
Github actions allow us to be consistent super-easy with custom actions. We can define an activity with all the steps needed and then reuse it every time with just one line of code.
Submission Category:
Maintainer Must-Haves
Yaml File or Link to Code
This is the actual action using yarn
as the package manager.
# .github/actions/setup/action.yml
name: Setup
description: Setup Node.js, cache and install dependencies
inputs:
node-version:
description: Node.js version
required: false
default: '16'
runs:
using: composite
steps:
- name: Install Dependencies
uses: actions/setup-node@v2
with:
cache: yarn
node-version: ${{ inputs.node-version }}
registry-url: https://registry.npmjs.org
- name: yarn install
shell: bash
run: yarn --frozen-lockfile --no-progress --non-interactive --prefer-offline
To use it on any job:
jobs:
any-job:
runs-on: ubuntu-latest
steps:
- name: Get code to get access to custom our actions
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install Dependencies
uses: ./.github/actions/setup
- name: Doing any-job
run: npm run any-job
Check out the workflow on an actual project.
dianjuar / improve-workspace-execution-32
Improve your workflow execution by 32% just by caching the yarn installation
Improve your Workflow execution time by 32% ⚡
Using cache on dependency installation to achieve up to 32% of execution improvement (GitHub Actions)
Check blog post on Dev.To
Additional Resources / Info
This discovery was formulated, tested, and explained with numbers statically correct on ngx-deploy-npm project.
@jscutlery/semver
project is implementing this improvement
Top comments (0)