diff --git a/.github/workflows/ci-cd-workflow.yml b/.github/workflows/ci-cd-workflow.yml new file mode 100644 index 0000000..580868d --- /dev/null +++ b/.github/workflows/ci-cd-workflow.yml @@ -0,0 +1,110 @@ +name: ๐Ÿš€ CI/CD workflow + +on: + push: + branches: + - main + - feat/* + pull_request: + branches: + - main + +permissions: + contents: write + checks: write + pull-requests: write + +jobs: + build: + runs-on: ubuntu-latest + outputs: + tests_passed: ${{ steps.test-status.outputs.tests_passed }} + + steps: + - name: ๐Ÿง‘โ€๐Ÿ’ป Checkout Repository + uses: actions/checkout@v4 + + - name: ๐Ÿ”ง Set Up .NET Core SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '9.x' + + - name: ๐Ÿ” Trust ASP.NET Core Developer Certificate + run: dotnet dev-certs https --trust + + - name: ๐Ÿ› ๏ธ Install trx2junit Tool + if: github.event_name == 'pull_request' + run: dotnet tool install --global trx2junit + + - name: ๐Ÿ“ฆ Restore Dependencies + run: dotnet restore + + - name: ๐Ÿ—๏ธ Build Project + run: dotnet build --configuration Release + + - name: ๐Ÿงช Run All Tests + id: run-tests + run: | + mkdir -p ./test-results + all_tests_passed=true + + for proj in $(find test -name "*.csproj"); do + proj_name=$(basename $proj .csproj) + if ! dotnet test "$proj" --configuration Release --logger "trx;LogFileName=${proj_name}.trx" --results-directory ./test-results; then + all_tests_passed=false + fi + done + + echo "all_tests_passed=${all_tests_passed}" >> $GITHUB_OUTPUT + shell: bash + + - name: ๐Ÿ“Š Set Test Status + id: test-status + run: | + if [ "${{ steps.run-tests.outputs.all_tests_passed }}" == "true" ]; then + echo "tests_passed=true" >> $GITHUB_OUTPUT + else + echo "tests_passed=false" >> $GITHUB_OUTPUT + echo "โŒ Some tests failed. Deployment will be skipped." + fi + + - name: ๐Ÿ”„ Convert Test Results to JUnit Format + if: github.event_name == 'pull_request' + run: find ./test-results -name '*.trx' -exec trx2junit {} \; + + - name: ๐Ÿ“‘ Publish Test Results as PR Comment + if: github.event_name == 'pull_request' + uses: EnricoMi/publish-unit-test-result-action@v2 + with: + files: '**/test-results/*.xml' + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: โœ… Add Check Comments for Failed Code Lines + if: github.event_name == 'pull_request' + uses: mikepenz/action-junit-report@v3 + with: + report_paths: '**/test-results/*.xml' + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: ๐Ÿ“ฆ Publish Project + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.test-status.outputs.tests_passed == 'true' + run: dotnet publish --configuration Release --output ./publish + + - name: ๐Ÿ“ค Upload Published Artifact + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.test-status.outputs.tests_passed == 'true' + uses: actions/upload-artifact@v4 + with: + name: published-app + path: ./publish + + download-artifact: + runs-on: ubuntu-latest + needs: build + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.build.outputs.tests_passed == 'true' + + steps: + - name: โฌ‡๏ธ Download Published Artifact + uses: actions/download-artifact@v4 + with: + name: published-app + path: ./downloaded-publish \ No newline at end of file diff --git a/test/InterviewAssistant.Web.Tests/InterviewAssistant.Web.Tests.csproj b/test/InterviewAssistant.Web.Tests/InterviewAssistant.Web.Tests.csproj index 177e9d0..8989fd2 100644 --- a/test/InterviewAssistant.Web.Tests/InterviewAssistant.Web.Tests.csproj +++ b/test/InterviewAssistant.Web.Tests/InterviewAssistant.Web.Tests.csproj @@ -28,4 +28,8 @@ - + + + + + \ No newline at end of file