Fix readme #1
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
name: Test | |
on: | |
push: | |
branches: | |
- dev | |
- master | |
- feature/use-github-actions | |
env: | |
DOTNET_INSTALL_DIR: "./.dotnet" | |
SOLUTION_NAME: "AElf.All.sln" | |
GIST_ID: "59e13bd3823d754542ac98d24b3329b4" | |
jobs: | |
build-and-test: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup dotnet | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '8.0' | |
- name: Download AElf build tools | |
run: bash scripts/download_binary.sh | |
- name: Install Protobuf | |
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler | |
- run: dotnet restore ${{ env.SOLUTION_NAME }} | |
- run: dotnet build --no-restore ${{ env.SOLUTION_NAME }} | |
- name: Run Unit Tests | |
run: | | |
for testproj in $(find . -name '*Tests.csproj') | |
do | |
dotnet test --no-build --no-restore --verbosity normal -l:"trx;LogFileName=TestResults.xml" $testproj || true | |
done | |
- name: Install xmlstarlet | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y xmlstarlet | |
- name: Extract Test Counts | |
id: test_counts | |
run: | | |
passed=0 | |
failed=0 | |
skipped=0 | |
for file in $(find . -name 'TestResults.xml') | |
do | |
passed_value=$(xmlstarlet sel -N x="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" -t -v "/x:TestRun/x:ResultSummary/x:Counters/@passed" "$file") | |
passed=$((passed + passed_value)) | |
failed_value=$(xmlstarlet sel -N x="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" -t -v "/x:TestRun/x:ResultSummary/x:Counters/@failed" "$file") | |
failed=$((failed + failed_value)) | |
total_value=$(xmlstarlet sel -N x="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" -t -v "/x:TestRun/x:ResultSummary/x:Counters/@total" "$file") | |
executed_value=$(xmlstarlet sel -N x="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" -t -v "/x:TestRun/x:ResultSummary/x:Counters/@executed" "$file") | |
skipped_value=$((total_value - executed_value)) | |
skipped=$((skipped + skipped_value)) | |
done | |
echo "PASSED=$passed" >> $GITHUB_ENV | |
echo "FAILED=$failed" >> $GITHUB_ENV | |
echo "SKIPPED=$skipped" >> $GITHUB_ENV | |
- name: Get branch name | |
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV | |
- name: Update Gist | |
uses: actions/github-script@v5 | |
with: | |
github-token: ${{ secrets.GIST_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const passed = "${{ env.PASSED }}"; | |
const failed = "${{ env.FAILED }}"; | |
const skipped = "${{ env.SKIPPED }}"; | |
const gistId = "${{ env.GIST_ID }}"; | |
let branchName = "${{ env.BRANCH_NAME }}"; | |
branchName = branchName.replace(/\//g, '-'); | |
const filename = `${branchName}-test-results.json`; | |
const color = failed > 0 ? "red" : (skipped > 0 ? "green" : "brightgreen"); | |
const content = `{"schemaVersion":1,"label":"tests","message":"${passed} passed, ${failed} failed, ${skipped} skipped","color":"${color}"}`; | |
let gist; | |
try { | |
gist = await github.rest.gists.get({ gist_id: gistId }); | |
} catch (error) { | |
if (error.status !== 404) { | |
throw error; | |
} | |
} | |
await github.rest.gists.update({ | |
gist_id: gistId, | |
files: { | |
[filename]: { content } | |
} | |
}); |