GitHub Actions Optimization Techniques

Good day. It's Friday, Aug. 30, and in this issue, we're covering:

  • GitHub Actions Optimization Techniques

  • How Meta enforces purpose limitation via Privacy Aware Infrastructure at scale

  • Google Introducing delayed destruction, a new way to protect your secrets

  • Reverse Terraforming Using Terraformer

  • Database Automation for Modern DevOps Practices

  • A Guide to Modern Kubernetes Service Networking

Use Case

GitHub Actions Optimization Techniques

While multiple production deployments in a day is routine for many companies, there are still teams that struggle with building bulk dependencies that take the build times forever.

This is for them..

1. Speed Up Your Workflows with Caching:

Just by implementing cache in a sample project,

I reduced build time from 5m 29s to 2m 12s - A whopping 60%.

And the installation of dependencies time reduced from 5m 17s to 1m 38s - A 69% improvement.

We all know, Caching allows you to save dependencies and other commonly used data between workflow runs, significantly cutting down the time needed for repeated tasks.

Instead of doing this:

  • Install build essentials

  • Install dependencies

  • Run application script

Do this:

  • Install build essentials

  • Cache dependencies

  • Install dependencies

  • Run application script

GitHub Actions snippet without Caching:

- name: Install build essentials
     run: sudo apt-get update && sudo apt-get install -y python3-distutils python3-dev build-essential

- name: Install dependencies
     run: |
       python -m pip install --upgrade pip
       pip install -r requirements.txt

- name: Run Python script
     run: |
       python main.py

GitHub Actions Config with Caching:

- name: Install build essentials
     run: sudo apt-get update && sudo apt-get install -y python3-distutils python3-dev build-essential

- name: Cache dependencies
     uses: actions/cache@v4
     with:
       path: ~/.cache/pip
       key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
       restore-keys: |
         ${{ runner.os }}-pip-

- name: Install dependencies
     run: |
       python -m pip install --upgrade pip
       pip install -r requirements.txt

- name: Run Python script
     run: |
       python main.py

The above example is for pip. Adjust the path and key according to your project's dependency management (e.g., ~/.m2 for Maven, ~/.gradle for Gradle).

2. Simplify Workflow Management with Reusable Workflows:

Reusable workflows enable you to consolidate shared processes, making them easily applicable across multiple workflows. This approach minimizes repetition and boosts the overall maintainability of your workflow configurations.

An example:

# .github/workflows/reusable-workflow.yaml
name: Reusable Workflow
on: workflow_call

jobs:
  reusable-job:
    runs-on: ubuntu-latest
    steps:
      - name: Print message
        run: echo "Reusable workflow executed"

You can now call this workflow from any other workflow within your repository.

name: Use Reusable Workflow
on: [push]
jobs:
  execute-reusable:
    uses: your-org/repo/.github/workflows/reusable-workflow.yaml@main

These are very simple to understand and implement.

Remember, often the most simple solutions do great magic. We just overlook them.

p.s. if you think someone else you know may like this newsletter, share with them to join here

Tool Of The Day

Mixeway Flow - Repository containing source code of MixewayFlow service that is Swiss army knife for DevSecOps Teams

Trends & Updates

Resources & Tutorials

Picture Of The Day

Did someone forward this email to you? Sign up here

Interested in reaching smart techies?

Our newsletter puts your products and services in front of the right people - engineering leaders and senior engineers - who make important tech decisions and big purchases.