From f8e1996630a3b89793693c3cdf11de899c97704a Mon Sep 17 00:00:00 2001 From: Eppin <96589679+Eppin@users.noreply.github.com> Date: Sat, 2 Nov 2024 11:29:06 +0100 Subject: [PATCH] Changed actions, to build for multiple destinations --- .github/actions/app-build/action.yml | 47 ++++++++++++++++ .github/workflows/dotnet-build.yml | 80 ++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 .github/actions/app-build/action.yml create mode 100644 .github/workflows/dotnet-build.yml diff --git a/.github/actions/app-build/action.yml b/.github/actions/app-build/action.yml new file mode 100644 index 0000000..1e4a441 --- /dev/null +++ b/.github/actions/app-build/action.yml @@ -0,0 +1,47 @@ +name: 'Build .NET app' +description: 'Build .NET app, upload artifact and compress' + +inputs: + dotnet: + description: '.NET version' + required: true + default: 'net8.0-windows' + + platform: + description: 'Platform' + required: true + default: 'win-x64' + + project: + description: 'Project' + required: true + + artifact: + description: 'Artifact name' + required: true + + version: + description: 'Version' + required: true + default: 1.0.0.0 + +runs: + using: "composite" + steps: + # Build applications + - name: Build application + shell: pwsh + run: dotnet publish -c Release -r ${{ inputs.platform }} --sc false -p:PublishSingleFile=true /p:Version=${{ inputs.version }} .\${{ inputs.project }}\${{ inputs.project }}.csproj + + # Upload artifact + - name: Upload build artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.artifact }} + path: .\${{ inputs.project }}\bin\Release\${{ inputs.dotnet }}\${{ inputs.platform }}\publish + + # Compress application + - name: application + if: github.event_name != 'pull_request' + shell: pwsh + run: Compress-Archive .\${{ inputs.project }}\bin\Release\${{ inputs.dotnet }}\${{ inputs.platform }}\publish\* ${{ inputs.artifact }} diff --git a/.github/workflows/dotnet-build.yml b/.github/workflows/dotnet-build.yml new file mode 100644 index 0000000..0b97438 --- /dev/null +++ b/.github/workflows/dotnet-build.yml @@ -0,0 +1,80 @@ +name: .NET Desktop + +on: + push: + branches: [ "main", "develop" ] + tags-ignore: [ "**" ] + pull_request: + branches: [ "main", "develop" ] + +jobs: + build: + runs-on: windows-latest + + permissions: + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: | + 6.0.x + 7.0.x + 8.0.x + + - name: Restore packages + run: dotnet restore + + # Get current date for release naming + - name: Get current date + id: date + run: echo "DATE=$(date +'%y.%m.%d')" >> $ENV:GITHUB_OUTPUT + + # Build applications + - name: Build for Windows x64 + uses: ./.github/actions/app-build + with: + dotnet: 'net6.0-windows' + platform: 'win-x64' + project: 'PokeNX.DesktopApp' + artifact: 'windows-x64' + version: '${{ steps.date.outputs.DATE }}.${{ github.run_number }}' + + - name: Build for macOS arm64 + uses: ./.github/actions/app-build + with: + dotnet: 'net6.0' + platform: 'osx-arm64' + project: 'PokeNX.DesktopApp' + artifact: 'macos-arm64' + version: '${{ steps.date.outputs.DATE }}.${{ github.run_number }}' + + # Create pre-release + - name: Pre-Release + uses: softprops/action-gh-release@v1 + if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/develop' }} + with: + tag_name: ${{ steps.date.outputs.DATE }}.${{ github.run_number }} + prerelease: true + body: Pre-release, compare Git commits. + files: | + windows-x64.zip + macos-arm64.zip + + # Create release + - name: Release + uses: softprops/action-gh-release@v1 + if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }} + with: + tag_name: ${{ steps.date.outputs.DATE }}.${{ github.run_number }} + prerelease: false + body: Release, compare Git commits. + files: | + windows-x64.zip + macos-arm64.zip