Skip to content

Commit 0549d8c

Browse files
authored
Merge pull request #2502 from Kobzol/rustc-josh-sync-ci
2 parents 23d74cf + 82c5c43 commit 0549d8c

File tree

1 file changed

+9
-102
lines changed

1 file changed

+9
-102
lines changed

.github/workflows/rustc-pull.yml

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

Comments
 (0)