lock0 #21
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Enforce Lockfile Status | |
on: [ push, pull_request_target] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref || github.run_id }} | |
cancel-in-progress: true | |
env: | |
PYTHON_VERSION: '3.13' # renovate: datasource=python-version depName=python | |
UV_VERSION: 0.5.18 # renovate: datasource=pypi depName=uv | |
jobs: | |
lock: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: check for mergeability | |
if: github.event_name == 'pull_request_target' | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
# Retry the API query this many times | |
retryCount=3 | |
# Start with 5 seconds, but double every retry | |
retryInterval=5 | |
while true; do | |
echo "Checking whether the pull request can be merged" | |
prInfo=$(gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/"$GITHUB_REPOSITORY"/pulls/${{ github.event.pull_request.number }}) | |
mergeable=$(jq -r .mergeable <<< "$prInfo") | |
mergedSha=$(jq -r .merge_commit_sha <<< "$prInfo") | |
if [[ "$mergeable" == "null" ]]; then | |
if (( retryCount == 0 )); then | |
echo "Not retrying anymore, probably GitHub is having internal issues" | |
exit 1 | |
else | |
(( retryCount -= 1 )) || true | |
# null indicates that GitHub is still computing whether it's mergeable | |
# Wait a couple seconds before trying again | |
echo "GitHub is still computing whether this PR can be merged, waiting $retryInterval seconds before trying again ($retryCount retries left)" | |
sleep "$retryInterval" | |
(( retryInterval *= 2 )) || true | |
fi | |
else | |
break | |
fi | |
done | |
if [[ "$mergeable" == "true" ]]; then | |
echo "The PR can be merged, checking the merge commit $mergedSha" | |
else | |
echo "The PR cannot be merged, it has a merge conflict, cancelling the workflow.." | |
gh api \ | |
--method POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/"$GITHUB_REPOSITORY"/actions/runs/"$GITHUB_RUN_ID"/cancel | |
sleep 60 | |
# If it's still not canceled after a minute, something probably went wrong, just exit | |
exit 1 | |
fi | |
echo "mergedSha=$mergedSha" >> "$GITHUB_ENV" | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
if: github.event_name == 'pull_request_target' | |
with: | |
ref: ${{ github.event.pull_request.merge_commit_sha }} | |
path: merge | |
- name: Install uv | |
uses: astral-sh/setup-uv@887a942a15af3a7626099df99e897a18d9e5ab3a # v5 | |
with: | |
enable-cache: true | |
python-version: ${{ env.PYTHON_VERSION }} | |
version: ${{ env.UV_VERSION }} | |
- run: | | |
if [[ ${{github.event_name}} == "push" ]] | |
then | |
uv lock | |
else | |
uv lock --directory merge | |
mv merge/uv.lock uv.lock | |
fi | |
git config user.email github-actions[bot]@users.noreply.github.com | |
git config user.name github-actions[bot] | |
if ! git diff --exit-code | |
then | |
git add uv.lock | |
git commit -m "enforce lockfile status" | |
git push | |
fi |