|
| 1 | +name: shake |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run several hours before the technical debt report which runs Mondays at 04:00 UTC |
| 6 | + - cron: "10 20 * * 0" # At 20:10 UTC on Sunday. |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + dry_run: |
| 10 | + description: 'If true, only scan and report without modifying files or opening a PR' |
| 11 | + required: false |
| 12 | + default: false |
| 13 | + type: boolean |
| 14 | + # auto_merge: |
| 15 | + # description: 'If true, apply the auto-merge-after-CI label when creating a PR' |
| 16 | + # required: false |
| 17 | + # default: true |
| 18 | + # type: boolean |
| 19 | + |
| 20 | +jobs: |
| 21 | + build: |
| 22 | + name: lake shake --fix |
| 23 | + runs-on: ubuntu-latest |
| 24 | + if: github.repository == 'leanprover-community/mathlib4' |
| 25 | + permissions: |
| 26 | + contents: read |
| 27 | + id-token: write |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 30 | + |
| 31 | + - name: Configure Lean |
| 32 | + uses: leanprover/lean-action@c544e89643240c6b398f14a431bcdc6309e36b3e # v1.4.0 |
| 33 | + with: |
| 34 | + auto-config: false |
| 35 | + use-github-cache: false |
| 36 | + use-mathlib-cache: true |
| 37 | + |
| 38 | + # - name: lake build |
| 39 | + # run: | |
| 40 | + # lake build Archive Counterexamples |
| 41 | + |
| 42 | + - name: lake shake |
| 43 | + id: shake |
| 44 | + run: | |
| 45 | + # Add back Archive and Counterexamples when they've been modulized |
| 46 | + lake shake --add-public --keep-implied --keep-prefix --fix --explain Mathlib > explain.txt 2>&1 |
| 47 | + if git diff --quiet; then |
| 48 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 49 | + else |
| 50 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Parse shake stats |
| 54 | + id: stats |
| 55 | + if: steps.shake.outputs.changed == 'true' |
| 56 | + run: | |
| 57 | + scripts/parse_shake_output.py explain.txt "$GITHUB_OUTPUT" |
| 58 | +
|
| 59 | + - name: Upload explain.txt |
| 60 | + id: upload-artifact |
| 61 | + if: failure() || steps.shake.outputs.changed == 'true' |
| 62 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 63 | + with: |
| 64 | + name: shake-explain |
| 65 | + path: explain.txt |
| 66 | + |
| 67 | + - name: Cleanup explain.txt |
| 68 | + if: steps.shake.outputs.changed == 'true' |
| 69 | + run: | |
| 70 | + rm -f explain.txt |
| 71 | +
|
| 72 | + - name: Build PR body |
| 73 | + id: pr_body |
| 74 | + if: steps.shake.outputs.changed == 'true' && toJson(inputs.dry_run) != 'true' |
| 75 | + shell: bash |
| 76 | + env: |
| 77 | + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 78 | + ARTIFACT_ID: ${{ steps.upload-artifact.outputs.artifact-id }} |
| 79 | + CHANGED_FILES: ${{ steps.stats.outputs.changed_files }} |
| 80 | + ADDED: ${{ steps.stats.outputs.added }} |
| 81 | + REMOVED: ${{ steps.stats.outputs.removed }} |
| 82 | + run: | |
| 83 | + { |
| 84 | + echo "body<<EOF" |
| 85 | + echo "I am happy to shake some imports for you!" |
| 86 | + echo "" |
| 87 | + echo "**${CHANGED_FILES} files changed** · +${ADDED} imports added · -${REMOVED} imports removed" |
| 88 | + echo "" |
| 89 | + echo "---" |
| 90 | + echo "" |
| 91 | + echo "[workflow run for this PR](${RUN_URL})" |
| 92 | + echo "[explain.txt](${RUN_URL}/artifacts/${ARTIFACT_ID})" |
| 93 | + echo "EOF" |
| 94 | + } >> "$GITHUB_OUTPUT" |
| 95 | +
|
| 96 | + - name: Generate app token |
| 97 | + id: app-token |
| 98 | + if: steps.shake.outputs.changed == 'true' && toJson(inputs.dry_run) != 'true' |
| 99 | + uses: leanprover-community/mathlib-ci/.github/actions/azure-create-github-app-token@3bb576208589a435eeaeac9b144a1b7c3e948760 |
| 100 | + with: |
| 101 | + app-id: ${{ secrets.MATHLIB_NOLINTS_APP_ID }} |
| 102 | + key-vault-name: ${{ vars.MATHLIB_AZ_KEY_VAULT_NAME }} |
| 103 | + key-name: mathlib-nolints-app-pk |
| 104 | + azure-client-id: ${{ vars.GH_APP_AZURE_CLIENT_ID_PR_WRITERS }} |
| 105 | + azure-tenant-id: ${{ secrets.LPC_AZ_TENANT_ID }} |
| 106 | + |
| 107 | + - name: Create Pull Request |
| 108 | + id: pr |
| 109 | + if: steps.shake.outputs.changed == 'true' && toJson(inputs.dry_run) != 'true' |
| 110 | + uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0 |
| 111 | + with: |
| 112 | + author: "mathlib-nolints[bot] <258989889+mathlib-nolints[bot]@users.noreply.github.com>" |
| 113 | + token: "${{ steps.app-token.outputs.token }}" |
| 114 | + commit-message: | |
| 115 | + chore: lake shake --add-public --keep-implied --keep-prefix --fix |
| 116 | +
|
| 117 | + ${{ steps.stats.outputs.changed_files }} files changed · +${{ steps.stats.outputs.added }} imports added · -${{ steps.stats.outputs.removed }} imports removed |
| 118 | + branch: "shake" |
| 119 | + base: master |
| 120 | + title: "chore: lake shake --add-public --keep-implied --keep-prefix --fix" |
| 121 | + body: ${{ steps.pr_body.outputs.body }} |
| 122 | + # labels: ${{ (github.event_name == 'schedule' || toJson(inputs.auto_merge) == 'true') && 'auto-merge-after-CI' || '' }} |
| 123 | + |
| 124 | + - name: Send Zulip message (success) |
| 125 | + if: steps.pr.outcome == 'success' |
| 126 | + uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 |
| 127 | + with: |
| 128 | + api-key: ${{ secrets.ZULIP_API_KEY }} |
| 129 | + email: 'github-mathlib4-bot@leanprover.zulipchat.com' |
| 130 | + organization-url: 'https://leanprover.zulipchat.com' |
| 131 | + to: 'nightly-testing-mathlib' |
| 132 | + type: 'stream' |
| 133 | + topic: 'Mathlib `shake --fix`' |
| 134 | + content: | |
| 135 | + Please review #${{ steps.pr.outputs.pull-request-number }} which changes |
| 136 | + ${{ steps.stats.outputs.changed_files }} files: |
| 137 | + - +${{ steps.stats.outputs.added }} imports added |
| 138 | + - -${{ steps.stats.outputs.removed }} imports removed |
| 139 | +
|
| 140 | + - name: Send Zulip message (failure) |
| 141 | + if: ${{ toJson(inputs.dry_run) != 'true' && failure() }} |
| 142 | + uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 |
| 143 | + with: |
| 144 | + api-key: ${{ secrets.ZULIP_API_KEY }} |
| 145 | + email: 'github-mathlib4-bot@leanprover.zulipchat.com' |
| 146 | + organization-url: 'https://leanprover.zulipchat.com' |
| 147 | + to: 'nightly-testing-mathlib' |
| 148 | + type: 'stream' |
| 149 | + topic: 'Mathlib `shake --fix`' |
| 150 | + content: | |
| 151 | + [`shake` workflow run failed](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 152 | +
|
| 153 | + triggered by: `${{ github.event_name }}` |
0 commit comments