skip to Main Content

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?

2

Answers


  1. Add git remote origin before push command

    git remote add origin https://github.com/{username}/{repository-name}.git

    Login or Signup to reply.
  2. 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:

    1. 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.
    1. 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
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search