|
| 1 | +name: rustc-pull |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + # Run at 04:00 UTC every Monday |
| 7 | + - cron: '0 4 * * 1' |
| 8 | + |
| 9 | +jobs: |
| 10 | + pull: |
| 11 | + if: github.repository == 'rust-lang/rustc-dev-guide' |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + pr_url: ${{ steps.update-pr.outputs.pr_url }} |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + # We need the full history for josh to work |
| 22 | + fetch-depth: '0' |
| 23 | + - name: Install stable Rust toolchain |
| 24 | + run: rustup update stable |
| 25 | + - uses: Swatinem/rust-cache@v2 |
| 26 | + with: |
| 27 | + workspaces: "josh-sync" |
| 28 | + # Cache the josh directory with checked out rustc |
| 29 | + cache-directories: "/home/runner/.cache/rustc-dev-guide-josh" |
| 30 | + - name: Install josh |
| 31 | + run: RUSTFLAGS="--cap-lints warn" cargo +stable install josh-proxy --git https://github.com/josh-project/josh --tag r24.10.04 |
| 32 | + - name: Setup bot git name and email |
| 33 | + run: | |
| 34 | + git config --global user.name 'The rustc-dev-guide Cronjob Bot' |
| 35 | + git config --global user.email '[email protected]' |
| 36 | + - name: Perform rustc-pull |
| 37 | + run: cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull |
| 38 | + - name: Push changes to a branch |
| 39 | + run: | |
| 40 | + # Update a sticky branch that is used only for rustc pulls |
| 41 | + BRANCH="rustc-pull" |
| 42 | + git switch -c $BRANCH |
| 43 | + git push -u origin $BRANCH --force |
| 44 | + - name: Create pull request |
| 45 | + id: update-pr |
| 46 | + run: | |
| 47 | + # Check if an open pull request for an rustc pull update already exists |
| 48 | + # If it does, the previous push has just updated it |
| 49 | + # If not, we create it now |
| 50 | + RESULT=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | length' --json title` |
| 51 | + if [[ "$RESULT" -eq 0 ]]; then |
| 52 | + echo "Creating new pull request" |
| 53 | + PR_URL=gh pr create -B master --title 'Rustc pull update' --body 'Latest update from rustc.' |
| 54 | + echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT |
| 55 | + else |
| 56 | + PR_URL=gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].url' --json url,title |
| 57 | + echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT |
| 58 | + fi |
| 59 | + env: |
| 60 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + send-zulip-message: |
| 62 | + needs: [pull] |
| 63 | + if: ${{ !cancelled() }} |
| 64 | + runs-on: ubuntu-latest |
| 65 | + steps: |
| 66 | + - name: Compute message |
| 67 | + id: message |
| 68 | + run: | |
| 69 | + if [ "${{ needs.pull.result }}" == "failure" ]; |
| 70 | + then |
| 71 | + WORKFLOW_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 72 | + echo "message=Rustc pull sync failed. Check out the [workflow URL]($WORKFLOW_URL)." >> $GITHUB_OUTPUT |
| 73 | + else |
| 74 | + echo "message=Rustc pull sync succeeded. Check out the [PR](${{ needs.pull.outputs.pr_url }})." >> $GITHUB_OUTPUT |
| 75 | + fi |
| 76 | + - name: Send a Zulip message about updated PR |
| 77 | + uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 |
| 78 | + with: |
| 79 | + api-key: ${{ secrets.ZULIP_API_TOKEN }} |
| 80 | + |
| 81 | + organization-url: "https://rust-lang.zulipchat.com" |
| 82 | + to: 196385 |
| 83 | + type: "stream" |
| 84 | + topic: "Subtree sync automation" |
| 85 | + content: ${{ steps.message.outputs.message }} |
0 commit comments