|
| 1 | +name: Automated Mypy Version Sync |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 0 * * *" |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + actions: write |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + issues: read |
| 13 | + |
| 14 | +jobs: |
| 15 | + update-mypy-version: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v5 |
| 20 | + |
| 21 | + - name: Set up Python |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: "3.13" |
| 25 | + |
| 26 | + - name: Update Mypy version in requirements.txt |
| 27 | + run: | |
| 28 | + MYPY_VERSION=$(pip index versions --json mypy | jq -r '.latest' | cat) |
| 29 | + echo "VERSION=${MYPY_VERSION}" >> "$GITHUB_ENV" |
| 30 | + sed -i "s/^mypy=.*/mypy==$MYPY_VERSION/" requirements.txt |
| 31 | +
|
| 32 | + - name: Check for changes |
| 33 | + id: compare |
| 34 | + shell: bash |
| 35 | + run: | |
| 36 | + if git diff -s --exit-code; then |
| 37 | + echo "update_needed=false" >> "$GITHUB_OUTPUT" |
| 38 | + else |
| 39 | + echo "update_needed=true" >> "$GITHUB_OUTPUT" |
| 40 | + fi |
| 41 | +
|
| 42 | + - name: Setup git identity and branch name |
| 43 | + if: steps.compare.outputs.update_needed == 'true' |
| 44 | + shell: bash |
| 45 | + run: | |
| 46 | + git config user.name "github-actions[bot]" |
| 47 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 48 | + echo "BRANCH_NAME=update-mypy-version-${{ env.VERSION }}" >> "$GITHUB_ENV" |
| 49 | +
|
| 50 | + - name: Commit changes |
| 51 | + if: steps.compare.outputs.update_needed == 'true' |
| 52 | + shell: bash |
| 53 | + run: | |
| 54 | + git commit -am "Automated update to mypy==${{ env.VERSION }}" |
| 55 | +
|
| 56 | + - name: Bump version version.txt |
| 57 | + if: steps.compare.outputs.update_needed == 'true' |
| 58 | + shell: bash |
| 59 | + run: | |
| 60 | + v=$(<version.txt); IFS=. read -r x y z <<<"$v"; echo "$x.$y.$((z+1))" > version.txt |
| 61 | + git commit version.txt -m "Bump version $v -> $(<version.txt)" |
| 62 | +
|
| 63 | + - name: Push changes |
| 64 | + if: steps.compare.outputs.update_needed == 'true' |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + git checkout -b "${{ env.BRANCH_NAME }}" || true |
| 68 | + git pull origin "${{ env.BRANCH_NAME }}" --no-edit --rebase=true -X ours || true |
| 69 | + git push origin "${{ env.BRANCH_NAME }}" |
| 70 | +
|
| 71 | + - name: Create Pull Request |
| 72 | + if: steps.compare.outputs.update_needed == 'true' |
| 73 | + shell: bash |
| 74 | + env: |
| 75 | + GH_TOKEN: ${{ github.token }} |
| 76 | + run: | |
| 77 | + (gh pr create \ |
| 78 | + --title "Automated mypy version sync" \ |
| 79 | + --body "Update mypy version to ${{ env.VERSION }}" \ |
| 80 | + --head "${{ env.BRANCH_NAME }}" \ |
| 81 | + --base master && \ |
| 82 | + gh pr merge \ |
| 83 | + --auto \ |
| 84 | + --merge "${{ env.BRANCH_NAME }}") || true |
0 commit comments