Skip to content

Commit

Permalink
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
Browse files Browse the repository at this point in the history
…nsion--persistence-telemetry
  • Loading branch information
gambinish authored Oct 7, 2024
2 parents e7a879e + fd4cdf0 commit f4ef0da
Show file tree
Hide file tree
Showing 33 changed files with 1,411 additions and 44 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ name: Main

on:
push:
branches: [develop, master]
branches:
- develop
- master
pull_request:
types:
- opened
- reopened
- synchronize
merge_group:

jobs:
check-workflows:
Expand All @@ -21,11 +28,25 @@ jobs:
run: ${{ steps.download-actionlint.outputs.executable }} -color
shell: bash

run-tests:
name: Run tests
uses: ./.github/workflows/run-tests.yml

sonarcloud:
name: SonarCloud
uses: ./.github/workflows/sonarcloud.yml
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
needs:
- run-tests

all-jobs-completed:
name: All jobs completed
runs-on: ubuntu-latest
needs:
- check-workflows
- run-tests
- sonarcloud
outputs:
PASSED: ${{ steps.set-output.outputs.PASSED }}
steps:
Expand All @@ -37,7 +58,8 @@ jobs:
name: All jobs pass
if: ${{ always() }}
runs-on: ubuntu-latest
needs: all-jobs-completed
needs:
- all-jobs-completed
steps:
- name: Check that all jobs have passed
run: |
Expand Down
68 changes: 30 additions & 38 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
name: Run tests

on:
push:
branches:
- develop
- master
pull_request:
types:
- opened
- reopened
- synchronize
merge_group:
workflow_call:
outputs:
current-coverage:
description: Current coverage
value: ${{ jobs.report-coverage.outputs.current-coverage }}
stored-coverage:
description: Stored coverage
value: ${{ jobs.report-coverage.outputs.stored-coverage }}

jobs:
test-unit:
Expand Down Expand Up @@ -79,18 +77,19 @@ jobs:
name: coverage-integration
path: coverage/integration/coverage-integration.json

