Logo

dev-resources.site

for different kinds of informations.

Optimizing Parallel Jobs in a Github Workflow

Published at
3/13/2024
Categories
github
cicd
actions
Author
jpoehnelt
Categories
3 categories in total
github
open
cicd
open
actions
open
Author
9 person written this
jpoehnelt
open
Optimizing Parallel Jobs in a Github Workflow

This weekend I was trying to optimize a GitHub Actions workflow composed of three primary steps: build, preview, and test. I really wanted the build step to be followed by the in preview and test steps in parallel. My first thought was to use the actions/cache action to persist the workspace between jobs, but there was a little more boilerplate than I wanted because I didn’t need to cache between different workflow runs, only jobs for a particular commit.

So I created a new action with two child actions jpoehnelt/reusable-workspace/save and jpoehnelt/reusable-workspace/restore to simplify the process.

Performance

The usage looks like the following.

name: CI
on:
  pull_request:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      # Build steps (save should be after this)
      - uses: jpoehnelt/reusable-workspace/save@v1
  preview:
    needs: [build]
    runs-on: ubuntu-latest
    steps:
      - uses: jpoehnelt/reusable-workspace/restore@v1
      # Additional steps (restore should be before this)
  test:
    needs: [build]
    runs-on: ubuntu-latest
    steps:
      - uses: jpoehnelt/reusable-workspace/restore@v1
        with:
          fail-on-miss: true
      # Additional steps (restore should be before this)
Enter fullscreen mode Exit fullscreen mode

My workflow now runs the build and then the preview and test steps in parallel. The preview job can also use a matrix without needing to rebuild the workspace after this change.

Optimized parallel jobs in a GitHub workflow

This new action is a great way to optimize your GitHub Actions workflows and reduce the time it takes to run your CI/CD pipeline. I hope you find it useful, just include the following:

- uses: jpoehnelt/reusable-workspace/restore@v1
- uses: jpoehnelt/reusable-workspace/save@v1
Enter fullscreen mode Exit fullscreen mode
actions Article's
30 articles in total
Favicon
How to upload Markdown files to Dev.to from GitHub
Favicon
How to Configure GitHub Actions CI for Python Using Poetry on Multiple Versions
Favicon
Proposal: Standard Communication API Channels for AI Agents (AI Generated)
Favicon
Understanding GitHub Actions Working Directory
Favicon
Automating Mastodon Posts with GitHub Actions
Favicon
Getting Started with GitHub Actions: A Beginner's Guide to Automation
Favicon
Configure GitHub for Dev.to Publishing
Favicon
Getting Started with GitHub Actions: A Beginner's Guide to Automation
Favicon
Configure GitHub for Dev.to Publishing
Favicon
github action services: mysql, redis and elasticsearch
Favicon
Future-Proofing Your Auth0 Integration: Moving from Rules and Hooks to Actions
Favicon
6 GitHub Actions Every DevOps Team Needs
Favicon
GitHub Workflow and Automation: Streamlining Project Management 🚀
Favicon
Server actions in Next.js
Favicon
Actions - React 19
Favicon
NextJs Server Actions: Why and How
Favicon
The truth about Mindset and how it can influence your actions positively
Favicon
Optimizing Parallel Jobs in a Github Workflow
Favicon
How to set preconfigured actions in the CloudBees platform
Favicon
Auto-deploy docker images to Docker Hub using GitHub actions
Favicon
Secure NextJS Server Actions Using Body Validation
Favicon
Github action to detect ip addresses
Favicon
Vegaration: Visualising continuous integration using Github actions and vega-lite
Favicon
GitHub Action for Commit Message Validation
Favicon
Query GitHub Repo Topics Using GraphQL
Favicon
Setup a Dynamic GitHub User Profile README
Favicon
How to publish React App (CRA) on Github Pages using Github Actions with Turborepo
Favicon
Guide: Automate the deployment of a virtual machine on AWS using Terraform and Github Actions
Favicon
Netlify Nextjs Deployment — Page Not Found Issue Solution
Favicon
Github Actions

Featured ones: