-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix-no-permission-state
- Loading branch information
Showing
165 changed files
with
4,432 additions
and
2,956 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
@@ -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 | ||
|
@@ -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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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%." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.