Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(2675): exclude ci build for non-pr #25489

Closed
wants to merge 2 commits into from
Closed

Conversation

DDDDDanica
Copy link
Contributor

@DDDDDanica DDDDDanica commented Jun 24, 2024

Description

To reduce cost for circle ci and allocate more resources to PR, we remove the circle build for non-pr branches.

Sample test jobs:

When branch name is matching filter as develop, master, release branch starting with Version, here's a test job with mocked branch filter feat/test-circle-ci, be aware that this is for pure testing purpose:

- Condition A:

#`+|feat/test-circle-ci` is for testing purpose
if [[ "$CIRCLE_BRANCH" =~ ^(develop|master|Version-v[0-9]+\.[0-9]+\.[0-9]+|feat/test-circle-ci)$ || -n "$CIRCLE_PULL_REQUESTS" ]]; then
                echo "Branch matches filters. Proceeding with pipeline."
            else
                if [ -z "$CIRCLE_PULL_REQUESTS" ]; then
                    echo "This branch has no associated pull request. Terminating pipeline build."
                    exit 1
                else
                    echo "Branch does not match filters. Terminating pipeline build."
                fi
                exit 1
            fi

Result: (success)

https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/91110/workflows/80415232-2145-4a5d-a994-c89287351fc4/jobs/3384490

- Condition B:

Branch does not have an associated pull request, and does not match the filter, hence running feat/test-circle-ci branch will result in a failed pipeline:

            if [[ "$CIRCLE_BRANCH" =~ ^(develop|master|Version-v[0-9]+\.[0-9]+\.[0-9]+|trigger-ci.*)$ || -n "$CIRCLE_PULL_REQUESTS" ]]; then
                echo "Branch matches filters. Proceeding with pipeline."
            else
                if [ -z "$CIRCLE_PULL_REQUESTS" ]; then
                    echo "This branch has no associated pull request. Terminating pipeline build."
                    exit 1
                else
                    echo "Branch does not match filters. Terminating pipeline build."
                fi
                exit 1
            fi

Result: (failure)

https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/91111/workflows/f084602e-1af6-497f-b192-639861c25e01

- Condition C:

We trigger the build of current branch feature/2675, which doesn't match any name filter but has this current PR associated with it. Hence the pipeline will be triggered.

Result: (success)

https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/91112/workflows/c21314e0-dcab-4813-9031-8e1698524f02/jobs/3384524

Open in GitHub Codespaces

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/2675

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

Condition B
截屏2024-07-11 01 45 03

Condition C
截屏2024-07-11 01 49 14

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@DDDDDanica DDDDDanica requested review from kumavis and a team as code owners June 24, 2024 15:08
@DDDDDanica DDDDDanica requested a review from danjm June 24, 2024 15:08
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

hjetpoluru
hjetpoluru previously approved these changes Jun 24, 2024
Copy link
Contributor

@hjetpoluru hjetpoluru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -81,6 +81,9 @@ aliases:

workflows:
test_and_release:
when:
not:
is: pull_request # Exclude pull request events
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would break CI on develop and master (which would break releases)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may also want to allow runs from branches that are manually triggered (not especially important to me but @HowardBraham mentioned this idea in Slack, some people mind find this useful)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gudahtt I expanded the script to include develop and master in this commit e3fcfc49

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gudahtt

We may also want to allow runs from branches that are manually triggered (not especially important to me but @HowardBraham mentioned this idea in Slack, some people mind find this useful)

Can we target in a different ticket, and use an agreed scheme like trigger-CI-feature-123-test where we always have trigger-CI as prefix for branches who needs to have a pipeline before creating a PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HowardBraham Thanks for the information, but I was a bit lost there. Can you elaborate more on this propsal?
my understanding is, in the thread an API is suggested to config the setting. But we can use a schema in yml file to target the branch segmentation. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree it's confusing and I definitely don't completely understand it either. Basically there exist options in the API that are not available in the YML.

I thought about that trigger-CI thing, yeah can we do that for now?

Copy link
Contributor Author

@DDDDDanica DDDDDanica Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain to me again about the trigger-CI thing, is this related to triggering job manually in branch page in circle ci?
截屏2024-06-28 14 25 56

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure there's a way to configure the manual trigger thing in config.yml, I think the only way to do it is with that CircleCI API.

But if you make the pattern /^(master|develop|trigger-CI-.*)$/ it should at least run automatically on those branches.

