Skip to content

Commit

Permalink
Merge branch 'develop' into fix-no-permission-state
Browse files Browse the repository at this point in the history
  • Loading branch information
NidhiKJha authored Oct 8, 2024
2 parents ca4fb3e + 44aa027 commit 75fed70
Show file tree
Hide file tree
Showing 165 changed files with 4,432 additions and 2,956 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%."
4 changes: 4 additions & 0 deletions .metamaskrc.dist
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ BLOCKAID_PUBLIC_KEY=
; Enable/disable why did you render debug tool: https://github.com/welldone-software/why-did-you-render
; This should NEVER be enabled in production since it slows down react
; ENABLE_WHY_DID_YOU_RENDER=false

; API key used in Etherscan requests to prevent rate limiting.
; Only applies to Mainnet and Sepolia.
; ETHERSCAN_API_KEY=
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.scss
.nyc_output/**/*
node_modules/**/*
# Exclude lottie json files
/app/images/animations/**/*.json
/app/vendor/**
/builds/**/*
/coverage/**/*
Expand Down
17 changes: 0 additions & 17 deletions app/_locales/de/messages.json

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

17 changes: 0 additions & 17 deletions app/_locales/el/messages.json

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

Loading

0 comments on commit 75fed70

Please sign in to comment.