@@ -3,8 +3,8 @@ name: rustc-pull
3
3
on :
4
4
workflow_dispatch :
5
5
schedule :
6
- # Run at 04:00 UTC every Monday
7
- - cron : ' 0 4 * * 1 '
6
+ # Run at 04:00 UTC every day
7
+ - cron : ' 0 4 * * * '
8
8
9
9
jobs :
10
10
pull :
@@ -34,15 +34,33 @@ jobs:
34
34
git config --global user.name 'The rustc-dev-guide Cronjob Bot'
35
35
git config --global user.email '[email protected] '
36
36
- name : Perform rustc-pull
37
- run : cargo run --manifest-path josh-sync/Cargo.toml -- 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}
38
54
- name : Push changes to a branch
55
+ if : ${{ steps.rustc-pull.outputs.pull_result == 'pull-finished' }}
39
56
run : |
40
57
# Update a sticky branch that is used only for rustc pulls
41
58
BRANCH="rustc-pull"
42
59
git switch -c $BRANCH
43
60
git push -u origin $BRANCH --force
44
61
- name : Create pull request
45
62
id : update-pr
63
+ if : ${{ steps.rustc-pull.outputs.pull_result == 'pull-finished' }}
46
64
run : |
47
65
# Check if an open pull request for an rustc pull update already exists
48
66
# If it does, the previous push has just updated it
54
72
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
55
73
else
56
74
PR_URL=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].url' --json url,title`
75
+ echo "Updating pull request ${PR_URL}"
57
76
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
58
77
fi
59
78
env :
@@ -64,16 +83,23 @@ jobs:
64
83
runs-on : ubuntu-latest
65
84
steps :
66
85
- name : Compute message
67
- id : message
86
+ id : create- message
68
87
run : |
69
- if [ "${{ needs.pull.result }}" == "failure" ];
70
- then
88
+ if [ "${{ needs.pull.result }}" == "failure" ]; then
71
89
WORKFLOW_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
72
90
echo "message=Rustc pull sync failed. Check out the [workflow URL]($WORKFLOW_URL)." >> $GITHUB_OUTPUT
73
91
else
74
- echo "message=Rustc pull sync succeeded. Check out the [PR](${{ needs.pull.outputs.pr_url }})." >> $GITHUB_OUTPUT
92
+ CREATED_AT=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].createdAt' --json createdAt,title`
93
+ PR_URL=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].url' --json url,title`
94
+ week_ago=$(date +%F -d '7 days ago')
95
+
96
+ # If there is an open PR that is at least a week old, post a message about it
97
+ if [[ -n $DATE_GH && $DATE_GH < $week_ago ]]; then
98
+ echo "message=A PR with a Rustc pull has been opened for more a week. Check out the [PR](${PR_URL})." >> $GITHUB_OUTPUT
99
+ fi
75
100
fi
76
101
- name : Send a Zulip message about updated PR
102
+ if : ${{ steps.create-message.outputs.message != '' }}
77
103
uses : zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5
78
104
with :
79
105
api-key : ${{ secrets.ZULIP_API_TOKEN }}
0 commit comments