diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..057c59e --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,134 @@ +name: .NET Build and Test +on: + push: + +env: + App_Name: WpfReleaseActionDemo + Solution_Path: WpfReleaseActionDemo.sln + App_Project_Path: src/WpfDemo.App/WpfDemo.App.csproj + Test_Directory: tests/WpfDemo.Test + +jobs: + build: + strategy: + matrix: + configuration: [Release] # [Debug, Release] + runs-on: windows-latest + timeout-minutes: 15 + + steps: + # Dump for debug workflow + - name: Dump Github Context + env: + GitHub_Context: ${{ toJson(github) }} + run: echo "${GitHub_Context}" + + # Checks-out repository under $GITHUB_WORKSPACE: https://github.com/actions/checkout + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + # Install the .NET workload: https://github.com/actions/setup-dotnet + - name: Install .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + # Add MsBuild to the PATH: https://github.com/microsoft/setup-msbuild + - name: Setup MSBuild.exe + uses: microsoft/setup-msbuild@v1.3.1 + + # Restore before build and test + - name: Restore + run: dotnet restore ${{ env.Solution_Path }} + + - name: Build with dotnet + run: dotnet build ${{ env.App_Project_Path }} --no-restore + env: + Configuration: ${{ matrix.configuration }} + + # Execute all unit tests in the solution + - name: Execute unit tests + run: dotnet test --no-restore + + create-release: + runs-on: windows-latest + timeout-minutes: 15 + needs: [build] + if: "contains( github.ref , 'tags/v')" + + steps: + - name: echos + shell: bash + run: | + echo $RELEASE_VERSION + echo "version=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV + echo "app_x64_framework_name=${{ env.App_Name }}_win-x64_framework-dependent_ver${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV + echo "app_x64_self_name=${{ env.App_Name }}_win-x64_self-contained_ver${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV + + # Checks-out repository under $GITHUB_WORKSPACE: https://github.com/actions/checkout + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: dotnet publish x64 Framework-dependent + run: > + dotnet publish ${{ env.App_Project_Path }} + -c Release + -r win-x64 + --self-contained false -p:UseAppHost=true + -p:PublishSingleFile=true + -p:PublishReadyToRun=false + -p:PublishTrimmed=false + -p:IncludeNativeLibrariesForSelfExtract=true + -o outputs\${{ env.app_x64_framework_name }} + + - name: dotnet publish x64 Self-contained + run: > + dotnet publish ${{ env.App_Project_Path }} + -c Release + -r win-x64 + --self-contained true + -p:PublishSingleFile=true + -p:PublishReadyToRun=false + -p:PublishTrimmed=false + -p:IncludeNativeLibrariesForSelfExtract=true + -o outputs\${{ env.app_x64_self_name }} + + # Upload Actions Artifacts: https://github.com/actions/upload-artifact + - name: Archive publish files + uses: actions/upload-artifact@v3 + with: + name: ${{ env.App_Name }} + path: outputs + + # Create zip + - name: Create zip archive + shell: pwsh + run: | + Compress-Archive -Path outputs\${{ env.app_x64_framework_name }} -DestinationPath ${{ env.app_x64_framework_name }}.zip + Compress-Archive -Path outputs\${{ env.app_x64_self_name }} -DestinationPath ${{ env.app_x64_self_name }}.zip + + # Create release page: https://github.com/ncipollo/release-action + - name: Create release + id: create_release + uses: ncipollo/release-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + tag: v${{ env.version }} + name: Ver ${{ env.version }} + body: | + - Change design + - Bug fix + draft: true + prerelease: false + artifacts: "${{ env.app_x64_framework_name }}.zip, ${{ env.app_x64_self_name }}.zip" + + # Remove artifacts to save space: https://github.com/c-hive/gha-remove-artifacts + - name: Remove old artifacts + uses: c-hive/gha-remove-artifacts@v1 + with: + age: '1 weeks' + skip-recent: 2