Skip to content

Commit 1092522

Browse files
woody-applepull[bot]
authored andcommitted
Working on auto-regeneration (#10936)
Adding first shot at auto regeneration
1 parent 2b6db4b commit 1092522

File tree

2 files changed

+149
-64
lines changed

2 files changed

+149
-64
lines changed

.github/workflows/zap_regeneration.yaml

+24-64
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
name: ZAP - Regenerate
1616

1717
on:
18-
# push:
19-
# pull_request:
2018
workflow_dispatch:
19+
issue_comment:
20+
types: [created]
2121

2222
concurrency:
2323
group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }}
@@ -29,67 +29,27 @@ jobs:
2929
timeout-minutes: 60
3030

3131
runs-on: ubuntu-18.04
32-
if: github.actor != 'restyled-io[bot]'
32+
if: (github.event.issue.pull_request != '' && contains(github.event.comment.body, '/regenerate') || (github.event_name == 'workflow_dispatch')
3333

34-
# container:
35-
# image: connectedhomeip/chip-build:latest
3634
steps:
37-
- name: Checkout
38-
uses: actions/checkout@v2
39-
with:
40-
# token: ${{ secrets.APPLE_PERSONAL_ACCESS_TOKEN }}
41-
# ref: ${{ github.head_ref }}
42-
submodules: true
43-
- name: Use Node.js 14.x
44-
uses: actions/setup-node@v2
45-
with:
46-
node-version: '14'
47-
- name: Use Java
48-
uses: actions/setup-java@v2
49-
with:
50-
distribution: 'zulu'
51-
java-version: '11'
52-
java-package: jre
53-
- run: sudo apt-get update
54-
- run: sudo apt-get install -fy --fix-missing libpixman-1-dev libcairo-dev libsdl-pango-dev libjpeg-dev libgif-dev python-autopep8
55-
- name: Setup ZAP
56-
timeout-minutes: 5
57-
run: |
58-
cd third_party/zap/repo/
59-
npm ci
60-
npm run version-stamp
61-
npm rebuild canvas --update-binary
62-
npm run build-spa
63-
- name: Generate all
64-
timeout-minutes: 5
65-
run: scripts/tools/zap_regen_all.py
66-
- name: Check for uncommited changes
67-
run: git status
68-
# git diff
69-
# git add .
70-
# git diff-index HEAD --
71-
# git diff-index --quiet HEAD --
72-
- name: Add generated paths
73-
run: |
74-
git add zzz_generated/*
75-
git add src/darwin/Framework/*
76-
git add src/controller/python/chip/clusters/*
77-
git add src/controller/java/zap-generated/*
78-
- uses: GuillaumeFalourd/git-commit-push@v1
79-
with:
80-
# email: ${{ github.actor }}@users.noreply.github.com
81-
# name: ${{ github.actor }}
82-
commit_message: Adding ZAP Generated Files
83-
# target_branch: target_branch_name
84-
# files: file1 file2 directory1 directory2/file3
85-
# remote_repository: https://github.com/owner/another_repository
86-
access_token: ${{ secrets.APPLE_PERSONAL_ACCESS_TOKEN }}
87-
# force: true
88-
# empty: true
89-
# tags: true
90-
# - name: Commit newly generated changes
91-
# uses: stefanzweifel/git-auto-commit-action@v4
92-
# with:
93-
# commit_message: Auto-regenerated ZAP Changes
94-
# file_pattern: "zzz_generated/* src/darwin/Framework/* src/controller/python/chip/clusters/* src/controller/java/zap-generated/*"
95-
# # branch: ${{ github.head_ref }}
35+
- name: Checkout
36+
uses: actions/checkout@v2
37+
with:
38+
token: ${{ secrets.APPLE_PERSONAL_ACCESS_TOKEN }}
39+
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
40+
- name: Use Node.js 14.x
41+
uses: actions/setup-node@v2
42+
with:
43+
node-version: '14'
44+
- name: Use Java
45+
uses: actions/setup-java@v2
46+
with:
47+
distribution: 'zulu'
48+
java-version: '11'
49+
java-package: jre
50+
- run: sudo apt-get update
51+
- run: sudo apt-get install -fy --fix-missing libpixman-1-dev libcairo-dev libsdl-pango-dev libjpeg-dev libgif-dev python-autopep8
52+
- name: Rebase and regenerate
53+
run: scripts/helpers/rebase_and_regenerate_zap.sh
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.APPLE_PERSONAL_ACCESS_TOKEN }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/bash
2+
# Credit to https://github.com/cirrus-actions/rebase for the base functionality here
3+
4+
set -e
5+
6+
if [ -z "$PR_NUMBER" ]; then
7+
PR_NUMBER=$(jq -r ".pull_request.number" "$GITHUB_EVENT_PATH")
8+
if [[ "$PR_NUMBER" == "null" ]]; then
9+
PR_NUMBER=$(jq -r ".issue.number" "$GITHUB_EVENT_PATH")
10+
fi
11+
if [[ "$PR_NUMBER" == "null" ]]; then
12+
echo "Failed to determine PR Number."
13+
exit 1
14+
fi
15+
fi
16+
17+
echo "Collecting information about PR #$PR_NUMBER of $GITHUB_REPOSITORY..."
18+
19+
if [[ -z "$GITHUB_TOKEN" ]]; then
20+
echo "Set the GITHUB_TOKEN env variable."
21+
exit 1
22+
fi
23+
24+
URI=https://api.github.com
25+
API_HEADER="Accept: application/vnd.github.v3+json"
26+
AUTH_HEADER="Authorization: token $GITHUB_TOKEN"
27+
28+
MAX_RETRIES=${MAX_RETRIES:-6}
29+
RETRY_INTERVAL=${RETRY_INTERVAL:-10}
30+
REBASEABLE=""
31+
pr_resp=""
32+
for ((i = 0; i < "$MAX_RETRIES"; i++)); do
33+
pr_resp=$(curl -X GET -s -H "$AUTH_HEADER" -H "$API_HEADER" \
34+
"$URI/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER")
35+
REBASEABLE=$(echo "$pr_resp" | jq -r .rebaseable)
36+
if [[ "$REBASEABLE" == "null" ]]; then
37+
echo "The PR is not ready to rebase, retry after $RETRY_INTERVAL seconds"
38+
sleep "$RETRY_INTERVAL"
39+
continue
40+
else
41+
break
42+
fi
43+
done
44+
45+
# if [[ "$REBASEABLE" != "true" ]] ; then
46+
# echo "GitHub doesn't think that the PR is rebaseable!"
47+
# exit 1
48+
# fi
49+
50+
BASE_REPO=$(echo "$pr_resp" | jq -r .base.repo.full_name)
51+
BASE_BRANCH=$(echo "$pr_resp" | jq -r .base.ref)
52+
53+
USER_LOGIN=$(jq -r ".comment.user.login" "$GITHUB_EVENT_PATH")
54+
55+
if [[ "$USER_LOGIN" == "null" ]]; then
56+
USER_LOGIN=$(jq -r ".pull_request.user.login" "$GITHUB_EVENT_PATH")
57+
fi
58+
59+
user_resp=$(curl -X GET -s -H "$AUTH_HEADER" -H "$API_HEADER" \
60+
"$URI/users/$USER_LOGIN")
61+
62+
USER_NAME=$(echo "$user_resp" | jq -r ".name")
63+
if [[ "$USER_NAME" == "null" ]]; then
64+
USER_NAME=$USER_LOGIN
65+
fi
66+
USER_NAME="$USER_NAME (Rebase PR Action)"
67+
68+
USER_EMAIL=$(echo "$user_resp" | jq -r ".email")
69+
if [[ "$USER_EMAIL" == "null" ]]; then
70+
USER_EMAIL="$USER_LOGIN@users.noreply.github.com"
71+
fi
72+
73+
if [[ -z "$BASE_BRANCH" ]]; then
74+
echo "Cannot get base branch information for PR #$PR_NUMBER!"
75+
exit 1
76+
fi
77+
78+
HEAD_REPO=$(echo "$pr_resp" | jq -r .head.repo.full_name)
79+
HEAD_BRANCH=$(echo "$pr_resp" | jq -r .head.ref)
80+
81+
echo "Base branch for PR #$PR_NUMBER is $BASE_BRANCH"
82+
83+
USER_TOKEN=${USER_LOGIN//-/_}_TOKEN
84+
UNTRIMMED_COMMITTER_TOKEN=${!USER_TOKEN:-$GITHUB_TOKEN}
85+
COMMITTER_TOKEN="$(echo -e "$UNTRIMMED_COMMITTER_TOKEN" | tr -d '[:space:]')"
86+
87+
git remote set-url origin https://x-access-token:"$COMMITTER_TOKEN@github.com/$GITHUB_REPOSITORY".git
88+
git config --global user.email "$USER_EMAIL"
89+
git config --global user.name "$USER_NAME"
90+
91+
git remote add fork https://x-access-token:"$COMMITTER_TOKEN@github.com/$HEAD_REPO".git
92+
93+
set -o xtrace
94+
95+
# make sure branches are up-to-date
96+
git fetch origin "$BASE_BRANCH"
97+
git fetch fork "$HEAD_BRANCH"
98+
99+
# do the rebase
100+
git checkout -b fork/"$HEAD_BRANCH" fork/"$HEAD_BRANCH"
101+
git rebase origin/"$BASE_BRANCH"
102+
103+
git submodule update --init --recursive third_party/zap/
104+
105+
cd third_party/zap/repo/
106+
npm ci
107+
npm run version-stamp
108+
npm rebuild canvas --update-binary
109+
npm run build-spa
110+
111+
cd ../../../
112+
113+
scripts/tools/zap_regen_all.py
114+
115+
git status
116+
117+
git add zzz_generated/*
118+
git add src/darwin/Framework/*
119+
git add src/controller/python/chip/clusters/*
120+
git add src/controller/java/zap-generated/*
121+
122+
git commit -m "Regenerating ZAP"
123+
124+
# push back
125+
git push --force-with-lease fork fork/"$HEAD_BRANCH:$HEAD_BRANCH"

0 commit comments

Comments
 (0)