diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..3200360 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,70 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: Build + +on: + workflow_dispatch: + push: + branches: [ "dev"] + paths: + - src/** + - test/** + pull_request: + paths: + - src/** + - test/** + +jobs: + build_and_test: + + runs-on: ubuntu-latest + env: + PackageOutputDir: ".packages" + TESTRESULTS_DIRECTORY: '.test_results' + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v3.0.0 + with: + versionSpec: '6.x' + + - name: Determine Version + run: | + ${GITVERSION_PATH}/dotnet-gitversion /output buildserver /output json + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: | + dotnet build --nologo --no-restore -p:AssemblyVersion=${GitVersion_AssemblySemVer} -p:FileVersion=${GitVersion_MajorMinorPatch} -p:Configuration=Release + + - name: Test + run: | + dotnet tool install -g dotnet-reportgenerator-globaltool --ignore-failed-sources + dotnet test --no-restore --verbosity normal --results-directory="${TESTRESULTS_DIRECTORY}" --logger:trx --collect:"XPlat Code Coverage${CI_DOTNET_TEST_COLLECTOR_OPT}" --nologo || (true && echo "ERROR test failure" >> errors) + reportgenerator -reports:${TESTRESULTS_DIRECTORY}/**/coverage.cobertura.xml '-reporttypes:TextSummary' -targetdir:${TESTRESULTS_DIRECTORY}/CoverageReports + printf 'TEST_TOTAL_COVERAGE: ' && grep 'Line coverage:' ${TESTRESULTS_DIRECTORY}/CoverageReports/Summary.txt | awk -F': ' '{print $2}' + if [ -e errors ] ; then cat errors ; exit 1 ; fi + + - name: Run codacy-coverage-reporter + uses: codacy/codacy-coverage-reporter-action@v1.3.0 + with: + project-token: ${{ secrets.CODACY_API_KEY }} + coverage-reports: ${{ env.TESTRESULTS_DIRECTORY }}/**/*cobertura.xml + + - name: Archive test report + uses: actions/upload-artifact@v4 + with: + name: test-report + path: ${{ env.TESTRESULTS_DIRECTORY }}/**/*.* \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..cd09e39 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,73 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: Publish + +on: + workflow_dispatch: + inputs: + prerelease: + default: true + type: boolean + required: true + push: + default: false + type: boolean + description: Push to nuget.org + + push: + branches: [ "main" ] + +jobs: + publish: + + runs-on: ubuntu-latest + env: + PackageOutputDir: ".packages" + Prerelease: ${{ github.event.inputs.prerelease || 'false' }} + PushPackage: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/master') || github.event.inputs.push }} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v3.0.0 + with: + versionSpec: '6.x' + + - name: Determine Version + run: | + ${GITVERSION_PATH}/dotnet-gitversion /output buildserver /output json + + - name: Pack + run: | + dotnet pack --nologo -o ${PackageOutputDir} \ + -p:PackageVersion=${GitVersion_SemVer} \ + -p:AssemblyVersion=${GitVersion_AssemblySemFileVer} \ + -p:FileVersion=${GitVersion_MajorMinorPatch} \ + -p:AssemblyVersion=${GitVersion_AssemblySemVer} \ + -p:FileVersion=${GitVersion_MajorMinorPatch} \ + -p:Configuration=Release + + - name: Nuget Push + if: env.PushPackage == 'true' + working-directory: ${{ env.PackageOutputDir }} + run: dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${{secrets.NUGET_API_KEY}} + + - name: Create Release + uses: ncipollo/release-action@v1 + with: + name: v${{ env.GitVersion_SemVer }} + tag: v${{ env.GitVersion_SemVer }} + artifacts: ${{ env.PackageOutputDir }}/*.nupkg + generateReleaseNotes: true + commit: ${{ env.GitVersion_Sha}} + prerelease: ${{ env.Prerelease }} + diff --git a/GitVersion.yml b/GitVersion.yml index 90f2eaa..e5c14da 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,11 +1,11 @@ mode: ContinuousDelivery branches: main: - tag: '' + label: '' increment: Patch - is-mainline: true + is-main-branch: true develop: - tag: rc + label: rc ignore: sha: [] merge-message-formats: {} diff --git a/README.MD b/README.MD index b24a87b..6bd8663 100644 --- a/README.MD +++ b/README.MD @@ -2,8 +2,7 @@ [![NuGet Version](https://img.shields.io/nuget/vpre/ApiCodeGenerator.MSBuild?style=flat-square)](https://www.nuget.org/packages/ApiCodeGenerator.MSBuild) [![GitHub License](https://img.shields.io/github/license/MobileTeleSystems/ApiCodeGenerator?style=flat-square)](https://github.com/MobileTeleSystems/ApiCodeGenerator/blob/dev/LICENSE) -![Code Coverage](https://img.shields.io/badge/84.90%25-z?style=flat-square&label=coverage) +[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/bcf93c4065c3442b92e5e95671b8cfcf)](https://app.codacy.com/gh/MobileTeleSystems/ApiCodeGenerator/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage) # How to install