Also it's a little hard to test, but I don't think it's going to run on master or develop as written. I think it will only run on Pull Requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Howard for suggestions, i configured to trigger it in each run and integrated the pattern you suggested~

@DDDDDanica DDDDDanica dismissed stale reviews from hjetpoluru and pedronfigueiredo via c6f2990 June 25, 2024 21:51
@DDDDDanica DDDDDanica force-pushed the feature/2675 branch 3 times, most recently from 5142f01 to 29c3e29 Compare June 28, 2024 16:48
Copy link

codecov bot commented Jul 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.77%. Comparing base (5ee57a6) to head (8abf362).
Report is 29 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #25489      +/-   ##
===========================================
- Coverage    69.77%   69.77%   -0.00%     
===========================================
  Files         1376     1378       +2     
  Lines        48403    48578     +175     
  Branches     13348    13394      +46     
===========================================
+ Hits         33773    33895     +122     
- Misses       14630    14683      +53     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DDDDDanica DDDDDanica force-pushed the feature/2675 branch 3 times, most recently from e578631 to 013018f Compare July 11, 2024 01:09
@metamaskbot
Copy link
Collaborator

Builds ready [013018f]
Page Load Metrics (65 ± 8 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint6214192178
domContentLoaded95624105
load4111365168
domInteractive95623105
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link

@metamaskbot
Copy link
Collaborator

Builds ready [8abf362]
Page Load Metrics (161 ± 189 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint64130102188
domContentLoaded95826147
load411873161393189
domInteractive95826147
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@HowardBraham
Copy link
Contributor

The solution in this PR is a little cumbersome. I implemented it the other way, as discussed in this article:
https://support.circleci.com/hc/en-us/articles/22357021358875-Build-on-Pull-Requests-and-all-commits

I turned on this switch in our CircleCI settings:
image

For our future records, the API call I ran was:

curl -X PUT \
--header "Circle-Token: <token>" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '{"feature_flags":{"pr-only-branch-overrides": "develop, master, trigger-ci.*, Version-v[0-9]+.[0-9]+.[0-9]+"}}' \
'https://circleci.com/api/v1.1/project/github/MetaMask/metamask-extension/settings'

This is the result of my tests on different branch names, notice the Not Run:

image

@DDDDDanica @Gudahtt please do try some independent tests on this, but I think it's fully working now without this PR.

command: |
#!/bin/bash
# Validate if branch is master, develop or release branch
if [[ "$CIRCLE_BRANCH" =~ ^(develop|master|Version-v[0-9]+\.[0-9]+\.[0-9]+|trigger-ci.*)$ || -n "$CIRCLE_PULL_REQUESTS" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] can you include a mention of trigger-ci.* in the comment?

@@ -423,12 +451,6 @@ jobs:
#!/bin/bash

GH_LABEL=team-mmi
if [ -z "$CIRCLE_PULL_REQUESTS" ]; then
echo "Skipping tag check; this is not a PR."
echo "false" > ./RUN_MMI_OPTIONAL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't the fact that we don't assign ./RUN_MMI_OPTIONAL anymore substantially change the script?

@DDDDDanica
Copy link
Contributor Author

DDDDDanica commented Jul 12, 2024

Hey @HowardBraham thanks for providing this solution. Unfortunately i cannot access the settings page you shared with. But this solution seems neat ! And then i checked the CURL you sent and it seems like this CURL was doing the opposite of what we are looking for? As now it is not running for branch trigger-ci.* or Version-C and running for other branches only. is something I'm missing here?

@HowardBraham
Copy link
Contributor

@DDDDDanica I believe the CURL call is saying:
Only run CircleCI on pull requests except use the overrides
{"pr-only-branch-overrides": "develop, master, trigger-ci.*, Version-v[0-9]+.[0-9]+.[0-9]+"}

So run on branches develop, master, trigger-ci.*, and Versions

@DDDDDanica
Copy link
Contributor Author

@HowardBraham the script seems correct, my bad, the branch I was testing was not named properly, and i believe this approach is the easiest one. Tested it locally as well and all works well.
@danjm and @Gudahtt If this approach is also acceptable with you, we can go ahead and close this PR & Ticket

@danjm
Copy link
Contributor

danjm commented Jul 19, 2024

It does seem like Howard's solution is working

@DDDDDanica
Copy link
Contributor Author

Close because this has been implemented by @HowardBraham with a cleaner solution

@DDDDDanica DDDDDanica closed this Jul 19, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants