Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/praveenpuglia/gh-actions-parallel-jobs
Run parallel builds for a single project with shared dependencies in GitHub Actions
https://github.com/praveenpuglia/gh-actions-parallel-jobs
actions build cache parallel workflow
Last synced: about 1 month ago
JSON representation
Run parallel builds for a single project with shared dependencies in GitHub Actions
- Host: GitHub
- URL: https://github.com/praveenpuglia/gh-actions-parallel-jobs
- Owner: praveenpuglia
- License: mit
- Created: 2024-09-12T14:22:40.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-21T09:35:46.000Z (4 months ago)
- Last Synced: 2024-11-26T22:35:57.905Z (about 1 month ago)
- Topics: actions, build, cache, parallel, workflow
- Language: TypeScript
- Homepage:
- Size: 44.9 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# GitHub Actions - Parallel Jobs with Dependency Sharing
Often times, especially in a multi-tenant architecture, it's expected to have one repository from where multiple builds are generated for different clients / architectures etc. Running separate actions for each of these different clients can be expensive and tricky if we have to download dependencies for every build again and again.
In this repo, I have solved this problem using two different approaches. Although the example uses a node project, the idea can be applied to all sorts of projects.
## Approach 1 - Using Upload Artifacts Action
In this approach, we use the https://github.com/actions/upload-artifact action to compress the `node_modules` directory after the dependencies are installed and upload it to artifact repository on GitHub. In the subsequent jobs, we pull in the same artifact, extract it and use it instead of reinstalling them for every build of the project.
Check [build-using-artifacts.yml](./.github/workflows/build-using-artifacts.yml).
## Approach 2 - Using Cache Action
In this approach, we use the https://github.com/actions/cache action to cache the `node_modules` directory across jobs. We cache the directory against the hash of the package-lock.json file and as long as the lock file hasn't changed, the same cache of `node_modules` is used.
This approach is at least as optimized as the artifacts approach since package-lock.json file doesn't always change with every run of the workflow in the real world.Check [build-using-cache.yml](./.github/workflows/build-using-cache.yml).
# Credits
Thanks to [Abhay Sharma](https://github.com/Daggron) for contributing ideas and helping me test them out.