From 75e604ed608ca697d38adc38024be958ee322136 Mon Sep 17 00:00:00 2001 From: habibayassin Date: Sat, 6 Jul 2024 22:34:23 +0000 Subject: [PATCH 1/7] add push pr job Signed-off-by: habibayassin --- .github/workflows/github-actions-update-rules.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github-actions-update-rules.yml b/.github/workflows/github-actions-update-rules.yml index f574c03a2d..6e67ca54e2 100644 --- a/.github/workflows/github-actions-update-rules.yml +++ b/.github/workflows/github-actions-update-rules.yml @@ -15,6 +15,7 @@ jobs: with: submodules: recursive fetch-depth: 0 + ref: ${{ github.event.client_payload.branch }} - uses: actions/setup-python@v4 with: python-version: "3.10" @@ -45,7 +46,12 @@ jobs: fi git add . git commit -m "flow: update rules based on new golden reference" - - if: "steps.remote-update.outputs.has_update == 'true'" + - if: "${{ github.event.client_payload.branch }} != "master"" + name: update rules pr + id: remote-update-pr + run: | + git push origin ${{ github.event.client_payload.branch }} + - if: "steps.remote-update.outputs.has_update == 'true' && ${{ github.event.client_payload.branch }} == "master"" name: Create Draft PR uses: peter-evans/create-pull-request@v5 with: From f0ecc6751fdb5e966fd3a2b849b0a4c5f96b42c9 Mon Sep 17 00:00:00 2001 From: habibayassin Date: Sat, 13 Jul 2024 22:33:28 +0000 Subject: [PATCH 2/7] fix gha Signed-off-by: habibayassin --- .../workflows/github-actions-cron-sync-fork-from-upstream.yml | 2 -- .github/workflows/github-actions-update-rules.yml | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/github-actions-cron-sync-fork-from-upstream.yml b/.github/workflows/github-actions-cron-sync-fork-from-upstream.yml index 064c1a259d..6d5f57424c 100644 --- a/.github/workflows/github-actions-cron-sync-fork-from-upstream.yml +++ b/.github/workflows/github-actions-cron-sync-fork-from-upstream.yml @@ -10,8 +10,6 @@ on: description: Use GitHub --force push. default: - repository_dispatch: - jobs: Sync-Branch-From-Upstream: diff --git a/.github/workflows/github-actions-update-rules.yml b/.github/workflows/github-actions-update-rules.yml index 6e67ca54e2..16a80a4853 100644 --- a/.github/workflows/github-actions-update-rules.yml +++ b/.github/workflows/github-actions-update-rules.yml @@ -46,12 +46,12 @@ jobs: fi git add . git commit -m "flow: update rules based on new golden reference" - - if: "${{ github.event.client_payload.branch }} != "master"" + - if: "${{ github.event.client_payload.branch }} != 'master'" name: update rules pr id: remote-update-pr run: | git push origin ${{ github.event.client_payload.branch }} - - if: "steps.remote-update.outputs.has_update == 'true' && ${{ github.event.client_payload.branch }} == "master"" + - if: "steps.remote-update.outputs.has_update == 'true' && ${{ github.event.client_payload.branch }} == 'master'" name: Create Draft PR uses: peter-evans/create-pull-request@v5 with: From 97ba8532aa766ee288ead06d1044b5007cd95d51 Mon Sep 17 00:00:00 2001 From: habibayassin Date: Mon, 22 Jul 2024 22:52:42 +0000 Subject: [PATCH 3/7] use all commits from db to update Signed-off-by: habibayassin --- .../workflows/github-actions-update-rules.yml | 4 ++-- flow/util/genRuleFile.py | 19 ++++++++++++++++++- flow/util/updateRules.py | 14 ++++++++------ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/.github/workflows/github-actions-update-rules.yml b/.github/workflows/github-actions-update-rules.yml index 16a80a4853..c891e12254 100644 --- a/.github/workflows/github-actions-update-rules.yml +++ b/.github/workflows/github-actions-update-rules.yml @@ -30,9 +30,9 @@ jobs: echo ${{ github.event_name }} echo ${{ github.event.client_payload.type }} if [[ "${{ github.event_name }}" == "repository_dispatch" && "${{ github.event.client_payload.type }}" == "overwrite" ]]; then - python flow/util/updateRules.py --keyFile "${CREDS_FILE}" --apiURL ${API_BASE_URL} --overwrite + python flow/util/updateRules.py --keyFile "${CREDS_FILE}" --apiURL ${API_BASE_URL} --commitSHA ${{ github.event.client_payload.commitsha }} --overwrite else - python flow/util/updateRules.py --keyFile "${CREDS_FILE}" --apiURL ${API_BASE_URL} + python flow/util/updateRules.py --keyFile "${CREDS_FILE}" --apiURL ${API_BASE_URL} --commitSHA ${{ github.event.client_payload.commitsha }} fi - name: Push updated rules id: remote-update diff --git a/flow/util/genRuleFile.py b/flow/util/genRuleFile.py index d17172dccf..1f515f101b 100755 --- a/flow/util/genRuleFile.py +++ b/flow/util/genRuleFile.py @@ -27,6 +27,23 @@ def get_golden(platform, design, api_base_url): print(f"An error occurred: {str(e)}") return None, f"An error occurred: {str(e)}" +def get_metrics(commitSHA, platform, design, api_base_url): + try: + response = requests.get(api_base_url+f"/commit?commitSHA={commitSHA}&platform={platform}&design={design}&variant=base") + + # Check if the request was successful (status code 200) + if response.status_code == 200 and "error" not in response.json(): + # Parse the JSON response + data = response.json() + + return data, None + else: + print("API request failed") + return None, "API request failed" + except Exception as e: + print(f"An error occurred: {str(e)}") + return None, f"An error occurred: {str(e)}" + def update_rules(designDir, variant, golden_metrics, overwrite): if overwrite: gen_rule_file(designDir, # design directory @@ -280,7 +297,7 @@ def gen_rule_file(design_dir, update, tighten, failing, variant, golden_metrics= if update and old_rule['value'] != rule_value: UPDATE = True - change_str += format.format_str.format(field, old_rule['value'], + change_str += format_str.format(field, old_rule['value'], rule_value, 'Updating') if not UPDATE: diff --git a/flow/util/updateRules.py b/flow/util/updateRules.py index 657e230cf9..714269d689 100644 --- a/flow/util/updateRules.py +++ b/flow/util/updateRules.py @@ -19,6 +19,7 @@ parser.add_argument('--keyFile', type=str, help='Service account credentials key file') parser.add_argument('--overwrite', action='store_true', default=False, help='Overwrite the golden metrics') parser.add_argument('--apiURL', type=str, default="http://localhost:80", help='Set API Base URL to get golden metrics') +parser.add_argument('--commitSHA', type=str, default="", help='commit for the metrics used to update the rules') # Parse the arguments args = parser.parse_args() @@ -44,15 +45,16 @@ test = '{} {}'.format(platform, design) dataFile = os.path.join(designsDir, runFilename) if os.path.exists(dataFile) and (platform != 'sky130hd_fakestack' or platform != 'src'): - golden_metrics, error_golden_metrics = get_golden(platform, # platform - design, # design - api_base_url # backend url - ) - if error_golden_metrics: + metrics, error_metrics = get_metrics(args.commitSHA # commit + platform, # platform + design, # design + api_base_url # backend url + ) + if error_metrics: print("failed to update rule for", platform, design) continue update_rules(designsDir, # design directory "base", # variant - golden_metrics, # metrics needed for update, default is {} in case of file + metrics, # metrics needed for update, default is {} in case of file args.overwrite # overwrite flag, default is false ) From 09330d13096fbffb0c4a17f3db0e86196791dc96 Mon Sep 17 00:00:00 2001 From: habibayassin Date: Tue, 23 Jul 2024 22:50:09 +0000 Subject: [PATCH 4/7] fixes Signed-off-by: habibayassin --- .github/workflows/github-actions-update-rules.yml | 2 +- flow/util/genRuleFile.py | 2 +- flow/util/updateRules.py | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/github-actions-update-rules.yml b/.github/workflows/github-actions-update-rules.yml index c891e12254..2d5ae60580 100644 --- a/.github/workflows/github-actions-update-rules.yml +++ b/.github/workflows/github-actions-update-rules.yml @@ -45,7 +45,7 @@ jobs: echo "has_update=false" >> "$GITHUB_OUTPUT" fi git add . - git commit -m "flow: update rules based on new golden reference" + git commit --signoff -m "flow: update rules based on new golden reference" - if: "${{ github.event.client_payload.branch }} != 'master'" name: update rules pr id: remote-update-pr diff --git a/flow/util/genRuleFile.py b/flow/util/genRuleFile.py index 6ab3a05af9..97d24c90ab 100755 --- a/flow/util/genRuleFile.py +++ b/flow/util/genRuleFile.py @@ -357,4 +357,4 @@ def gen_rule_file(design_dir, update, tighten, failing, variant, golden_metrics= parser.print_help() sys.exit(1) - gen_rule_file(args.dir, args.update, args.tighten, args.failing, args.variant) + gen_rule_file(args.dir, args.update, args.tighten, args.failing, args.variant) \ No newline at end of file diff --git a/flow/util/updateRules.py b/flow/util/updateRules.py index 714269d689..c565b2afbe 100644 --- a/flow/util/updateRules.py +++ b/flow/util/updateRules.py @@ -9,6 +9,7 @@ import requests from genRuleFile import get_golden from genRuleFile import update_rules +from genRuleFile import get_metrics # make sure the working dir is flow/ os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) @@ -45,7 +46,7 @@ test = '{} {}'.format(platform, design) dataFile = os.path.join(designsDir, runFilename) if os.path.exists(dataFile) and (platform != 'sky130hd_fakestack' or platform != 'src'): - metrics, error_metrics = get_metrics(args.commitSHA # commit + metrics, error_metrics = get_metrics(args.commitSHA, # commit platform, # platform design, # design api_base_url # backend url @@ -57,4 +58,4 @@ "base", # variant metrics, # metrics needed for update, default is {} in case of file args.overwrite # overwrite flag, default is false - ) + ) \ No newline at end of file From afcb5e0f7d0236aae24bee721c97faf40a61a67f Mon Sep 17 00:00:00 2001 From: habibayassin Date: Tue, 23 Jul 2024 23:08:53 +0000 Subject: [PATCH 5/7] condition on master Signed-off-by: habibayassin --- .github/workflows/github-actions-update-rules.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-actions-update-rules.yml b/.github/workflows/github-actions-update-rules.yml index 2d5ae60580..fcfc65a10d 100644 --- a/.github/workflows/github-actions-update-rules.yml +++ b/.github/workflows/github-actions-update-rules.yml @@ -46,12 +46,12 @@ jobs: fi git add . git commit --signoff -m "flow: update rules based on new golden reference" - - if: "${{ github.event.client_payload.branch }} != 'master'" + - if: "github.event.client_payload.branch != 'master'" name: update rules pr id: remote-update-pr run: | git push origin ${{ github.event.client_payload.branch }} - - if: "steps.remote-update.outputs.has_update == 'true' && ${{ github.event.client_payload.branch }} == 'master'" + - if: "steps.remote-update.outputs.has_update == 'true' && github.event.client_payload.branch == 'master'" name: Create Draft PR uses: peter-evans/create-pull-request@v5 with: From cb7fa58c85a63ef4a2afbf2d955fa06c143158d6 Mon Sep 17 00:00:00 2001 From: habibayassin Date: Thu, 25 Jul 2024 17:23:07 +0000 Subject: [PATCH 6/7] fetch prs Signed-off-by: habibayassin --- .github/workflows/github-actions-update-rules.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/github-actions-update-rules.yml b/.github/workflows/github-actions-update-rules.yml index fcfc65a10d..ed7f3cec25 100644 --- a/.github/workflows/github-actions-update-rules.yml +++ b/.github/workflows/github-actions-update-rules.yml @@ -10,6 +10,10 @@ jobs: strategy: fail-fast: false steps: + - name: Git prep + run: | + git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*" + git fetch - name: Check out repository code recursively uses: actions/checkout@v3 with: From 5ca88a76aed2b2430a8fe2b8eaf254c6aa400e65 Mon Sep 17 00:00:00 2001 From: habibayassin Date: Thu, 25 Jul 2024 17:29:20 +0000 Subject: [PATCH 7/7] fetch prs and checkout Signed-off-by: habibayassin --- .github/workflows/github-actions-update-rules.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/github-actions-update-rules.yml b/.github/workflows/github-actions-update-rules.yml index ed7f3cec25..ab8f35a1fb 100644 --- a/.github/workflows/github-actions-update-rules.yml +++ b/.github/workflows/github-actions-update-rules.yml @@ -10,16 +10,16 @@ jobs: strategy: fail-fast: false steps: - - name: Git prep - run: | - git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*" - git fetch - name: Check out repository code recursively uses: actions/checkout@v3 with: submodules: recursive fetch-depth: 0 - ref: ${{ github.event.client_payload.branch }} + - name: Git prep + run: | + git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*" + git fetch + git checkout ${{ github.event.client_payload.branch }} - uses: actions/setup-python@v4 with: python-version: "3.10"