-
Notifications
You must be signed in to change notification settings - Fork 176
138 lines (117 loc) · 7.41 KB
/
winget-bucket-update.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# This workflow will automatically submit a PR on winget-pkgs in order to update the package corresponding to the release published.
# This can be run by hand by giving the type of release (which defaults to stable if neither '[beta]' or '[nightly]' are present in the invokation)
# Note: This requires a personal gh token to be setup as a secret named 'FERDIUM_WINGET_PAT'
# TODO: refactor the jobs process in order to do the parsing of the json only in one place.
name: Update Ferdium package on winget
on:
workflow_dispatch:
inputs:
message:
description: 'Channel to update'
required: false
release:
types: [published]
env:
REPO_URL: https://api.github.com/repos/ferdium/ferdium-app/releases
jobs:
manual_winget_update:
runs-on: windows-2022
name: 'Manual winget update: ${{ github.event.inputs.message }}'
if: ${{ github.event_name == 'workflow_dispatch' }}
steps:
- name: 'Install winget'
# cf https://github.com/actions/virtual-environments/issues/910#issuecomment-1009640391
# TODO: update urls to get more updated version
run: |
$ErrorActionPreference = 'Stop'
iwr $(iwr 'https://store.rg-adguard.net/api/GetFiles' -Method 'POST' -ContentType 'application/x-www-form-urlencoded' -Body 'type=PackageFamilyName&url=Microsoft.VCLibs.140.00_8wekyb3d8bbwe&ring=RP&lang=en-US' -UseBasicParsing | Foreach-Object Links | Where-Object outerHTML -match 'Microsoft.VCLibs.140.00_.+_x64__8wekyb3d8bbwe.appx' | Foreach-Object href) -OutFile $env:TEMP\vclibs.appx
iwr $(iwr 'https://store.rg-adguard.net/api/GetFiles' -Method 'POST' -ContentType 'application/x-www-form-urlencoded' -Body 'type=PackageFamilyName&url=Microsoft.VCLibs.140.00.UWPDesktop_8wekyb3d8bbwe&ring=RP&lang=en-US' -UseBasicParsing | Foreach-Object Links | Where-Object outerHTML -match 'Microsoft.VCLibs.140.00.UWPDesktop_.+_x64__8wekyb3d8bbwe.appx' | Foreach-Object href) -OutFile $env:TEMP\vclibsuwp.appx
iwr 'https://github.com/microsoft/winget-cli/releases/download/v1.1.12653/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle' -OutFile $env:TEMP\winget.msixbundle
iwr 'https://github.com/microsoft/winget-cli/releases/download/v1.1.12653/9c0fe2ce7f8e410eb4a8f417de74517e_License1.xml' -Outfile $env:TEMP\winget.license
Add-AppxProvisionedPackage -Online -PackagePath $env:TEMP\winget.msixbundle -LicensePath $env:TEMP\winget.license -DependencyPackagePath @("$env:TEMP\vclibs.appx", "$env:TEMP\vclibsuwp.appx")
- name: 'Verify winget'
run: |
winget --info
- name: 'Get release tag'
run: |
if ("${{ contains(github.event.inputs.message, '[nightly]') }}" -eq $True) {
$preRel = $True
$tagInc = "nightly"
$package = "Ferdium.Ferdium.Nightly"
}
elseif ("${{ contains(github.event.inputs.message, '[beta]') }}" -eq $True) {
$preRel = $True
$tagInc = "beta"
$package = "Ferdium.Ferdium.Beta"
}
else
{
$preRel = $False
$tagInc = ""
$package = "Ferdium.Ferdium"
}
$release=Invoke-RestMethod -Uri '${{ env.REPO_URL }}'
$lastCorrectTag = $release | Where-Object -Property prerelease -eq $preRel | Where-Object -Property tag_name -match $tagInc | Select -First 1 | Select -ExpandProperty tag_name
$lastVersion = $($lastCorrectTag.Trim('v'))
echo "last_tag=$lastCorrectTag" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
echo "last_version=$lastVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
echo "PACKAGE_NAME=$package" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: 'Verify if version already exist on winget'
run: |
$lastVersion = '${{ env.last_version }}'
$versions = winget show --id '${{ env.PACKAGE_NAME }}' --versions --accept-source-agreements
if ( $versions.Contains('${{ env.last_version }}') ) {
Write-Host "The last version already exists. Nothing to update."
echo "version_exists=true" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
}
- name: 'Publish update'
if: ${{ env.version_exists != 'true' }}
run: |
$release=Invoke-RestMethod -Uri '${{ env.REPO_URL }}'
$assets = $release | Where-Object -Property tag_name -match '${{ env.last_tag }}' | Select -First 1 | Select -ExpandProperty assets
$urlSetup64 = $assets | Where-Object -Property name -CLike '*-win-AutoSetup*-x64.exe' | Select -ExpandProperty browser_download_url
$urlSetup86 = $assets | Where-Object -Property name -CLike '*-win-AutoSetup*-ia32.exe' | Select -ExpandProperty browser_download_url
$urlSetupArm = $assets | Where-Object -Property name -CLike '*-win-AutoSetup*-arm64.exe' | Select -ExpandProperty browser_download_url
$installerUrls = "'$urlSetup64|x64' '$urlSetup86|x86' '$urlSetupArm|arm64'"
Write-Host "urls to use: $installerUrls"
$package = '${{ env.PACKAGE_NAME }}'
$ghToken = '${{ secrets.FERDIUM_WINGET_PAT }}'
iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
$command = ".\wingetcreate.exe update $package -v '${{ env.last_version }}' -u $installerUrls -t $ghToken -o .\ -s"
Write-Host $command
Invoke-Expression $command
winget_release:
name: 'Update winget after publish: ${{ github.event.inputs.message }}'
if: ${{ github.event_name == 'release' }}
runs-on: windows-2022
steps:
- name: Check release type
run: |
PRERELEASE_VERSION="${{ github.event.release.prerelease }}"
if [ $PRERELEASE_VERSION == "true" ] && ${{ contains(github.event.release.tag_name, 'nightly') }}; then
# use the nightly version
PACKAGE_NAME="Ferdium.Ferdium.Nightly"
elif [ $PRERELEASE_VERSION == "true" ] && ${{ contains(github.event.release.tag_name, 'beta') }} ; then
PACKAGE_NAME="Ferdium.Ferdium.Beta"
else
PACKAGE_NAME="Ferdium.Ferdium"
fi
echo "Using package $PACKAGE_NAME with pre-release $PRERELEASE_VERSION"
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
shell: bash
- name: Send update to winget
run: |
iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
$ghobject = Get-Content '${{ github.event_path }}' | ConvertFrom-Json
$assets = $ghobject.release.assets
$urlSetup64 = $assets | Where-Object -Property name -CLike '*-win-AutoSetup*-x64.exe' | Select -ExpandProperty browser_download_url
$urlSetup86 = $assets | Where-Object -Property name -CLike '*-win-AutoSetup*-ia32.exe' | Select -ExpandProperty browser_download_url
$urlSetupArm = $assets | Where-Object -Property name -CLike '*-win-AutoSetup*-arm64.exe' | Select -ExpandProperty browser_download_url
$installerUrls = "'$urlSetup64|x64' '$urlSetup86|x86' '$urlSetupArm|arm64'"
Write-Host "urls to use: $installerUrls"
$version = $ghobject.release.tag_name
$package = '${{ env.PACKAGE_NAME }}'
$ghToken = '${{ secrets.FERDIUM_WINGET_PAT }}'
$command = ".\wingetcreate.exe update $package -v $($version.Trim('v')) -u $installerUrls -t $ghToken -o .\ -s"
Write-Host $command
Invoke-Expression $command