I am trying to build a workflow to build the package in my repository and push
it to the GitHub repository.
I used: os: [ubuntu-20.04, windows-2019, macos-11]
inside the job matrix and this is the final part of the workflow (the repo is checked out using actions/checkout@v3
):
- name: Upload
run: |
git config --global user.email "[email protected]"
git config --global user.name "user"
git add .
git commit -m "Build"
git push
Here is one problem that I think of:
Suppose the build on Ubuntu completes first. Then it gets to the Upload
step which uploads the built files to the repository.
Another machine completes its build (say, Windows). When it tries and run git push
, won't it the repository not up to date error?
How can I fix this?
CodePudding user response:
If I understand correctly, you have 3 jobs (one for each OS) building your project and pushing the build outputs back to the repo. The repo may not be the best place to store build outputs but if that is how you need it done I would do the following:
- Instead of pushing to the repo in each matrix job instead upload an artifact using actions/upload-artifact.
- Make sure to use the OS name in the artifact name so you can tell the 3 apart. This is available via the
RUNNER_OS
environment variable.
- Add an additional job that waits for all 3 matrix jobs to complete.
- In this additional job download all 3 artifacts with actions/download-artifact
- Then push all three back to the repo together
CodePudding user response:
Add git remote origin before push command
git remote add origin https://github.com/{username}/{repository-name}.git