From cb192a6146648f490c36db928199e723ce8d5c31 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Fri, 13 Sep 2024 22:06:18 +0200 Subject: [PATCH 1/6] Review code for MSI creation --- .../workflows/WAU-AutoCreatePreVersion.yml | 125 --- .github/workflows/WAU-CreateNewVersion.yml | 94 -- .github/workflows/WAU-ReleaseBuilder.yml | 156 ++++ Sources/WAU Configurator.bat | 811 ------------------ Sources/Winget-AutoUpdate-Install.ps1 | 514 ----------- Sources/Winget-AutoUpdate/User-Run.ps1 | 99 +-- Sources/Winget-AutoUpdate/Version.txt | 1 - Sources/Winget-AutoUpdate/WAU-Uninstall.ps1 | 86 -- Sources/Winget-AutoUpdate/Winget-Install.ps1 | 28 +- Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 | 72 +- .../config/WAU-MSI_Actions.ps1 | 173 ++++ .../functions/Get-WAUConfig.ps1 | 3 +- .../functions/Install-Prerequisites.ps1 | 58 ++ .../functions/Invoke-PostUpdateActions.ps1 | 168 ---- .../functions/Update-WAU.ps1 | 111 +-- .../functions/Update-WinGet.ps1 | 73 -- Sources/Wix/build.wxs | 369 ++++++++ Sources/Wix/files/banner.bmp | Bin 0 -> 85894 bytes Sources/Wix/files/dialog.bmp | Bin 0 -> 461814 bytes Sources/Wix/files/icon.ico | Bin 0 -> 158362 bytes 20 files changed, 843 insertions(+), 2098 deletions(-) delete mode 100644 .github/workflows/WAU-AutoCreatePreVersion.yml delete mode 100644 .github/workflows/WAU-CreateNewVersion.yml create mode 100644 .github/workflows/WAU-ReleaseBuilder.yml delete mode 100644 Sources/WAU Configurator.bat delete mode 100644 Sources/Winget-AutoUpdate-Install.ps1 delete mode 100644 Sources/Winget-AutoUpdate/Version.txt delete mode 100644 Sources/Winget-AutoUpdate/WAU-Uninstall.ps1 create mode 100644 Sources/Winget-AutoUpdate/config/WAU-MSI_Actions.ps1 delete mode 100644 Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 delete mode 100644 Sources/Winget-AutoUpdate/functions/Update-WinGet.ps1 create mode 100644 Sources/Wix/build.wxs create mode 100644 Sources/Wix/files/banner.bmp create mode 100644 Sources/Wix/files/dialog.bmp create mode 100644 Sources/Wix/files/icon.ico diff --git a/.github/workflows/WAU-AutoCreatePreVersion.yml b/.github/workflows/WAU-AutoCreatePreVersion.yml deleted file mode 100644 index ba189e78..00000000 --- a/.github/workflows/WAU-AutoCreatePreVersion.yml +++ /dev/null @@ -1,125 +0,0 @@ ---- -name: WAU - Auto Create Pre-Release Version - -on: - schedule: - - cron: "0 0 * * *" - -permissions: - contents: write - -jobs: - check_merged: - name: Compare latest merge and tag - runs-on: ubuntu-latest - outputs: - should_run: ${{ steps.should_run.outputs.SHOULD_RUN }} - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Check if latest merged is older than latest tag - id: should_run - run: | - echo "Latest tag:" - git log --tags --pretty="%ci - %h - %s %d" -n 1 - LATEST_TAG_DATE=$(git log --tags -n 1 --pretty="%ct") - echo $LATEST_TAG_DATE - - echo "Latest merge:" - git log --merges --pretty="%ci - %h - %s %d" -n 1 - LATEST_MERGE_DATE=$(git log --merges -n 1 --pretty="%ct") - echo $LATEST_MERGE_DATE - - if [[ $LATEST_MERGE_DATE -gt $LATEST_TAG_DATE ]]; then - echo "Latest tag is older than latest merge. Nightly will be created." - echo "SHOULD_RUN=true" >> $GITHUB_OUTPUT - else - echo "Latest merge is not older than latest tag. No new release needed." - echo "SHOULD_RUN=false" >> $GITHUB_OUTPUT - fi - - build: - name: Create Release Asset - needs: [check_merged] - if: ${{ needs.check_merged.outputs.should_run == 'true' }} - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - lfs: "true" - fetch-depth: 0 - - - name: Auto Increment Semver Action - uses: MCKanpolat/auto-semver-action@5003b8d37f4b03d95f15303ea10242cbf7c13141 # 2 - id: versioning - with: - releaseType: Patch - incrementPerCommit: false - github_token: ${{ secrets.GITHUB_TOKEN }} - - - name: Next Release Number - id: WAU_version - run: | - echo "Next Release version: ${{ steps.versioning.outputs.version }}" - - - name: Overwrite Version.txt file - uses: DamianReeves/write-file-action@6929a9a6d1807689191dcc8bbe62b54d70a32b42 # v1.3 - with: - path: Sources/Winget-AutoUpdate/Version.txt - write-mode: overwrite - contents: ${{ steps.versioning.outputs.version }} - - - name: Commit & Push - uses: actions-js/push@5a7cbd780d82c0c937b5977586e641b2fd94acc5 # v1.5 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: main - force: true - message: "Changed version to ${{ steps.versioning.outputs.version }}" - - - name: Build project - run: | - echo "### Get MDT from Microsoft ###" - wget https://download.microsoft.com/download/3/3/9/339BE62D-B4B8-4956-B58D-73C4685FC492/MicrosoftDeploymentToolkit_x64.msi - - echo "### Extract MSI ###" - 7z x MicrosoftDeploymentToolkit_x64.msi - - echo "### Copy ServiceUI.exe to 'Sources/Winget-AutoUpdate' folder ###" - mv Modena_File206 Sources/Winget-AutoUpdate/ServiceUI.exe -v - - echo "### Go to Sources ###" - cd Sources - - echo "### Zip WAU ###" - zip -r ../WAU.zip Winget-AutoUpdate - zip ../WAU.zip Winget-AutoUpdate-Install.ps1 - - echo "### Zip WAU-Configurator ###" - zip -r ../WAU-Configurator.zip Winget-AutoUpdate - zip ../WAU-Configurator.zip "Winget-AutoUpdate-Install.ps1" - zip ../WAU-Configurator.zip "WAU Configurator.bat" - - echo "### Zip ADMX ###" - cd Policies - zip -r ../../WAU_ADMX.zip * - cd ../.. - - echo "### Create install counter file ###" - echo "Install counter file." > WAU_InstallCounter - - - name: Create release - uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0 - id: release - with: - tag: "v${{ steps.versioning.outputs.version }}" - prerelease: true - generateReleaseNotes: true - name: "v${{ steps.versioning.outputs.version }} [Nightly Build]" - artifacts: "WAU-Configurator.zip,WAU.zip,WAU_ADMX.zip,WAU_InstallCounter" - - - name: URL to release - run: echo "Release -> ${{ steps.release.outputs.html_url }}" diff --git a/.github/workflows/WAU-CreateNewVersion.yml b/.github/workflows/WAU-CreateNewVersion.yml deleted file mode 100644 index 51495293..00000000 --- a/.github/workflows/WAU-CreateNewVersion.yml +++ /dev/null @@ -1,94 +0,0 @@ ---- -name: WAU - Create New Version - -on: - workflow_dispatch: - inputs: - version: - type: choice - default: "Patch" - description: Select next release type - options: - - Patch - - Minor - - Major - required: true - pre-release: - type: boolean - description: Set as Pre-release version - -permissions: - contents: write - -jobs: - build: - name: Create Release Asset - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - lfs: "true" - - - name: Auto Increment Semver Action - uses: MCKanpolat/auto-semver-action@5003b8d37f4b03d95f15303ea10242cbf7c13141 # 2 - id: versioning - with: - releaseType: ${{ github.event.inputs.version }} - incrementPerCommit: false - github_token: ${{ secrets.GITHUB_TOKEN }} - - - name: Overwrite Version.txt file - uses: DamianReeves/write-file-action@6929a9a6d1807689191dcc8bbe62b54d70a32b42 # v1.3 - with: - path: Sources/Winget-AutoUpdate/Version.txt - write-mode: overwrite - contents: "${{ steps.versioning.outputs.version }}" - - - name: Commit & Push - uses: actions-js/push@5a7cbd780d82c0c937b5977586e641b2fd94acc5 # v1.5 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: main - force: true - message: "Changed version to ${{ steps.versioning.outputs.version }}" - - - name: Build project - run: | - echo "### Get MDT from Microsoft ###" - wget https://download.microsoft.com/download/3/3/9/339BE62D-B4B8-4956-B58D-73C4685FC492/MicrosoftDeploymentToolkit_x64.msi - - echo "### Extract MSI ###" - 7z x MicrosoftDeploymentToolkit_x64.msi - - echo "### Copy ServiceUI.exe to 'Sources/Winget-AutoUpdate' folder ###" - mv Modena_File206 Sources/Winget-AutoUpdate/ServiceUI.exe -v - - echo "### Go to Sources ###" - cd Sources - - echo "### Zip WAU ###" - zip -r ../WAU.zip Winget-AutoUpdate - zip ../WAU.zip Winget-AutoUpdate-Install.ps1 - - echo "### Zip WAU-Configurator ###" - zip -r ../WAU-Configurator.zip Winget-AutoUpdate - zip ../WAU-Configurator.zip "Winget-AutoUpdate-Install.ps1" - zip ../WAU-Configurator.zip "WAU Configurator.bat" - - echo "### Zip ADMX ###" - cd Policies - zip -r ../../WAU_ADMX.zip * - cd ../.. - - echo "### Create install counter file ###" - echo "Install counter file." > WAU_InstallCounter - - - name: Create release - uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0 - with: - tag: "v${{ steps.versioning.outputs.version }}" - prerelease: ${{ github.event.inputs.pre-release }} - generateReleaseNotes: true - name: "v${{ steps.versioning.outputs.version }}" - artifacts: "WAU-Configurator.zip,WAU.zip,WAU_ADMX.zip,WAU_InstallCounter" diff --git a/.github/workflows/WAU-ReleaseBuilder.yml b/.github/workflows/WAU-ReleaseBuilder.yml new file mode 100644 index 00000000..465cf4a4 --- /dev/null +++ b/.github/workflows/WAU-ReleaseBuilder.yml @@ -0,0 +1,156 @@ +--- +name: WAU - Release builder + +on: + # To trigger nightly release (Auto) + schedule: + - cron: "*/5 * * * *" + # To trigger stable release + workflow_dispatch: + inputs: + version: + type: choice + default: "Minor" + description: Select next release type + options: + - Patch + - Minor + - Major + required: true + pre-release: + type: boolean + description: Set as Pre-release version + +permissions: + contents: write + +jobs: + build: + name: Create Release + runs-on: windows-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + lfs: "true" + fetch-depth: 0 + + - name: Manually OR Scheduled. If Scheduled, check if release is necessary + run: | + if ("${{ github.event_name }}" -eq "schedule") { + echo "Latest tag:" + git log --tags --pretty="%ci - %h - %s %d" -n 1 + $LATEST_TAG_DATE = git log --tags -n 1 --pretty="%ct" + echo $LATEST_TAG_DATE + + echo "Latest merge:" + git log --merges --pretty="%ci - %h - %s %d" -n 1 + $LATEST_MERGE_DATE = git log --merges -n 1 --pretty="%ct" + echo $LATEST_MERGE_DATE + + if ( $LATEST_MERGE_DATE -gt $LATEST_TAG_DATE ) { + echo "Scheduled request. Latest tag is older than latest merge. Nightly prerelease will be created." + echo "ReleaseType=Prerelease" >> $env:GITHUB_ENV + } + else { + echo "Scheduled request. Latest tag is not older than latest merge. No new Nightly release needed." + echo "ReleaseType=No" >> $env:GITHUB_ENV + } + } + else { + echo "Manual request. Release will be created." + echo "ReleaseType=Release" >> $env:GITHUB_ENV + } + + - name: Auto Increment Semver Action + uses: MCKanpolat/auto-semver-action@5003b8d37f4b03d95f15303ea10242cbf7c13141 # 2 + if: env.ReleaseType != 'No' + id: versioning + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + incrementPerCommit: false + releaseType: Pre${{ github.event.inputs.version || 'patch'}} # Using Prepatch by default + + - name: Format Semver (and msi version) + if: env.ReleaseType != 'No' + # Remove "-0" for stable release and replace by "-n" for Nightlies + run: | + $NextAutoSemver = "${{ steps.versioning.outputs.version }}" + if ("${{ env.ReleaseType }}" -eq "Release") { + $MsiVersion = $NextAutoSemver.Split("-")[0] + $NextSemver = $NextAutoSemver.Split("-")[0] + $ReleaseName = $NextSemver + $Prerelease = 0 + } + else { + $MsiVersion = $NextAutoSemver.Split("-")[0] + $NextSemver = $NextAutoSemver.Replace("-0","-n") + $ReleaseName = $NextSemver + " [Nightly Build]" + $Prerelease = 1 + } + echo "MSI version: $MsiVersion" + echo "Semver created: $NextSemver" + echo "Prerelease: $Prerelease" + echo "Release name: $ReleaseName" + echo "MsiVersion=$MsiVersion" >> $env:GITHUB_ENV + echo "NextSemVer=$NextSemVer" >> $env:GITHUB_ENV + echo "Prerelease=$Prerelease" >> $env:GITHUB_ENV + echo "ReleaseName=$ReleaseName" >> $env:GITHUB_ENV + + - name: Build project + if: env.ReleaseType != 'No' + shell: powershell + run: | + echo "### Get MDT from Microsoft ###" + wget https://download.microsoft.com/download/3/3/9/339BE62D-B4B8-4956-B58D-73C4685FC492/MicrosoftDeploymentToolkit_x64.msi -UseBasicParsing -OutFile .\MicrosoftDeploymentToolkit_x64.msi + Start-Process .\MicrosoftDeploymentToolkit_x64.msi -ArgumentList "/quiet /norestart" -Wait + + echo "### Copy ServiceUI.exe x64 to 'Sources\Winget-AutoUpdate' folder ###" + Copy-Item -Path "C:\Program Files\Microsoft Deployment Toolkit\Templates\Distribution\Tools\x64\ServiceUI.exe" -Destination ".\Sources\Winget-AutoUpdate\ServiceUI.exe" -Force + Get-Item .\Sources\Winget-AutoUpdate\* + + echo "### Install WiX ###" + dotnet new console + dotnet tool install --global wix --version 5.0.1 + wix extension add WixToolset.UI.wixext/5.0.1 -g + wix extension add WixToolset.Util.wixext/5.0.1 -g + + echo "### Create WAU msi ###" + cd .\Sources\Wix\ + wix build -src build.wxs -ext WixToolset.Util.wixext -ext WixToolset.UI.wixext -out ..\..\WAU.msi -arch x64 -d Version=${{ env.MsiVersion }} -d NextSemVer=${{ env.NextSemVer }} -d Comment="${{ env.ReleaseName }}" -d PreRelease=${{ env.PreRelease }} + cd ..\.. + Get-Item .\WAU.msi + + echo "### Get MSI file SHA ###" + $MsiSHA = (Get-FileHash .\WAU.msi).hash + echo " - WAU.msi SHA256: $MsiSHA" + echo "MSI_SHA=$MsiSHA" >> $env:GITHUB_ENV + + echo "### Zip ADMX ###" + Compress-Archive -Path .\Sources\Policies\ADMX -DestinationPath .\WAU_ADMX.zip -Force + Get-Item .\*.zip + + echo "### Get ADMX zip SHA ###" + $ADMXSHA = (Get-FileHash .\WAU_ADMX.zip).hash + echo " - WAU_ADMX.zip SHA256: $ADMXSHA" + echo "ADMX_SHA=$ADMXSHA" >> $env:GITHUB_ENV + + echo "### Create install counter file ###" + echo "Install counter file." > WAU_InstallCounter + + - name: Create release + uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0 + if: env.ReleaseType != 'No' + with: + tag: v${{ env.NextSemVer }} + prerelease: ${{ github.event.inputs.pre-release || true }} + generateReleaseNotes: true + name: ${{ env.ReleaseName }} + artifacts: "WAU.msi,WAU_ADMX.zip,WAU_InstallCounter" + body: | + |Files|Hash (SHA256)|Downloads| + |---|---|---| + |[WAU.msi](https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v${{ env.NextSemVer }}/WAU.msi) (x64)|${{ env.MSI_SHA }}|![WAU.msi](https://img.shields.io/github/downloads/Romanitho/Winget-AutoUpdate/v${{ env.NextSemVer }}/WAU.msi?style=flat-square&label=&color=blue)| + |[WAU_ADMX.zip](https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v${{ env.NextSemVer }}/WAU_ADMX.zip)|${{ env.ADMX_SHA }}|![WAU_ADMX.zip](https://img.shields.io/github/downloads/Romanitho/Winget-AutoUpdate/v${{ env.NextSemVer }}/WAU_ADMX.zip?style=flat-square&label=&color=blue)| + + ![Install counter](https://img.shields.io/github/downloads/Romanitho/Winget-AutoUpdate/v${{ env.NextSemVer }}/WAU_InstallCounter?style=flat-square&label=Total%20reported%20installations%20for%20this%20release&color=blue) diff --git a/Sources/WAU Configurator.bat b/Sources/WAU Configurator.bat deleted file mode 100644 index bab45742..00000000 --- a/Sources/WAU Configurator.bat +++ /dev/null @@ -1,811 +0,0 @@ -@@:: This prolog allows a PowerShell script to be embedded in a .CMD file. -@@:: Any non-PowerShell content must be preceeded by "@@" -@@setlocal -@@set POWERSHELL_BAT_ARGS=%* -@@if defined POWERSHELL_BAT_ARGS set POWERSHELL_BAT_ARGS=%POWERSHELL_BAT_ARGS:"=\"% -@@PowerShell -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -Command Invoke-Expression $('$args=@(^&{$args} %POWERSHELL_BAT_ARGS%);'+[String]::Join([char]10,$((Get-Content '%~f0') -notmatch '^^@@'))) & goto :EOF - -<# -.SYNOPSIS -Install and configure Winget-AutoUpdate - -.DESCRIPTION -This script will: - - Install Winget if not present - - Install Winget-AutoUpdate to get apps daily updated - - Install apps with Winget from a custom list file (apps.txt) or directly from popped up default list. -#> - -<# UNBLOCK FILES #> - -Get-ChildItem -R | Unblock-File - - -<# APP INFO #> - -# import Appx module if the powershell version is 7/core -if ( $psversionTable.PSEdition -eq "core" ) { - import-Module -name Appx -UseWIndowsPowershell -WarningAction:SilentlyContinue -} - -$Script:WorkingDir = (Get-Location).Path -$Script:WAUConfiguratorVersion = Get-Content "$WorkingDir\Winget-AutoUpdate\Version.txt" - - -<# FUNCTIONS #> - -. "$WorkingDir\Winget-AutoUpdate\functions\Update-WinGet.ps1" -. "$WorkingDir\Winget-AutoUpdate\functions\Get-WingetCmd.ps1" - -#Function to start or update popup -Function Start-PopUp ($Message) { - - if (!$PopUpWindow) { - - #Create window - $inputXML = @" - - - - - -"@ - - [xml]$XAML = ($inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^ - - - -