diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..d54c546 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,203 @@ +name: Build and Deploy + +on: + push: + tags: [ 'v*' ] + workflow_dispatch: # Allow manual trigger + +env: + SOLUTION_FILE_PATH: ./Neptuo.Productivity.SnippetManager.sln + BUILD_CONFIGURATION: Release + BUILD_PLATFORM: x86 + APPX_PACKAGE_DIR: ${{ github.workspace }}/AppPackages + +jobs: + build: + runs-on: windows-latest + outputs: + version-number: ${{ steps.version.outputs.number }} + version-appx: ${{ steps.version.outputs.appx }} + is-release: ${{ startsWith(github.ref, 'refs/tags/v') }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '9.0.x' + + - name: Setup MSBuild + uses: microsoft/setup-msbuild@v2 + + - name: Setup NuGet + uses: NuGet/setup-nuget@v2 + + - name: Cache NuGet packages + uses: actions/cache@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-nuget- + + - name: Restore dependencies + run: dotnet restore ${{ env.SOLUTION_FILE_PATH }} -r win-${{ env.BUILD_PLATFORM }} + + - name: Extract version from tag + id: version + run: | + $version = "0.0.0" # Default version + if ($env:GITHUB_REF -like "refs/tags/v*") { + $version = $env:GITHUB_REF -replace "refs/tags/v", "" + Write-Host "Found tag version: $version" + } else { + Write-Host "No version tag found, using default: $version" + } + echo "number=$version" >> $env:GITHUB_OUTPUT + echo "appx=$version.0" >> $env:GITHUB_OUTPUT + + - name: Update Version in manifest + working-directory: './src/Neptuo.Productivity.SnippetManager.Package' + run: | + $xmlFilePath = "Package.appxmanifest" + [xml]$xml = Get-Content $xmlFilePath + $newVersion = "${{ steps.version.outputs.appx }}" + $xml.Package.Identity.Version = $newVersion + $xml.Save($xmlFilePath) + Write-Output "Version updated to $newVersion in $xmlFilePath" + + - name: Build solution + run: | + msbuild ${{ env.SOLUTION_FILE_PATH }} ` + /bl ` + /p:Configuration=${{ env.BUILD_CONFIGURATION }} ` + /p:Platform=${{ env.BUILD_PLATFORM }} ` + /p:AppxBundlePlatforms=${{ env.BUILD_PLATFORM }} ` + /p:AppxPackageDir=${{ env.APPX_PACKAGE_DIR }} ` + /p:AppxBundle=Always ` + /p:UapAppxPackageBuildMode=SideloadOnly ` + /p:AppxPackageSigningEnabled=false + + - name: List build output + run: | + Write-Host "Build output directory contents:" + Get-ChildItem -Recurse ${{ env.APPX_PACKAGE_DIR }} | Format-Table -AutoSize + + - name: Create GitHub Release + if: startsWith(github.ref, 'refs/tags/v') + uses: softprops/action-gh-release@v2 + with: + name: "v${{ steps.version.outputs.number }}" + tag_name: "v${{ steps.version.outputs.number }}" + draft: false + prerelease: false + files: | + ${{ env.APPX_PACKAGE_DIR }}/**/*.msix + ${{ env.APPX_PACKAGE_DIR }}/**/*.msixbundle + ${{ env.APPX_PACKAGE_DIR }}/**/*.appxupload + generate_release_notes: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Update App Installer file + if: startsWith(github.ref, 'refs/tags/v') + run: | + $appInstallerPath = "${{ env.APPX_PACKAGE_DIR }}" + $appInstallerFile = Get-ChildItem -Recurse -Path $appInstallerPath -Name "*.appinstaller" | Select-Object -First 1 + + if ($appInstallerFile) { + $fullPath = Join-Path $appInstallerPath $appInstallerFile + [xml]$xml = Get-Content $fullPath + + # Update the Uri to point to GitHub Pages + $xml.AppInstaller.Uri = "https://apps.neptuo.com/snippetmanager/Neptuo.Productivity.SnippetManager.Package.appinstaller" + + # Update the MainBundle Uri to point to GitHub release + $bundleName = "Neptuo.Productivity.SnippetManager.Package_${{ steps.version.outputs.appx }}_${{ env.BUILD_PLATFORM }}.msixbundle" + $xml.AppInstaller.MainBundle.Uri = "https://github.com/neptuo/Productivity.SnippetManager/releases/download/v${{ steps.version.outputs.number }}/$bundleName" + + $xml.Save($fullPath) + Write-Output "Updated App Installer file: $fullPath" + Write-Output "Bundle URL: $($xml.AppInstaller.MainBundle.Uri)" + } else { + Write-Error "App Installer file not found" + exit 1 + } + + - name: Prepare files for GitHub Pages + if: startsWith(github.ref, 'refs/tags/v') + run: | + $deployDir = "${{ github.workspace }}/deploy" + New-Item -ItemType Directory -Path $deployDir -Force + + # Copy only .appinstaller and .html files + Get-ChildItem -Recurse -Path "${{ env.APPX_PACKAGE_DIR }}" -Include "*.appinstaller", "*.html" | ForEach-Object { + Copy-Item $_.FullName -Destination $deployDir + Write-Host "Copied: $($_.Name)" + } + + Write-Host "Files prepared for deployment:" + Get-ChildItem $deployDir | Format-Table -AutoSize + + - name: Upload deployment files + if: startsWith(github.ref, 'refs/tags/v') + uses: actions/upload-artifact@v4 + with: + name: deployment-files + path: ${{ github.workspace }}/deploy + retention-days: 1 + + # Upload artifacts for development builds (non-tag pushes) + - name: Upload development build artifacts + if: ${{ !startsWith(github.ref, 'refs/tags/v') }} + uses: actions/upload-artifact@v4 + with: + name: dev-build-${{ env.BUILD_PLATFORM }}-${{ github.sha }} + path: | + ${{ env.APPX_PACKAGE_DIR }}/**/*.msix + ${{ env.APPX_PACKAGE_DIR }}/**/*.msixbundle + ${{ env.APPX_PACKAGE_DIR }}/**/*.appxupload + ${{ env.APPX_PACKAGE_DIR }}/**/*.appinstaller + ${{ env.APPX_PACKAGE_DIR }}/**/*.html + retention-days: 7 + + - name: Upload build logs + uses: actions/upload-artifact@v4 + if: failure() + with: + name: build-logs + path: | + **/*.log + **/*.binlog + retention-days: 7 + + deploy: + needs: build + runs-on: ubuntu-latest + if: needs.build.outputs.is-release == 'true' + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download deployment files + uses: actions/download-artifact@v4 + with: + name: deployment-files + path: ./deploy + + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@v4 + with: + token: ${{ secrets.PAGES_DEPLOY_TOKEN }} + repository-name: neptuo/com.neptuo.apps + branch: gh-pages + folder: ./deploy + target-folder: snippetmanager + clean: true + single-commit: true + commit-message: "Deploy Snippet Manager v${{ needs.build.outputs.version-number }}" diff --git a/src/Neptuo.Productivity.SnippetManager.Package/Neptuo.Productivity.SnippetManager.Package.wapproj b/src/Neptuo.Productivity.SnippetManager.Package/Neptuo.Productivity.SnippetManager.Package.wapproj index 1a62b6b..b5b2262 100644 --- a/src/Neptuo.Productivity.SnippetManager.Package/Neptuo.Productivity.SnippetManager.Package.wapproj +++ b/src/Neptuo.Productivity.SnippetManager.Package/Neptuo.Productivity.SnippetManager.Package.wapproj @@ -62,10 +62,9 @@ False True x86 - \\heap\Temp\SnippetManager + https://apps.neptuo.com/snippetmanager 0 E91A19A0E44C1DD0640117CBD55AAFA516E4D866 - \\heap\Temp\SnippetManager Always diff --git a/src/Neptuo.Productivity.SnippetManager.Package/Package.appxmanifest b/src/Neptuo.Productivity.SnippetManager.Package/Package.appxmanifest index c76fc5d..65cfa18 100644 --- a/src/Neptuo.Productivity.SnippetManager.Package/Package.appxmanifest +++ b/src/Neptuo.Productivity.SnippetManager.Package/Package.appxmanifest @@ -10,7 +10,7 @@ + Version="0.23.0.0" /> Snippet Manager by Neptuo