-
Notifications
You must be signed in to change notification settings - Fork 78
139 lines (118 loc) · 3.95 KB
/
sync_branch.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: sync main with dev
on:
push:
# schedule:
# - 0 8 * * * # Runs at 8am UTC
defaults:
run:
shell: bash -x -e -u -o pipefail {0}
jobs:
sync-branches-via-rebase:
runs-on: ubuntu-latest
name: syncing main with dev
outputs:
date: ${{ steps.date.outputs.date }}
commit-delta: ${{ steps.commit-delta.outputs.main }}
environment: main
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ko3n1g/dev
fetch-depth: 0
token: ${{ secrets.PAT }}
- name: Get todays date
id: date
run: |
DATE=$(date +"%Y-%m-%d")
echo "date=$DATE" | tee -a "$GITHUB_OUTPUT"
- name: Get commit delta
id: commit-delta
run: |
git fetch origin main:main
DELTA=$(git cherry -v ko3n1g/dev main | tr '+' '*')
DELTA=$(echo "${DELTA//$'\n'/<<<NEWLINE>>>}")
echo "main=$DELTA" | tee -a "$GITHUB_OUTPUT"
- name: Attempt rebase
run: |
git config --global user.email "[email protected]"
git config --global user.name "NVIDIA NeMo Bot"
git fetch origin main
git rebase origin/main
git push --force
notify-success:
runs-on: ubuntu-latest
if: success()
needs: [sync-branches-via-rebase]
env:
DATE: ${{ needs.sync-branches-via-rebase.outputs.date }}
steps:
- name: Find PR
id: fp
env:
REPOSITORY: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
run: |
set +x
PRs=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$REPOSITORY/pulls)
PR_NUMBER=$(echo -E "$PRs" \
| jq '.[]
| select(.head.ref == "ko3n1g/dev")
| .number'
)
set -x
echo "pr-number=$PR_NUMBER" | tee -a "$GITHUB_OUTPUT"
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ steps.fp.outputs.pr-number }}
body-includes: <!-- auto-rebase-message -->
- name: Parse output
run: |
DELTA=${{ needs.sync-branches-via-rebase.outputs.commit-delta }}
DELTA=$(echo "${DELTA//<<<NEWLINE>>>/\n}")
echo "COMMIT_DELTA<<EOF" >> $GITHUB_ENV
echo "$DELTA" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Add PR comment for PyLint
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ steps.fp.outputs.pr-number }}
edit-mode: replace
body: |
<!-- auto-rebase-message -->
beep boop 🤖: This branch was last rebased onto `main` on ${{ env.DATE }}.
---
📢✨🪄 Updated commits:
```
${{ env.COMMIT_DELTA }}
```
notify-failure:
runs-on: ubuntu-latest
if: failure()
needs: [sync-branches-via-rebase]
env:
RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
SLACK_WEBHOOK_ADMIN: "<!subteam^${{ secrets.SLACK_WEBHOOK_ADMIN }}>"
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
DATE: ${{ needs.sync-branches-via-rebase.outputs.date }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: NVIDIA/NeMo-FW-CI-templates
ref: v0.5.0
path: send-slack-alert
# - name: Send Slack alert
# uses: ./send-slack-alert/.github/actions/send-slack-alert
# with:
# message: >
# Daily <${{ env.RUN_URL }}|sync main with dev> has failed for ${{ env.DATE }}.
# cc: ${{ env.SLACK_WEBHOOK_ADMIN }}
# webhook: ${{ env.SLACK_WEBHOOK }}