Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚗️ Test for CI System (#12) #29

Merged
merged 49 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f56099e
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
34bd2cf
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
d673768
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
a2b9c02
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
0c14e4b
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
775d860
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
1d6b7e8
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
19067dc
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
25e33f9
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
0dda01c
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
a4e5a3c
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
b72d2b2
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
1406216
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
4320c8c
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
c85ed43
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
f1719a7
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
71c8401
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
4ad3e88
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
d252914
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
f8cab89
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
afed9d1
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
d9739c2
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
b3c7cd0
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
02c256e
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
5cc877c
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
4160725
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
43b7835
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
70ae278
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
e3bb748
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
3d566dd
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
4aebad6
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
19340e9
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
f225255
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
9d6833f
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
9faa98d
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
aab7772
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
9b95897
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
0754905
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
f564612
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
b6748f7
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
327e9e5
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
b5a3d73
:alembic: Test for CI System (#12)
soo-bak Jul 7, 2024
cea35f0
:alembic: Test for CI System (#12)
soo-bak Jul 8, 2024
0aaba05
:alembic: Test for CI System (#12)
soo-bak Jul 8, 2024
29cb6e8
:alembic: Test for CI System (#12)
soo-bak Jul 8, 2024
99597fe
:alembic: Test for CI System (#12)
soo-bak Jul 8, 2024
91e8486
:alembic: Test for CI System (#12)
soo-bak Jul 8, 2024
b5b221c
:alembic: Test for CI System (#12)
soo-bak Jul 8, 2024
d59fd32
:alembic: Test for CI System (#12)
soo-bak Jul 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions .github/workflows/TestAndCoverageUnityPackage.yml

This file was deleted.

214 changes: 214 additions & 0 deletions .github/workflows/UnitTestsAndCodeCoverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
name: 🧪 Unit Tests And Code Coverage

on:
pull_request:
branches:
- main

jobs:
testAllModes:
name: Test in ${{ matrix.testMode }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
projectPath:
- temp_package
unityVersion: [2022.3.21f1]
testMode:
- playmode
- editmode
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Create temp_package directory
run: mkdir temp_package

- name: Move package to temp_package directory
run: |
shopt -s extglob
mv !(temp_package|.github) temp_package/
mv .github temp_package/.github

- name: Verify package.json existence
run: |
if [ ! -f temp_package/package.json ]; then
echo "package.json not found in temp_package"
exit 1
fi

- name: Get runner's uid and gid
id: runner-info
run: |
echo "uid=$(id -u)" >> $GITHUB_ENV
echo "gid=$(id -g)" >> $GITHUB_ENV

- name: Run Unity Tests
uses: game-ci/unity-test-runner@v4
id: tests
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
packageMode: true
projectPath: ${{ matrix.projectPath }}
unityVersion: ${{ matrix.unityVersion }}
testMode: ${{ matrix.testMode }}
artifactsPath: ${{ matrix.testMode }}-artifacts
githubToken: ${{ secrets.GITHUB_TOKEN }}
checkName: ${{ matrix.testMode }} Test Results
coverageOptions: 'generateAdditionalMetrics;generateHtmlReport;generateBadgeReport;assemblyFilters:+Soobak.SoobakUnityLibrary.*'

- name: Upload Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: Test results for ${{ matrix.testMode }}
path: ${{ matrix.testMode }}-artifacts

- name: Upload Coverage Results
uses: actions/upload-artifact@v4
if: always()
with:
name: Coverage results for ${{ matrix.testMode }}
path: CodeCoverage/

- name: Upload Badge Coverage Report
uses: actions/upload-artifact@v4
if: always()
with:
name: Badge coverage report for ${{ matrix.testMode }}
path: CodeCoverage/Report/badge_linecoverage.svg

- name: Check if Summary.xml Exists
id: check_summary
run: |
if [ -f CodeCoverage/Report/Summary.xml ]; then
echo "SUMMARY_EXISTS=true" >> $GITHUB_ENV
else
echo "SUMMARY_EXISTS=false" >> $GITHUB_ENV
fi

- name: Setup Node.js
if: env.SUMMARY_EXISTS == 'true'
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install Dependencies
if: env.SUMMARY_EXISTS == 'true'
run: npm install xml2js @actions/github@latest

- name: Create Node.js Script
if: env.SUMMARY_EXISTS == 'true'
run: |
cat << EOF > script.js
const fs = require('fs');
const xml2js = require('xml2js');
const parser = new xml2js.Parser();
const xml = fs.readFileSync('CodeCoverage/Report/Summary.xml', 'utf8');
const { context, getOctokit } = require('@actions/github');
const github = getOctokit(process.env.GITHUB_TOKEN);

async function run() {
try {
const summary = await parseXML();
const commentBody = createCommentBody(summary);
await deleteExistingCommentAndCreateNew(commentBody);
} catch (error) {
console.error('Error:', error);
process.exit(1);
}
}

function parseXML() {
return new Promise((resolve, reject) => {
parser.parseString(xml, (err, result) => {
if (err) reject(err);
else resolve(result.CoverageReport.Summary[0]);
});
});
}

function createCommentBody(summary) {
const lineCoverage = summary.Linecoverage[0];
const methodCoverage = summary.Methodcoverage[0];

const formattedLineCoverage = formatCoverage(lineCoverage);
const formattedMethodCoverage = formatCoverage(methodCoverage);

return \`
## 🍉 Code Coverage Summary 🧐

\| Metric \| Value \|
\|----------------------\|------------------------------\|
\| Generated on \| \${summary.Generatedon[0]} \|
\| Author \| soo-bak \|
\| Assemblies \| \${summary.Assemblies[0]} \|
\| Classes \| \${summary.Classes[0]} \|
\| Files \| \${summary.Files[0]} \|
\| Covered Lines \| **\${summary.Coveredlines[0]}** \|
\| Uncovered Lines \| \${summary.Uncoveredlines[0]} \|
\| Coverable Lines \| \${summary.Coverablelines[0]} \|
\| Total Lines \| **\${summary.Totallines[0]}** \|
\| Line Coverage \| \${formattedLineCoverage} \|
\| Covered Methods \| **\${summary.Coveredmethods[0]}** \|
\| Total Methods \| **\${summary.Totalmethods[0]}** \|
\| Method Coverage \| \${formattedMethodCoverage} \|

\`;
}

function formatCoverage(coverage) {
const coverageNum = parseFloat(coverage);
if (coverageNum === 100) {
return \`\\\${\\\\rm{\\\\color{#00FF00}100\\\\\\\\%}}\\\$\`;
} else if (coverageNum >= 80) {
return \`\\\${\\\\rm{\\\\color{#FFD700}\${coverageNum}\\\\\\\\%}}\\\$\`;
} else {
return \`\\\${\\\\rm{\\\\color{#8B0000}\${coverageNum}\\\\\\\\%}}\\\$\`;
}
}

async function deleteExistingCommentAndCreateNew(body) {
const { data: comments } = await github.rest.issues.listComments({
...context.repo,
issue_number: context.issue.number,
});

const botComment = comments.find(comment =>
comment.user.login === 'github-actions[bot]' &&
comment.body.includes('Code Coverage Summary')
);

if (botComment) {
await github.rest.issues.deleteComment({
...context.repo,
comment_id: botComment.id,
});
console.log('Deleted existing comment');
}

try {
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body,
});
console.log('Created new comment');
} catch (error) {
console.error('Error creating comment:', error);
process.exit(1);
}
}

run();
EOF

- name: Run Node.js Script
if: env.SUMMARY_EXISTS == 'true'
run: node script.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/verify-commits.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Verify Commits
name: 🍉 Verify Commits

on:
pull_request:
Expand All @@ -12,7 +12,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0 # 모든 히스토리를 가져옵니다.
fetch-depth: 0 # fetch all histories

- name: Install GPG
run: |
Expand Down
3 changes: 2 additions & 1 deletion Tests/Utilities/StringExtensionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using SUL;

// XXX Consider namespace for classification structure in terms of hierarchy.
namespace SUL_Tests.Utilities {
Expand All @@ -15,7 +16,7 @@ public void Reverse_WithNonEmptyString_ReturnsReversedString() {

// Act
string result = original.Reverse();

// Assert
Assert.AreEqual(expected, result);
}
Expand Down
17 changes: 11 additions & 6 deletions Utilities/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using System;

public static class StringExtensions {
public static string Reverse(this string str) {
if (string.IsNullOrEmpty(str)) return str;
namespace SUL {

char[] charArr = str.ToCharArray();
Array.Reverse(charArr);
return new string(charArr);
public static class StringExtensions {
public static string Reverse(this string str) {
if (string.IsNullOrEmpty(str)) return str;

char[] charArr = str.ToCharArray();
Array.Reverse(charArr);

return new string(charArr);
}
}

}
Loading