-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
48 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,37 +1,77 @@ | ||
name: Test | ||
on: | ||
push: | ||
branches: | ||
- dev | ||
- master | ||
|
||
env: | ||
DOTNET_INSTALL_DIR: "./.dotnet" | ||
Solution_Name: AElf.All.sln | ||
Service_Name: AELF | ||
permissions: | ||
contents: read | ||
actions: read | ||
checks: write | ||
|
||
jobs: | ||
test: | ||
build-test: | ||
name: Build & Test | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
contents: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup dotnet | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: '6.0' | ||
|
||
- name: Download AElf build tools | ||
run: bash scripts/download_binary.sh | ||
- run: dotnet restore | ||
- run: dotnet build --no-restore | ||
- run: dotnet test --no-build --no-restore --verbosity normal -l:"trx;LogFileName=TestResults.xml" | ||
|
||
- name: Install xmlstarlet | ||
run: sudo apt-get install -y xmlstarlet | ||
|
||
- name: Install Protobuf | ||
run: bash scripts/install_protobuf.sh | ||
- name: Extract Test Counts | ||
id: test_counts | ||
run: | | ||
passed=0 | ||
failed=0 | ||
skipped=0 | ||
for file in $(find . -name 'TestResults.xml') | ||
do | ||
passed=$((passed + $(xmlstarlet sel -t -v "/TestRun/ResultSummary/Counters/@passed" "$file"))) | ||
failed=$((failed + $(xmlstarlet sel -t -v "/TestRun/ResultSummary/Counters/@failed" "$file"))) | ||
total=$(xmlstarlet sel -t -v "/TestRun/ResultSummary/Counters/@total" "$file") | ||
executed=$(xmlstarlet sel -t -v "/TestRun/ResultSummary/Counters/@executed" "$file") | ||
skipped=$((total - executed)) | ||
done | ||
echo "::set-output name=passed::$passed" | ||
echo "::set-output name=failed::$failed" | ||
echo "::set-output name=skipped::$skipped" | ||
- name: Update Gist | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{secrets.GIST_TOKEN}} | ||
script: | | ||
const fs = require('fs'); | ||
const passed = "${{ steps.test_counts.outputs.passed }}"; | ||
const failed = "${{ steps.test_counts.outputs.failed }}"; | ||
const skipped = "${{ steps.test_counts.outputs.skipped }}"; | ||
const gistId = "59e13bd3823d754542ac98d24b3329b4"; | ||
const filename = "test-results.json"; | ||
const color = failed > 0 ? "red" : "brightgreen"; | ||
const content = `{"schemaVersion":1,"label":"tests","message":"${passed} passed, ${failed} failed, ${skipped} skipped","color":"${color}"}`; | ||
- name: Build Solution | ||
run: bash scripts/build.sh | ||
let gist; | ||
try { | ||
gist = await github.rest.gists.get({ gist_id: gistId }); | ||
} catch (error) { | ||
if (error.status !== 404) { | ||
throw error; | ||
} | ||
} | ||
- name: Run Tests | ||
run: dotnet test ${{ env.Solution_Name }} | ||
await github.rest.gists.update({ | ||
gist_id: gistId, | ||
files: { | ||
[filename]: { content } | ||
} | ||
}); |