fix #40
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
# If you rename or move this file, you MUST update the filename used for YAML parsing below. | |
name: Autofix | |
on: | |
push: | |
branches: | |
- develop | |
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 | |
# If you rename env.UV_VERSION, you MUST update the YAML parsing below as well. | |
UV_VERSION: 0.5.22 # renovate: datasource=pypi depName=uv | |
jobs: | |
uv-lock: | |
name: Update uv.lock | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the HEAD commit | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
with: | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
ref: ${{ github.head_ref }} | |
token: ${{ secrets.FLEXGETBOT_PAT }} | |
path: HEAD | |
- name: Resolve the merge commit | |
id: resolve-merge-commit | |
if: github.event_name == 'pull_request_target' | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
retryCount=3 | |
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, this PR may have already been closed" | |
exit 1 | |
else | |
(( retryCount -= 1 )) || true | |
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 | |
exit 1 | |
fi | |
echo "merge-sha=$mergedSha" >> "$GITHUB_OUTPUT" | |
- name: Checkout the merge commit | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
if: github.event_name == 'pull_request_target' | |
with: | |
ref: ${{ steps.resolve-merge-commit.outputs.merge-sha }} | |
path: merge | |
- name: Extract the uv version in the merge commit | |
if: github.event_name == 'pull_request_target' | |
id: merge-commit-uv-version | |
uses: mikefarah/yq@master | |
with: | |
cmd: yq .env.UV_VERSION merge/.github/workflows/autofix.yml | |
- name: Install uv and Python | |
uses: astral-sh/setup-uv@b5f58b2abc5763ade55e4e9d0fe52cd1ff7979ca # v5 | |
with: | |
enable-cache: true | |
python-version: ${{ env.PYTHON_VERSION }} | |
version: ${{ steps.merge-commit-uv-version.outputs.result || env.UV_VERSION }} | |
- name: Run uv lock | |
run: | | |
if [[ ${{github.event_name}} == "push" ]]; then | |
uv lock --directory HEAD | |
else | |
uv lock --directory merge | |
mv merge/uv.lock HEAD/uv.lock | |
fi | |
- name: Push changes | |
id: push | |
run: | | |
cd HEAD | |
git add uv.lock | |
if ! git diff --cached --exit-code; then | |
git config user.email github-actions[bot]@users.noreply.github.com | |
git config user.name github-actions[bot] | |
git commit -m "Autofix: update uv.lock" | |
git push | |
fi | |
- name: Add a comment if permission denied | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 | |
if: failure() && steps.push.conclusion == 'failure' | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `The \`uv.lock\` file is missing or needs to be updated and we can't auto-fix it for you because you didn't check the 'Allow edits by maintainers' box. | |
Please check the box and push again or manually run \`uv lock\`.` | |
}) |