Let’s suppose I’m working on a React Native project.
As part of my workflow, I’d like to build both iOS and Android versions of the app, both build jobs will share the step of cloning the repo, installing dependencies, etc. Installing dependencies takes quite a while.
I know bitbucket pipelines offers a way to run a series of parent tasks before running parallel tasks. Does github actions provide something similar? I’d like to deduplicate the common tasks (like npm install) between the two jobs.
P.S github actions are a lot better than bitbucket pipelines (yay macOS containers)
What is your purpose? What time do you want to save?
If the build jobs for iOS and Android are in parallel, you seem do not need to some pre-tasks to install the dependencies. You can run the installation of the dependencies on each build job, they do not take twice as long because they are running in the parallel jobs.
That’s true that the overall runtime will be the same, however it seems like it would use unnecessary build minutes, no?
Sorry, should have clarified that.
For example, if installing dependencies takes 5 minutes and app build takes 10 minutes, if we could DRY up the dependency install process, it would only use 25 build minutes. Alternatively, having it run in parallel will use up 30 build minutes. Both would complete in 15 minutes but the latter would take up more Action minutes.
Over time, it adds up and uses up our allotted minutes.
When the two build jobs run in parallel in the workflow,that means they start running almost at the same time, not one job waiting for another job to complete, and they should be running on separate runners. So the whole run-time of the workflow is not determined by the sum of the two jobs, it should be determined by the longest running job.
Only if you set these two jobs to run on the same self-hosted runner, this will cause one job waiting for another job to complete.
In addition, generally the same dependency may have different configurations on diferent platforms, if install the same dependency with same configurations on different platforms, it may cause incompatibilities on some platforms.
If you really want to run some common pre-tasks to install the dependencies, you can try using the cache action to do that, more details you can reference Caching dependencies to speed up workflows.
In addition, you also can try using artifacts.
Cache can share data between jobs and workfkows, artifacts share data between jobs in the same workfkows.