| 
9 | 9 | jobs:  | 
10 | 10 |   pull:  | 
11 | 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 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 'github-actions@github.com'  | 
36 |  | -      - name: Perform rustc-pull  | 
37 |  | -        id: rustc-pull  | 
38 |  | -        # Turn off -e to disable early exit  | 
39 |  | -        shell: bash {0}  | 
40 |  | -        run: |  | 
41 |  | -          cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull  | 
42 |  | -          exitcode=$?  | 
43 |  | -
  | 
44 |  | -          # If no pull was performed, we want to mark this job as successful,  | 
45 |  | -          # but we do not want to perform the follow-up steps.  | 
46 |  | -          if [ $exitcode -eq 0 ]; then  | 
47 |  | -            echo "pull_result=pull-finished" >> $GITHUB_OUTPUT  | 
48 |  | -          elif [ $exitcode -eq 2 ]; then  | 
49 |  | -            echo "pull_result=skipped" >> $GITHUB_OUTPUT  | 
50 |  | -            exitcode=0  | 
51 |  | -          fi  | 
52 |  | -
  | 
53 |  | -          exit ${exitcode}  | 
54 |  | -      - name: Push changes to a branch  | 
55 |  | -        if: ${{ steps.rustc-pull.outputs.pull_result == 'pull-finished' }}  | 
56 |  | -        run: |  | 
57 |  | -          # Update a sticky branch that is used only for rustc pulls  | 
58 |  | -          BRANCH="rustc-pull"  | 
59 |  | -          git switch -c $BRANCH  | 
60 |  | -          git push -u origin $BRANCH --force  | 
61 |  | -      - name: Create pull request  | 
62 |  | -        id: update-pr  | 
63 |  | -        if: ${{ steps.rustc-pull.outputs.pull_result == 'pull-finished' }}  | 
64 |  | -        env:  | 
65 |  | -          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  | 
66 |  | -        run: |  | 
67 |  | -          # Check if an open pull request for an rustc pull update already exists  | 
68 |  | -          # If it does, the previous push has just updated it  | 
69 |  | -          # If not, we create it now  | 
70 |  | -          RESULT=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | length' --json title`  | 
71 |  | -          if [[ "$RESULT" -eq 0 ]]; then  | 
72 |  | -            echo "Creating new pull request"  | 
73 |  | -            PR_URL=`gh pr create -B master --title 'Rustc pull update' --body 'Latest update from rustc.'`  | 
74 |  | -            echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT  | 
75 |  | -          else  | 
76 |  | -            PR_URL=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].url' --json url,title`  | 
77 |  | -            echo "Updating pull request ${PR_URL}"  | 
78 |  | -            echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT  | 
79 |  | -          fi  | 
80 |  | -  send-zulip-message:  | 
81 |  | -    needs: [pull]  | 
82 |  | -    if: ${{ !cancelled() }}  | 
83 |  | -    runs-on: ubuntu-latest  | 
84 |  | -    steps:  | 
85 |  | -      - uses: actions/checkout@v4  | 
86 |  | -      - name: Compute message  | 
87 |  | -        id: create-message  | 
88 |  | -        env:  | 
89 |  | -          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  | 
90 |  | -        run: |  | 
91 |  | -          if [ "${{ needs.pull.result }}" == "failure" ]; then  | 
92 |  | -            WORKFLOW_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"  | 
93 |  | -            echo "message=Rustc pull sync failed. Check out the [workflow URL]($WORKFLOW_URL)." >> $GITHUB_OUTPUT  | 
94 |  | -          else  | 
95 |  | -            CREATED_AT=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].createdAt' --json createdAt,title`  | 
96 |  | -            PR_URL=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].url' --json url,title`  | 
97 |  | -            week_ago=$(date +%F -d '7 days ago')  | 
98 |  | -
  | 
99 |  | -            # If there is an open PR that is at least a week old, post a message about it  | 
100 |  | -            if [[ -n $DATE_GH && $DATE_GH < $week_ago ]]; then  | 
101 |  | -              echo "message=A PR with a Rustc pull has been opened for more a week. Check out the [PR](${PR_URL})." >> $GITHUB_OUTPUT  | 
102 |  | -            fi  | 
103 |  | -          fi  | 
104 |  | -      - name: Send a Zulip message about updated PR  | 
105 |  | -        if: ${{ steps.create-message.outputs.message != '' }}  | 
106 |  | -        uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5  | 
107 |  | -        with:  | 
108 |  | -          api-key: ${{ secrets.ZULIP_API_TOKEN }}  | 
109 |  | -          email: "rustc-dev-guide-gha-notif-bot@rust-lang.zulipchat.com"  | 
110 |  | -          organization-url: "https://rust-lang.zulipchat.com"  | 
111 |  | -          to: 196385  | 
112 |  | -          type: "stream"  | 
113 |  | -          topic: "Subtree sync automation"  | 
114 |  | -          content: ${{ steps.create-message.outputs.message }}  | 
 | 12 | +    uses: rust-lang/josh-sync/.github/workflows/rustc-pull.yml@main  | 
 | 13 | +    with:  | 
 | 14 | +      zulip-stream-id: 196385  | 
 | 15 | +      zulip-bot-email:  "rustc-dev-guide-gha-notif-bot@rust-lang.zulipchat.com"  | 
 | 16 | +      pr-base-branch: master  | 
 | 17 | +      branch-name: rustc-pull  | 
 | 18 | +    secrets:  | 
 | 19 | +      zulip-api-token: ${{ secrets.ZULIP_API_TOKEN }}  | 
 | 20 | +      token: ${{ secrets.GITHUB_TOKEN }}  | 
0 commit comments