-
Notifications
You must be signed in to change notification settings - Fork 1.3k
112 lines (98 loc) · 5.89 KB
/
create-upmerge-PRs.yml
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
name: Zephyr upmerge
# on:
# schedule:
# - cron: "0 0 * * *"
on: workflow_dispatch
env:
GH_TOKEN: ${{ secrets.NCS_GITHUB_UPMERGE_TOKEN }}
ZEPHYR_UPSTREAM: https://github.com/zephyrproject-rtos/zephyr
MCUBOOT_UPSTREAM: https://github.com/zephyrproject-rtos/mcuboot
PR_TARGET_BRANCH: upmerge-tmp
jobs:
auto-upmerge-create-PRs:
if: github.repository == 'nrfconnect/sdk-nrf'
runs-on: ubuntu-24.04
steps:
- name: Checkout sources
uses: nrfconnect/action-checkout-west-update@main
with:
git-fetch-depth: 0
west-update-args: 'zephyr bsim mcuboot'
- name: Install base dependencies
working-directory: ncs
run: |
pip3 install -r nrf/scripts/requirements-base.txt
pip3 install -r nrf/scripts/requirements-extra.txt
- name: Get repo urls
working-directory: ncs
run: |
echo "SDK_ZEPHYR=$(west list zephyr -f {url} | awk -F// '{print $NF}')" >> $GITHUB_ENV
echo "SDK_MCUBOOT=$(west list mcuboot -f {url} | awk -F// '{print $NF}')" >> $GITHUB_ENV
- name: Try closing existing auto-upmerge PRs
run: |
SDK_ZEPHYR_PR=$(gh pr list --repo $SDK_ZEPHYR --label "auto-upmerge" --json number --jq .[0].number)
gh pr close $SDK_ZEPHYR_PR --repo $SDK_ZEPHYR | true
SDK_MCUBOOT_PR=$(gh pr list --repo $SDK_MCUBOOT --label "auto-upmerge" --json number --jq .[0].number)
gh pr close $SDK_MCUBOOT_PR --repo $SDK_MCUBOOT | true
SDK_NRF_PR=$(gh pr list --repo $GITHUB_SERVER_URL/$GITHUB_REPOSITORY --label "auto-upmerge" --json number --jq .[0].number)
gh pr close $SDK_NRF_PR --repo $GITHUB_SERVER_URL/$GITHUB_REPOSITORY | true
- name: Run ncs-upmerge and create sdk-zephyr upmerge PR
working-directory: ncs/zephyr
run: |
git remote add -f upstream $ZEPHYR_UPSTREAM && git remote add -f origin https://nordicbuilder:${{secrets.NCS_GITHUB_UPMERGE_TOKEN}}@$SDK_ZEPHYR
git checkout -b upmerge_local
west ncs-upmerger zephyr
git push origin upmerge_local:auto-upmerge/$GITHUB_RUN_ID -u
MCUBOOT_UPSTREAM_REV=$(cat west.yml | awk -e '/- name: mcuboot/,/path: bootloader\/mcuboot/ { if ($0 ~ "revision:.*") { print $2; }; }')
UPSTREAMHASH=$(git rev-parse --short upstream/main)
ZEPHYR_PR_URL=$(gh pr create --base $PR_TARGET_BRANCH --title "[nrf mergeup] Merge upstream automatically up to commit $UPSTREAMHASH" --body "Automatic upmerge action" --repo $SDK_ZEPHYR --label "auto-upmerge")
echo "ZEPHYR_PR_URL=$ZEPHYR_PR_URL" >> $GITHUB_ENV
echo "Created PR: $ZEPHYR_PR_URL"
echo "MCUboot revision used by upstream: ${MCUBOOT_UPSTREAM_REV}"
echo "MCUBOOT_UPSTREAM_REV=${MCUBOOT_UPSTREAM_REV}" >> $GITHUB_ENV
- name: Run ncs-upmerge and create sdk-mcuboot upmerge PR
working-directory: ncs/bootloader/mcuboot
run: |
git remote add -f upstream $MCUBOOT_UPSTREAM && git remote add -f origin https://nordicbuilder:${{secrets.NCS_GITHUB_UPMERGE_TOKEN}}@$SDK_MCUBOOT
git checkout -b upmerge_local
west ncs-upmerger mcuboot
git push origin upmerge_local:auto-upmerge/$GITHUB_RUN_ID -u
UPSTREAMHASH=${MCUBOOT_UPSTREAM_REV}
MCUBOOT_PR_URL=$(gh pr create --base $PR_TARGET_BRANCH --title "[nrf mergeup] Merge upstream automatically up to commit $UPSTREAMHASH" --body "Automatic upmerge action" --repo $SDK_MCUBOOT --label "auto-upmerge")
echo "MCUBOOT_PR_URL=$MCUBOOT_PR_URL" >> $GITHUB_ENV
echo "Created PR: $MCUBOOT_PR_URL"
- name: create sdk-nrf PR with updated west.yml
working-directory: ncs/nrf
run: |
NEW_REV=$(echo "pull/$(basename $ZEPHYR_PR_URL)/head" | sed 's/\//\\\//g')
NEW_MCUBOOT_REV=$(echo "pull/$(basename $MCUBOOT_PR_URL)/head" | sed 's/\//\\\//g')
OLD_REV=$(west list zephyr -f {revision})
OLD_MCUBOOT_REV=$(west list mcuboot -f {revision})
git checkout -b upmerge_local
sed -i "s/revision: $OLD_REV/revision: $NEW_REV/" west.yml
sed -i "s/revision: $OLD_MCUBOOT_REV/revision: $NEW_MCUBOOT_REV/" west.yml
git commit -a -m "manifest: Update sdk-zephyr revision (automatic Zephyr upmerge)" -m "Automatically created by Github Action" --signoff
git push origin upmerge_local:auto-upmerge/$GITHUB_RUN_ID -u
gh pr create --base $PR_TARGET_BRANCH --title "manifest: Update revisions of upmerged projects (automatic upmerge)" --body "Automatic upmerge action" --label "CI-all-test" --label "auto-upmerge"
failure-notifier:
runs-on: ubuntu-24.04
if: failure()
needs: auto-upmerge-create-PRs
env:
MESSAGE: "<strong>Zephyr auto-upmerge workflow has failed.</strong><br> Please check action output for details: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
steps:
- name: Add summary (steps to reproduce)
run: |
echo "### :boom:Automatic zephyr upmerge action has failed :boom:" >> $GITHUB_STEP_SUMMARY
echo "#### In case of e.g. merge conflict you can reproduce it locally with the following steps:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`sh" >> $GITHUB_STEP_SUMMARY
echo "west init -l nrf" >> $GITHUB_STEP_SUMMARY
echo "west update zephyr" >> $GITHUB_STEP_SUMMARY
echo "cd zephyr" >> $GITHUB_STEP_SUMMARY
echo "git remote add -f upstream https://github.com/zephyrproject-rtos/zephyr" >> $GITHUB_STEP_SUMMARY
echo "west ncs-upmerger zephyr" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "Solve merge-conflict locally and submit sdk-zephyr and sdk-nrf PRs" >> $GITHUB_STEP_SUMMARY
- name: Send MS Teams notification
run: |
curl -s ${{ secrets.CONNECTOR_TEAMS_NCS_UPMERGE }} -X POST -H 'Content-type: application/json' --data '{"text": "'"$MESSAGE"'"}'