From 7630d1e98206a81a84107ec3daaa08cb64b3bea7 Mon Sep 17 00:00:00 2001 From: Daniel <790119+DanTheMan827@users.noreply.github.com> Date: Thu, 7 Nov 2024 07:49:26 -0600 Subject: [PATCH] Replace Azure Pipelines with GitHub Actions (#477) This replaces the old currently non-functioning Azure Pipelines configuration with an updated GitHub Actions workflow. --- .github/workflows/dotnet-desktop.yml | 112 +++++++++++++++++++++++++++ azure-pipelines.yml | 109 -------------------------- 2 files changed, 112 insertions(+), 109 deletions(-) create mode 100644 .github/workflows/dotnet-desktop.yml delete mode 100644 azure-pipelines.yml diff --git a/.github/workflows/dotnet-desktop.yml b/.github/workflows/dotnet-desktop.yml new file mode 100644 index 00000000..3adc2b5e --- /dev/null +++ b/.github/workflows/dotnet-desktop.yml @@ -0,0 +1,112 @@ +name: Build and Release .NET Desktop App + +on: + push: + tags: + - '*' + branches: + - '*' + pull_request: + branches: + - '*' + + workflow_dispatch: + +permissions: + contents: write + +jobs: + build: + runs-on: windows-latest + + env: + solution: 'hakchi_gui.sln' + buildPlatform: 'Any CPU' + buildConfiguration: 'Debug' + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: true + + - name: Install NSIS + uses: repolevedavaj/install-nsis@v1.0.2 + with: + nsis-version: '3.10' + + - name: Install .NET Framework 4.6.1 + shell: powershell + run: | + # Download the .NET Framework 4.6.1 installer + $url = "https://go.microsoft.com/fwlink/?linkid=2099470" + $outputPath = "$env:TEMP\dotnet461-installer.exe" + Invoke-WebRequest -Uri "$url" -OutFile "$outputPath" + + # Install silently + Start-Process -FilePath $outputPath -ArgumentList "/quiet", "/norestart" -Wait + + # Clean up the installer + Remove-Item -Path $outputPath + + - name: Set up .NET Core SDK 3.0 + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '3.0.x' + + - name: Setup MSBuild + uses: microsoft/setup-msbuild@v2 + + - name: Setup NuGet + uses: NuGet/setup-nuget@v2 + + - name: Restore NuGet packages + run: nuget restore ${{ env.solution }} + + - name: Prepare GamesDB API Key File + run: | + New-Item -ItemType Directory -Path "${{ github.workspace }}\hakchi_gui\ApiKeys" -Force + New-Item -ItemType File -Path "${{ github.workspace }}\hakchi_gui\ApiKeys\TheGamesDB.txt" -Force + Set-Content -Path "${{ github.workspace }}\hakchi_gui\ApiKeys\TheGamesDB.txt" -Value $env:GamesDBApiKey + env: + GamesDBApiKey: ${{ secrets.GAMESDB_API_KEY }} + + - name: Build solution + run: | + msbuild "Installer/Installer.vcxproj" /p:SolutionDir="${{ github.workspace }}\" /p:SolutionPath="${{ github.workspace }}\${{ env.solution }}" "/p:Platform=${{ env.buildPlatform }}" + + - name: Run Hakchi Version Script + run: | + $exePath = "${{ github.workspace }}\hakchi_gui\bin\Debug\net461\hakchi.exe" + $versionPath = "${{ github.workspace }}\displayVersion.txt" + & $exePath --versionFormat "{0}" --versionFile "$versionPath" + $version = Get-Content -Path $versionPath | Out-String + Remove-Item -Path $versionPath + Add-Content -Path $ENV:GITHUB_ENV -Value "displayVersion=$version" + + - name: Upload Artifacts (Portable) + uses: actions/upload-artifact@v4 + with: + name: hakchi2-ce-${{ env.displayVersion }}-portable + path: ${{ github.workspace }}\hakchi_gui\bin\Debug\net461\ + + - name: Upload Artifacts (Installer) + uses: actions/upload-artifact@v4 + with: + name: hakchi2-ce-${{ env.displayVersion }}-installer + path: ${{ github.workspace }}\hakchi_gui\bin\hakchi2-ce-${{ env.displayVersion }}-installer.exe + + - name: Create GitHub Release + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + name: Hakchi2 CE v${{ env.displayVersion }} + tag_name: ${{ github.ref_name }} + draft: true + prerelease: false + generate_release_notes: true + files: | + hakchi_gui/bin/hakchi2-ce-${{ env.displayVersion }}-installer.exe + hakchi_gui/bin/hakchi2-ce-${{ env.displayVersion }}-portable.zip + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 1104e17d..00000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,109 +0,0 @@ -# .NET Desktop -# Build and run tests for .NET Desktop or Windows classic desktop solutions. -# Add steps that publish symbols, save build artifacts, and more: -# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net - -name: $(Build.SourceVersion)-$(date:yyyy-MM-dd)$(rev:.r) - -trigger: - tags: - include: - - '*' - branches: - include: - - '*' -pr: - branches: - include: - - '*' # must quote since "*" is a YAML reserved character; we want a string - -pool: - vmImage: 'windows-2019' - -variables: - solution: 'hakchi_gui.sln' - buildPlatform: 'Any CPU' - buildConfiguration: 'Debug' - -steps: - -- checkout: self - submodules: true - persistCredentials: true - -- task: NuGetToolInstaller@1 - -- task: NuGetCommand@2 - inputs: - restoreSolution: '$(solution)' - -- task: nsis@1 - inputs: - scriptFile: - justInclude: 'yes' - includeMorePlugins: 'no' - -- task: DownloadSecureFile@1 - name: GamesDBApiKey - continueOnError: true - inputs: - secureFile: 'TheGamesDB.txt' - -- script: mkdir "$(System.DefaultWorkingDirectory)/hakchi_gui/ApiKeys" && copy "$(GamesDBApiKey.secureFilePath)" "$(System.DefaultWorkingDirectory)/hakchi_gui/ApiKeys/TheGamesDB.txt" - continueOnError: true - -- task: VSBuild@1 - inputs: - solution: 'hakchi_gui.sln' - configuration: 'Installer' - platform: 'Any CPU' - -- task: CmdLine@2 - inputs: - script: | - $(System.DefaultWorkingDirectory)/hakchi_gui/bin/Debug/net461/hakchi.exe --versionFormat "##vso[task.setvariable variable=displayVersion]{0}" --versionFile displayVersion.txt - cat displayVersion.txt - del displayVersion.txt - -- task: CopyFiles@2 - inputs: - SourceFolder: '$(System.DefaultWorkingDirectory)/hakchi_gui/bin/' - Contents: 'hakchi2-ce-*' - TargetFolder: '$(Build.ArtifactStagingDirectory)' - CleanTargetFolder: true - OverWrite: true - preserveTimestamp: true - -- task: CopyFiles@2 - inputs: - SourceFolder: '$(System.DefaultWorkingDirectory)/hakchi_gui/bin/' - Contents: 'hakchi2-ce-*installer.exe' - TargetFolder: '$(System.DefaultWorkingDirectory)/hakchi_gui/bin/installer/' - CleanTargetFolder: true - OverWrite: true - preserveTimestamp: true - -- task: PublishBuildArtifacts@1 - inputs: - PathtoPublish: '$(System.DefaultWorkingDirectory)/hakchi_gui/bin/Debug/net461/' - ArtifactName: 'hakchi2-ce-$(displayVersion)-portable' - publishLocation: 'Container' - -- task: PublishBuildArtifacts@1 - inputs: - PathtoPublish: '$(System.DefaultWorkingDirectory)/hakchi_gui/bin/installer/' - ArtifactName: 'hakchi2-ce-$(displayVersion)-installer' - publishLocation: 'Container' - -- task: GitHubRelease@1 - continueOnError: true - inputs: - gitHubConnection: 'github.com_DanTheMan827' - repositoryName: '$(Build.Repository.Name)' - action: 'create' - target: '$(Build.SourceVersion)' - tagSource: 'gitTag' - title: 'Hakchi2 CE v$(displayVersion)' - isDraft: true - changeLogCompareToRelease: 'lastFullRelease' - changeLogType: 'commitBased'