sonarcloud:
name: SonarCloud
report-coverage:
name: Report coverage
runs-on: ubuntu-latest
needs:
- test-unit
- test-webpack
- test-integration
outputs:
current-coverage: ${{ steps.get-current-coverage.outputs.CURRENT_COVERAGE }}
stored-coverage: ${{ steps.get-stored-coverage.outputs.STORED_COVERAGE }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for better relevancy of analysis

- name: Setup environment
uses: metamask/github-tools/.github/actions/setup-environment@main
Expand All @@ -109,35 +108,28 @@ jobs:
name: lcov.info
path: coverage/lcov.info

- name: Get Sonar coverage
id: get-sonar-coverage
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Get current coverage
id: get-current-coverage
run: |
current_coverage=$(yarn nyc report --reporter=text-summary | grep 'Lines' | awk '{gsub(/%/, ""); print int($3)}')
echo "The current coverage is $current_coverage%."
echo 'CURRENT_COVERAGE='"$current_coverage" >> "$GITHUB_OUTPUT"
- name: Get stored coverage
id: get-stored-coverage
run: |
projectKey=$(grep 'sonar.projectKey=' sonar-project.properties | cut -d'=' -f2)
sonar_coverage=$(curl --silent --header "Authorization: Bearer $SONAR_TOKEN" "https://sonarcloud.io/api/measures/component?component=$projectKey&metricKeys=coverage" | jq -r '.component.measures[0].value // 0')
echo "The Sonar coverage of $projectKey is $sonar_coverage%."
echo 'SONAR_COVERAGE='"$sonar_coverage" >> "$GITHUB_OUTPUT"
stored_coverage=$(jq ".coverage" coverage.json)
echo "The stored coverage is $stored_coverage%."
echo 'STORED_COVERAGE='"$stored_coverage" >> "$GITHUB_OUTPUT"
- name: Validate test coverage
env:
SONAR_COVERAGE: ${{ steps.get-sonar-coverage.outputs.SONAR_COVERAGE }}
CURRENT_COVERAGE: ${{ steps.get-current-coverage.outputs.CURRENT_COVERAGE }}
STORED_COVERAGE: ${{ steps.get-stored-coverage.outputs.STORED_COVERAGE }}
run: |
coverage=$(yarn nyc report --reporter=text-summary | grep 'Lines' | awk '{gsub(/%/, ""); print $3}')
if [ -z "$coverage" ]; then
echo "::error::Could not retrieve test coverage."
exit 1
fi
if (( $(echo "$coverage < $SONAR_COVERAGE" | bc -l) )); then
echo "::error::Quality gate failed for test coverage. Current test coverage is $coverage%, please increase coverage to at least $SONAR_COVERAGE%."
if (( $(echo "$CURRENT_COVERAGE < $STORED_COVERAGE" | bc -l) )); then
echo "::error::Quality gate failed for test coverage. Current coverage is $CURRENT_COVERAGE%, please increase coverage to at least $STORED_COVERAGE%."
exit 1
else
echo "Test coverage is $coverage%. Quality gate passed."
echo "The current coverage is $CURRENT_COVERAGE%, stored coverage is $STORED_COVERAGE%. Quality gate passed."
fi
- name: SonarCloud Scan
# This is SonarSource/[email protected]
uses: SonarSource/sonarcloud-github-action@4b4d7634dab97dcee0b75763a54a6dc92a9e6bc1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
30 changes: 30 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: SonarCloud

on:
workflow_call:
secrets:
SONAR_TOKEN:
required: true

jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for better relevancy of analysis

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: lcov.info
path: coverage

- name: SonarCloud Scan
# This is SonarSource/[email protected]
uses: SonarSource/sonarcloud-github-action@4b4d7634dab97dcee0b75763a54a6dc92a9e6bc1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
48 changes: 48 additions & 0 deletions .github/workflows/update-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Update coverage

on:
schedule:
# Once per day at midnight UTC
- cron: 0 0 * * *
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
run-tests:
name: Run tests
uses: ./.github/workflows/run-tests.yml

update-coverage:
if: ${{ needs.run-tests.outputs.current-coverage > needs.run-tests.outputs.stored-coverage }}
name: Update coverage
runs-on: ubuntu-latest
needs:
- run-tests
env:
CURRENT_COVERAGE: ${{ needs.run-tests.outputs.current-coverage }}
STORED_COVERAGE: ${{ needs.run-tests.outputs.stored-coverage }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Update coverage
run: |
echo "{ \"coverage\": $CURRENT_COVERAGE }" > coverage.json
- name: Checkout/create branch, commit, and force push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b metamaskbot/update-coverage
git add coverage.json
git commit -m "chore: Update coverage.json"
git push -f origin metamaskbot/update-coverage
- name: Create/update pull request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create --title "chore: Update coverage.json" --body "This PR is automatically opened to update the coverage.json file when test coverage increases. Coverage increased from $STORED_COVERAGE% to $CURRENT_COVERAGE%." --base develop --head metamaskbot/update-coverage || gh pr edit --body "This PR is automatically opened to update the coverage.json file when test coverage increases. Coverage increased from $STORED_COVERAGE% to $CURRENT_COVERAGE%."
26 changes: 26 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coverage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "coverage": 0 }
2 changes: 2 additions & 0 deletions privacy-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"mainnet.infura.io",
"metamask.eth",
"metamask.github.io",
"metametrics.metamask.test",
"min-api.cryptocompare.com",
"nft.api.cx.metamask.io",
"oidc.api.cx.metamask.io",
Expand All @@ -42,6 +43,7 @@
"portfolio.metamask.io",
"price.api.cx.metamask.io",
"proxy.api.cx.metamask.io",
"proxy.dev-api.cx.metamask.io",
"raw.githubusercontent.com",
"registry.npmjs.org",
"responsive-rpc.test",
Expand Down
2 changes: 2 additions & 0 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ export enum MetaMetricsEventName {
EncryptionPublicKeyApproved = 'Encryption Approved',
EncryptionPublicKeyRejected = 'Encryption Rejected',
EncryptionPublicKeyRequested = 'Encryption Requested',
ErrorOccured = 'Error occured',
ExternalLinkClicked = 'External Link Clicked',
KeyExportSelected = 'Key Export Selected',
KeyExportRequested = 'Key Export Requested',
Expand All @@ -556,6 +557,7 @@ export enum MetaMetricsEventName {
MarkAllNotificationsRead = 'Notifications Marked All as Read',
MetricsOptIn = 'Metrics Opt In',
MetricsOptOut = 'Metrics Opt Out',
MetricsDataDeletionRequest = 'Delete MetaMetrics Data Request Submitted',
NavAccountMenuOpened = 'Account Menu Opened',
NavConnectedSitesOpened = 'Connected Sites Opened',
NavMainMenuOpened = 'Main Menu Opened',
Expand Down
Loading

0 comments on commit f4ef0da

Please sign in to comment.