Skip to content

Commit 9f46231

Browse files
authored
GHA: add push pr job for update rules (#2115)
* add push pr job Signed-off-by: habibayassin <[email protected]>
1 parent ef48d5f commit 9f46231

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

.github/workflows/github-actions-cron-sync-fork-from-upstream.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ on:
1010
description: Use GitHub --force push.
1111
default:
1212

13-
repository_dispatch:
14-
1513

1614
jobs:
1715
Sync-Branch-From-Upstream:

.github/workflows/github-actions-update-rules.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
with:
1616
submodules: recursive
1717
fetch-depth: 0
18+
ref: ${{ github.event.client_payload.branch }}
1819
- uses: actions/setup-python@v4
1920
with:
2021
python-version: "3.10"
@@ -29,9 +30,9 @@ jobs:
2930
echo ${{ github.event_name }}
3031
echo ${{ github.event.client_payload.type }}
3132
if [[ "${{ github.event_name }}" == "repository_dispatch" && "${{ github.event.client_payload.type }}" == "overwrite" ]]; then
32-
python flow/util/updateRules.py --keyFile "${CREDS_FILE}" --apiURL ${API_BASE_URL} --overwrite
33+
python flow/util/updateRules.py --keyFile "${CREDS_FILE}" --apiURL ${API_BASE_URL} --commitSHA ${{ github.event.client_payload.commitsha }} --overwrite
3334
else
34-
python flow/util/updateRules.py --keyFile "${CREDS_FILE}" --apiURL ${API_BASE_URL}
35+
python flow/util/updateRules.py --keyFile "${CREDS_FILE}" --apiURL ${API_BASE_URL} --commitSHA ${{ github.event.client_payload.commitsha }}
3536
fi
3637
- name: Push updated rules
3738
id: remote-update
@@ -44,8 +45,13 @@ jobs:
4445
echo "has_update=false" >> "$GITHUB_OUTPUT"
4546
fi
4647
git add .
47-
git commit -m "flow: update rules based on new golden reference"
48-
- if: "steps.remote-update.outputs.has_update == 'true'"
48+
git commit --signoff -m "flow: update rules based on new golden reference"
49+
- if: "github.event.client_payload.branch != 'master'"
50+
name: update rules pr
51+
id: remote-update-pr
52+
run: |
53+
git push origin ${{ github.event.client_payload.branch }}
54+
- if: "steps.remote-update.outputs.has_update == 'true' && github.event.client_payload.branch == 'master'"
4955
name: Create Draft PR
5056
uses: peter-evans/create-pull-request@v5
5157
with:

flow/util/genRuleFile.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ def get_golden(platform, design, api_base_url):
2727
print(f"An error occurred: {str(e)}")
2828
return None, f"An error occurred: {str(e)}"
2929

30+
def get_metrics(commitSHA, platform, design, api_base_url):
31+
try:
32+
response = requests.get(api_base_url+f"/commit?commitSHA={commitSHA}&platform={platform}&design={design}&variant=base")
33+
34+
# Check if the request was successful (status code 200)
35+
if response.status_code == 200 and "error" not in response.json():
36+
# Parse the JSON response
37+
data = response.json()
38+
39+
return data, None
40+
else:
41+
print("API request failed")
42+
return None, "API request failed"
43+
except Exception as e:
44+
print(f"An error occurred: {str(e)}")
45+
return None, f"An error occurred: {str(e)}"
46+
3047
def update_rules(designDir, variant, golden_metrics, overwrite):
3148
if overwrite:
3249
gen_rule_file(designDir, # design directory
@@ -286,7 +303,7 @@ def gen_rule_file(design_dir, update, tighten, failing, variant, golden_metrics=
286303

287304
if update and old_rule['value'] != rule_value:
288305
UPDATE = True
289-
change_str += format.format_str.format(field, old_rule['value'],
306+
change_str += format_str.format(field, old_rule['value'],
290307
rule_value, 'Updating')
291308

292309
if not UPDATE:
@@ -340,4 +357,4 @@ def gen_rule_file(design_dir, update, tighten, failing, variant, golden_metrics=
340357
parser.print_help()
341358
sys.exit(1)
342359

343-
gen_rule_file(args.dir, args.update, args.tighten, args.failing, args.variant)
360+
gen_rule_file(args.dir, args.update, args.tighten, args.failing, args.variant)

flow/util/updateRules.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import requests
1010
from genRuleFile import get_golden
1111
from genRuleFile import update_rules
12+
from genRuleFile import get_metrics
1213

1314
# make sure the working dir is flow/
1415
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
@@ -19,6 +20,7 @@
1920
parser.add_argument('--keyFile', type=str, help='Service account credentials key file')
2021
parser.add_argument('--overwrite', action='store_true', default=False, help='Overwrite the golden metrics')
2122
parser.add_argument('--apiURL', type=str, default="http://localhost:80", help='Set API Base URL to get golden metrics')
23+
parser.add_argument('--commitSHA', type=str, default="", help='commit for the metrics used to update the rules')
2224

2325
# Parse the arguments
2426
args = parser.parse_args()
@@ -44,15 +46,16 @@
4446
test = '{} {}'.format(platform, design)
4547
dataFile = os.path.join(designsDir, runFilename)
4648
if os.path.exists(dataFile) and (platform != 'sky130hd_fakestack' or platform != 'src'):
47-
golden_metrics, error_golden_metrics = get_golden(platform, # platform
48-
design, # design
49-
api_base_url # backend url
50-
)
51-
if error_golden_metrics:
49+
metrics, error_metrics = get_metrics(args.commitSHA, # commit
50+
platform, # platform
51+
design, # design
52+
api_base_url # backend url
53+
)
54+
if error_metrics:
5255
print("failed to update rule for", platform, design)
5356
continue
5457
update_rules(designsDir, # design directory
5558
"base", # variant
56-
golden_metrics, # metrics needed for update, default is {} in case of file
59+
metrics, # metrics needed for update, default is {} in case of file
5760
args.overwrite # overwrite flag, default is false
58-
)
61+
)

0 commit comments

Comments
 (0)