-
Notifications
You must be signed in to change notification settings - Fork 264
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
10 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,157 +1,22 @@ | ||
name: Test | ||
|
||
permissions: | ||
contents: write | ||
|
||
on: | ||
push: | ||
branches: | ||
- dev | ||
- master | ||
- feature/use-github-actions | ||
|
||
env: | ||
SOLUTION_NAME: "AElf.All.sln" | ||
BRANCH_NAME: "feature/badge" | ||
|
||
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') | ||
do | ||
dotnet test --no-build --no-restore --verbosity normal -l:"trx;LogFileName=TestResults.xml" --collect:"XPlat Code Coverage" $testproj || true | ||
done | ||
continue-on-error: true | ||
|
||
- name: Install ReportGenerator tool | ||
run: dotnet tool install --global dotnet-reportgenerator-globaltool | ||
|
||
- name: Create Code Coverage Report | ||
run: | | ||
reportgenerator "-reports:**/coverage.cobertura.xml" "-targetdir:./coverage/reports" -reporttypes:"Cobertura" | ||
echo "COVERAGE_FILE=./coverage/reports/Cobertura.xml" >> $GITHUB_ENV | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v2 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
file: ${{ env.COVERAGE_FILE }} | ||
fail_ci_if_error: true | ||
continue-on-error: true | ||
|
||
- 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=$((passed + $(xmlstarlet sel -N x="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" -t -v "/x:TestRun/x:ResultSummary/x:Counters/@passed" "$file"))) | ||
failed=$((failed + $(xmlstarlet sel -N x="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" -t -v "/x:TestRun/x:ResultSummary/x:Counters/@failed" "$file"))) | ||
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=$((skipped + total_value - executed_value)) | ||
done | ||
echo "PASSED=$passed" >> $GITHUB_ENV | ||
echo "FAILED=$failed" >> $GITHUB_ENV | ||
echo "SKIPPED=$skipped" >> $GITHUB_ENV | ||
- name: Set file name | ||
run: echo "FILENAME=$(echo ${GITHUB_REF#refs/heads/} | tr '/' '-')-test-results.json" >> $GITHUB_ENV | ||
|
||
- name: Prepare Content | ||
uses: actions/github-script@v5 | ||
- name: Run dotnet ci action | ||
uses: AElfProject/[email protected] | ||
with: | ||
github-token: ${{ secrets.COMMIT_TOKEN }} | ||
script: | | ||
const fs = require('fs'); | ||
const passed = "${{ env.PASSED }}"; | ||
const failed = "${{ env.FAILED }}"; | ||
const skipped = "${{ env.SKIPPED }}"; | ||
const gistId = "${{ env.GIST_ID }}"; | ||
const color = failed > 0 ? "red" : (skipped > 0 ? "green" : "brightgreen"); | ||
const content = `{"schemaVersion":1,"label":"tests","message":"${passed} passed, ${failed} failed, ${skipped} skipped","color":"${color}"}`; | ||
fs.writeFileSync("${{ env.FILENAME }}", content); | ||
- name: Check if file exists | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{ secrets.COMMIT_TOKEN }} | ||
script: | | ||
let fileExists = false; | ||
try { | ||
const { data } = await github.rest.repos.getContent({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
path: "${{ env.FILENAME }}", | ||
ref: "${{ env.BRANCH_NAME }}", | ||
}); | ||
fileExists = !!data; | ||
} catch (error) { | ||
if (error.status !== 404) { | ||
throw error; | ||
} | ||
} | ||
core.exportVariable('FILE_EXISTS', fileExists); | ||
- name: Create or update file | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{ secrets.COMMIT_TOKEN }} | ||
script: | | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const filePath = path.join(process.env.GITHUB_WORKSPACE, "${{ env.FILENAME }}"); | ||
const fileContent = fs.readFileSync(filePath, 'utf8'); | ||
const params = { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
path: "${{ env.FILENAME }}", | ||
message: `Update ${{ env.FILENAME }}`, | ||
content: Buffer.from(fileContent).toString('base64'), | ||
branch: "${{ env.BRANCH_NAME }}" | ||
}; | ||
if (${{ env.FILE_EXISTS }}) { | ||
const { data } = await github.rest.repos.getContent({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
path: "${{ env.FILENAME }}", | ||
ref: "${{ env.BRANCH_NAME }}" | ||
}); | ||
params.sha = data.sha; | ||
} | ||
await github.rest.repos.createOrUpdateFileContents(params); | ||
commit-token: ${{ secrets.COMMIT_TOKEN }} | ||
codecov-token: ${{ secrets.CODECOV_TOKEN }} | ||
branch-name: "feature/badge-json" | ||
solution-name: "AElf.All.sln" |
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