fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
4.5 KiB142 linesraw
1# Automatically run `cargo update` periodically
2
3---
4name: Bump dependencies in Cargo.lock
5on:
6  schedule:
7    # Run weekly
8    - cron: '0 0 * * Sun'
9  workflow_dispatch:
10    # Needed so we can run it manually
11permissions:
12  contents: read
13defaults:
14  run:
15    shell: bash
16env:
17  # So cargo doesn't complain about unstable features
18  RUSTC_BOOTSTRAP: 1
19  PR_TITLE: Weekly `cargo update`
20  PR_MESSAGE: |
21    Automation to keep dependencies in `Cargo.lock` current.
22
23    The following is the output from `cargo update`:
24  COMMIT_MESSAGE: "cargo update \n\n"
25
26jobs:
27  not-waiting-on-bors:
28    if: github.repository_owner == 'rust-lang'
29    name: skip if S-waiting-on-bors
30    runs-on: ubuntu-latest
31    steps:
32      - env:
33          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34        run: |
35          # Fetch state and labels of PR
36          # Or exit successfully if PR does not exist
37          JSON=$(gh pr view cargo_update --repo $GITHUB_REPOSITORY --json labels,state || exit 0)
38          STATE=$(echo "$JSON" | jq -r '.state')
39          WAITING_ON_BORS=$(echo "$JSON" | jq '.labels[] | any(.name == "S-waiting-on-bors"; .)')
40
41          # Exit with error if open and S-waiting-on-bors
42          if [[ "$STATE" == "OPEN" && "$WAITING_ON_BORS" == "true" ]]; then
43            exit 1
44          fi
45
46  update:
47    if: github.repository_owner == 'rust-lang'
48    name: update dependencies
49    needs: not-waiting-on-bors
50    runs-on: ubuntu-latest
51    steps:
52      - name: checkout the source code
53        uses: actions/checkout@v4
54        with:
55          submodules: recursive
56      - name: install the bootstrap toolchain
57        run: |
58          # Extract the stage0 version
59          TOOLCHAIN=$(jq -r '.compiler | {version,date} | join("-")' -- src/stage0.json)
60          # Install and set as default
61          rustup toolchain install --no-self-update --profile minimal $TOOLCHAIN
62          rustup default $TOOLCHAIN
63
64      - name: cargo update
65        # Remove first line that always just says "Updating crates.io index"
66        run: cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
67      - name: upload Cargo.lock artifact for use in PR
68        uses: actions/upload-artifact@v3
69        with:
70          name: Cargo-lock
71          path: Cargo.lock
72          retention-days: 1
73      - name: upload cargo-update log artifact for use in PR
74        uses: actions/upload-artifact@v3
75        with:
76          name: cargo-updates
77          path: cargo_update.log
78          retention-days: 1
79
80  pr:
81    if: github.repository_owner == 'rust-lang'
82    name: amend PR
83    needs: update
84    runs-on: ubuntu-latest
85    permissions:
86      contents: write
87      pull-requests: write
88    steps:
89      - name: checkout the source code
90        uses: actions/checkout@v4
91
92      - name: download Cargo.lock from update job
93        uses: actions/download-artifact@v3
94        with:
95          name: Cargo-lock
96      - name: download cargo-update log from update job
97        uses: actions/download-artifact@v3
98        with:
99          name: cargo-updates
100
101      - name: craft PR body and commit message
102        run: |
103          echo "${COMMIT_MESSAGE}" > commit.txt
104          cat cargo_update.log >> commit.txt
105
106          echo "${PR_MESSAGE}" > body.md
107          echo '```txt' >> body.md
108          cat cargo_update.log >> body.md
109          echo '```' >> body.md
110
111      - name: commit
112        run: |
113          git config user.name github-actions
114          git config user.email github-actions@github.com
115          git switch --force-create cargo_update
116          git add ./Cargo.lock
117          git commit --no-verify --file=commit.txt
118
119      - name: push
120        run: git push --no-verify --force --set-upstream origin cargo_update
121
122      - name: edit existing open pull request
123        id: edit
124        # Don't fail job if we need to open new PR
125        continue-on-error: true
126        env:
127          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
128        run: |
129          # Exit with error if PR is closed
130          STATE=$(gh pr view cargo_update --repo $GITHUB_REPOSITORY --json state --jq '.state')
131          if [[ "$STATE" != "OPEN" ]]; then
132            exit 1
133          fi
134
135          gh pr edit cargo_update --title "${PR_TITLE}" --body-file body.md --repo $GITHUB_REPOSITORY
136
137      - name: open new pull request
138        # Only run if there wasn't an existing PR
139        if: steps.edit.outcome != 'success'
140        env:
141          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
142        run: gh pr create --title "${PR_TITLE}" --body-file body.md --repo $GITHUB_REPOSITORY