diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml deleted file mode 100644 index cb21995..0000000 --- a/.github/workflows/CI.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: CI - -on: - push: - tags-ignore: - - '**' - branches: - - '**' - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # fixes https://stackoverflow.com/questions/59000099/sonarqube-with-shallow-clone-warning-even-with-shallow-disabled-on-jenkins-build - - name: Set up .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: '8.0' - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: 17 - distribution: 'zulu' - - name: Restore dependencies - run: dotnet restore ThisIsYourLife.sln - - name: Begin Sonar scan - run: | - dotnet tool install --global dotnet-sonarscanner - dotnet sonarscanner begin /k:mu88_Project28 /o:mu88 /d:sonar.token=${{ secrets.SONAR_TOKEN }} /d:sonar.host.url=https://sonarcloud.io /d:sonar.cs.opencover.reportsPaths=src/Tests/coverage.opencover.xml /s:$GITHUB_WORKSPACE/SonarQube.Analysis.xml - - name: Build - run: dotnet build --no-restore ThisIsYourLife.sln - - name: Test and collect coverage - run: dotnet test --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover - - name: End Sonar scan - run: dotnet sonarscanner end /d:sonar.token=${{ secrets.SONAR_TOKEN }} - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build Docker - run: dotnet publish src/WebApp/WebApp.csproj --os linux --arch arm64 /t:PublishContainer - - name: Build single-file EXE - run: dotnet publish src/WebApp/WebApp.csproj -r win-x64 -p:PublishSingleFile=true --self-contained true diff --git a/.github/workflows/Release.yml b/.github/workflows/CI_CD.yml similarity index 57% rename from .github/workflows/Release.yml rename to .github/workflows/CI_CD.yml index 0bd678b..685b3e3 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/CI_CD.yml @@ -1,12 +1,17 @@ -name: Release +name: Combined CI / Release on: push: tags: - '*' + branches: + - '**' + +env: + IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/') }} jobs: - build: + ci_cd: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -14,29 +19,47 @@ jobs: uses: actions/setup-dotnet@v4 with: dotnet-version: '8.0' + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: 'zulu' - name: Restore dependencies run: dotnet restore ThisIsYourLife.sln + - name: Begin Sonar scan + run: | + dotnet tool install --global dotnet-sonarscanner + dotnet sonarscanner begin /k:mu88_Project28 /o:mu88 /d:sonar.token=${{ secrets.SONAR_TOKEN }} /d:sonar.host.url=https://sonarcloud.io /d:sonar.cs.opencover.reportsPaths=src/Tests/coverage.opencover.xml /s:$GITHUB_WORKSPACE/SonarQube.Analysis.xml - name: Build run: dotnet build --no-restore ThisIsYourLife.sln - - name: Test - run: dotnet test --no-build --verbosity normal ThisIsYourLife.sln + - name: Test and collect coverage + run: dotnet test --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + - name: End Sonar scan + run: dotnet sonarscanner end /d:sonar.token=${{ secrets.SONAR_TOKEN }} - name: Login to DockerHub uses: docker/login-action@v3 + if: ${{ env.IS_RELEASE == 'true' }} with: registry: registry.hub.docker.com username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Write release version + if: ${{ env.IS_RELEASE == 'true' }} run: | VERSION=${GITHUB_REF_NAME#v} echo Version: $VERSION echo "VERSION=$VERSION" >> $GITHUB_ENV - - name: Build Docker and Push + - name: Build Docker + if: ${{ env.IS_RELEASE != 'true' }} + run: dotnet publish src/WebApp/WebApp.csproj --os linux --arch arm64 /t:PublishContainer '-p:ContainerImageTags="${{ env.VERSION }};latest"' + - name: Push Docker + if: ${{ env.IS_RELEASE == 'true' }} run: dotnet publish src/WebApp/WebApp.csproj --os linux --arch arm64 /t:PublishContainer '-p:ContainerImageTags="${{ env.VERSION }};latest"' -p:ContainerRegistry=registry.hub.docker.com - name: Build single-file EXE run: dotnet publish src/WebApp/WebApp.csproj -r win-x64 -p:PublishSingleFile=true --self-contained true - name: Create ZIP for release uses: thedoctor0/zip-release@master + if: ${{ env.IS_RELEASE == 'true' }} with: type: 'zip' filename: ThisIsYourLife.${{ env.VERSION }}.zip @@ -44,12 +67,14 @@ jobs: - name: Create CHANGELOG id: changelog uses: Requarks/changelog-action@v1 + if: ${{ env.IS_RELEASE == 'true' }} with: token: ${{ github.token }} tag: ${{ github.ref_name }} excludeTypes: build,docs,other,style,chore(deps) - name: Create GitHub Release uses: softprops/action-gh-release@v1 + if: ${{ env.IS_RELEASE == 'true' }} with: files: src/WebApp/bin/Release/net8.0/win-x64/publish/ThisIsYourLife*.zip tag_name: ${{ github.ref_name }}