From 68fe216a538f10cde5648d0f23d3aa6e1327699a Mon Sep 17 00:00:00 2001 From: wes Date: Sat, 1 Mar 2025 15:43:42 +0100 Subject: [PATCH] github action --- .github/workflows/build-deploy.yml | 71 +++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml index 4f044aa..674705e 100644 --- a/.github/workflows/build-deploy.yml +++ b/.github/workflows/build-deploy.yml @@ -1,12 +1,12 @@ -name: Build, Test and Release +name: Build, Test and Deploy on: push: branches: - - master + - main jobs: - build-deploy: + build: runs-on: windows-latest steps: - name: Checkout repository @@ -23,23 +23,72 @@ jobs: - name: Build solution run: dotnet build ConfigCreator/ConfigCreator.sln --configuration Release - - name: Run tests - run: dotnet test ConfigCreator/Testing/Testing.csproj --configuration Release --no-build - - name: Publish WPF App run: dotnet publish ConfigCreator/ConfigCreator.App/ConfigCreator.App.csproj --configuration Release --output published - - name: Create ZIP archive + - name: Create ZIP archive of published app run: Compress-Archive -Path published\* -DestinationPath release.zip - - name: Create Release + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: app-build + path: release.zip + + test: + runs-on: windows-latest + needs: build + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '6.0.x' + + - name: Restore dependencies + run: dotnet restore ConfigCreator/ConfigCreator.sln + + - name: Run tests + run: dotnet test ConfigCreator/Testing/Testing.csproj --configuration Release --logger "trx;LogFileName=test_results.trx" + + - name: Upload test results artifact + uses: actions/upload-artifact@v4 + with: + name: test-results + path: '**/TestResults/*.trx' + + deploy: + runs-on: windows-latest + needs: test + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set Release Version + id: set_release_version + shell: bash + run: | + version=$(cat ConfigCreator/version.txt) + commit=$(git rev-parse --short HEAD) + release_version="${version}-${commit}" + echo "release_version=$release_version" >> $GITHUB_OUTPUT + + - name: Download build artifact + uses: actions/download-artifact@v4 + with: + name: app-build + path: . + + - name: Create GitHub Release id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: v${{ github.run_number }} - release_name: Release ${{ github.run_number }} + tag_name: v${{ steps.set_release_version.outputs.release_version }} + release_name: Release ${{ steps.set_release_version.outputs.release_version }} draft: false prerelease: false @@ -50,5 +99,5 @@ jobs: with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: release.zip - asset_name: ConfigCreator.zip + asset_name: ConfigCreator-${{ steps.set_release_version.outputs.release_version }}.zip asset_content_type: application/zip