Skip to content

Commit

Permalink
Avoid executing contracts-docs-publish parallelly
Browse files Browse the repository at this point in the history
When `contracts-docs-publish` job is executed at a similar time for both Random
Beacon and ECDSA, it may happen that both jobs pull the
`auto-update-solidity-api-docs` branch at the same state and one of the jobs
will push a commit with updated docs, while the other won't be able to do that,
as the state of the branch will be different than when the pull happened.
The error we see in that case is following:
```
error: failed to push some refs to 'https://github.com/threshold-network/threshold.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
```
To avoid such situations we add a `contracts-docs-prepublish-wait` job to each
workflow with a step that checks if any 'Publish contracts documentation'
worklow is currently running. If it detects such job, it will wait specified
time and check again. Only when no running job is detected, the steps will
succeed and the workflow will proceed to execution of the `Publish contracts
documentation` job.
As it's likely that both `contracts-docs-prepublish-wait` jobs will be run at a
similar time. we add a 10s wait in one of them, to avoid executing both at a
moment when no `Publish contracts documentation` is run yet in any workflow.

There is still a small change that both `Publish contracts documentation` jobs
will run at similar time and cause a failure of one of them, but in that
unlikely scenario, we can always rerun the failing job and it should pass on
that second run.
  • Loading branch information
michalinacienciala committed Jun 27, 2023
1 parent c7f233c commit 27aad13
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
27 changes: 24 additions & 3 deletions .github/workflows/contracts-ecdsa-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ jobs:
commentPR: true
exportAsGHArtifacts: true

# This job is needed to avoid a clash of `contracts-docs-publish` jobs for
# `random-beacon` and `ecdsa` projects (if both are run and pull the code at
# the same time and try to push to the same branch, one of them will fail).
contracts-docs-prepublish-wait:
name: Wait for contracts docs to be published
needs: contracts-docs-publish-preview
# TODO: remove last OR
if: (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/solidity/')) || github.ref == 'refs/pull/3534/merge'
runs-on: ubuntu-latest
steps:
# We want to minimize the risk the next step executes at the same time as
# the similar step in Random Beacon.
- name: Wait 10 seconds
run: sleep 10
- name: Wait for `random-beacon` docs to be published
uses: lewagon/[email protected]
with:
ref: ${{ github.ref }}
check-name: 'Publish contracts documentation'
repo-token: ${{ secrets.GITHUB_TOKEN }}
# 120s is a value for testing purposes. TODO: change to 10s
wait-interval: 120

# This job will be triggered for releases which name starts with
# `refs/tags/solidity/`. It will generate contracts documentation in
# Markdown and sync it with a specific path of
Expand All @@ -57,9 +80,7 @@ jobs:
# commit pushing the changes will be verified using GPG key.
contracts-docs-publish:
name: Publish contracts documentation
needs: docs-detect-changes
# TODO: remove last OR
if: (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/solidity/')) || github.ref == 'refs/pull/3534/merge'
needs: [docs-detect-changes, contracts-docs-prepublish-wait]
uses: keep-network/ci/.github/workflows/reusable-solidity-docs.yml@main
with:
projectDir: /solidity/ecdsa
Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/contracts-random-beacon-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ jobs:
commentPR: true
exportAsGHArtifacts: true

# This job is needed to avoid a clash of `contracts-docs-publish` jobs for
# `random-beacon` and `ecdsa` projects (if both are run and pull the code at
# the same time and try to push to the same branch, one of them will fail).
contracts-docs-prepublish-wait:
name: Wait for contracts docs to be published
needs: contracts-docs-publish-preview
# TODO: remove last OR
if: (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/solidity/')) || github.ref == 'refs/pull/3534/merge'
runs-on: ubuntu-latest
steps:
- name: Wait for `random-beacon` docs to be published
uses: lewagon/[email protected]
with:
ref: ${{ github.ref }}
check-name: 'Publish contracts documentation'
repo-token: ${{ secrets.GITHUB_TOKEN }}
# 120s is a value for testing purposes. TODO: change to 10s
wait-interval: 120

# This job will be triggered for releases which name starts with
# `refs/tags/solidity/`. It will generate contracts documentation in
# Markdown and sync it with a specific path of
Expand All @@ -57,7 +76,7 @@ jobs:
# commit pushing the changes will be verified using GPG key.
contracts-docs-publish:
name: Publish contracts documentation
needs: docs-detect-changes
needs: [docs-detect-changes, contracts-docs-prepublish-wait]
# TODO: remove last OR
if: (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/solidity/')) || github.ref == 'refs/pull/3534/merge'
uses: keep-network/ci/.github/workflows/reusable-solidity-docs.yml@main
Expand Down

0 comments on commit 27aad13

Please sign in to comment.