forked from vedantmgoyal9/winget-releaser
-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
116 lines (114 loc) · 5.5 KB
/
action.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
name: WinGet Releaser
description: Publish new releases of your application to Windows Package Manager easily.
author: vedantmgoyal9 (Vedant)
inputs:
identifier:
required: true
description: The PackageIdentifier of the package (case-sensitive).
version:
required: false
description: The PackageVersion of the package you want to release.
installers-regex:
required: true
description: The regex to match the installers.
default: '.(exe|msi|msix|appx)(bundle){0,1}$'
max-versions-to-keep:
required: true
description: 'The maximum number of versions to keep in WinGet Community Repository (Default: 0 - no limit)'
default: '0'
release-repository:
required: true
description: The repository where the release is present (should be present under same user/organization).
default: ${{ github.event.repository.name }}
release-tag:
required: true
description: The release tag to be used for creating manifests.
default: ${{ github.event.release.tag_name || github.ref_name }}
token:
required: true
description: GitHub token to create pull request on Windows Package Manager Community Repository.
fork-user:
required: true
description: GitHub username where the fork of winget-pkgs is present.
default: ${{ github.repository_owner }}
runs:
using: composite
steps:
- run: |
# check if at least one version of the package is already present in winget-pkgs repository
$ErrorActionPreference = 'SilentlyContinue'
$PkgId = '${{ inputs.identifier }}'
Invoke-WebRequest -Uri "https://github.com/microsoft/winget-pkgs/tree/master/manifests/$($PkgId.ToLower()[0])\$($PkgId.Replace('.', '/'))" -Method Head
if (-not $?) {
Write-Output "::error::Package $PkgId does not exist in the winget-pkgs repository. Please add atleast one version of the package before using this action."
exit 1
}
shell: pwsh
- run: |
# check if max-versions-to-keep is a valid number and is 0 (keep all versions) or greater than 0
$MaxVersionsToKeep = '${{ inputs.max-versions-to-keep }}'
if (-not [int]::TryParse($MaxVersionsToKeep, [ref]$null) -or $MaxVersionsToKeep -lt 0) {
Write-Output "::error::Invalid input: max-versions-to-keep should be 0 (zero - keep all versions) or a POSITIVE INTEGER."
exit 1
}
shell: pwsh
- uses: cargo-bins/cargo-binstall@main
env:
GITHUB_TOKEN: ${{ github.token }}
- run: cargo binstall komac -y
env:
GITHUB_TOKEN: ${{ github.token }}
shell: pwsh
- run: |
# get release information
$ReleaseInfo = Invoke-RestMethod `
-Uri 'https://api.github.com/repos/${{ github.repository_owner }}/${{ inputs.release-repository }}/releases/tags/${{ inputs.release-tag }}' `
-Headers @{ Authorization = "token $env:GITHUB_TOKEN" }
If ('' -eq '${{ inputs.version }}') {
Write-Output "version=$($ReleaseInfo.tag_name -replace '^v')" >> $env:GITHUB_OUTPUT
} Else {
Write-Output "version=${{ inputs.version }}" >> $env:GITHUB_OUTPUT
}
Write-Output "urls=$($ReleaseInfo.assets.Where({ $_.name -match '${{ inputs.installers-regex }}' }).browser_download_url -join ' ')" >> $env:GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ github.token }}
id: version-and-urls
shell: pwsh
- run: komac update '${{ inputs.identifier }}' --version '${{ steps.version-and-urls.outputs.version }}' --submit --urls ${{ steps.version-and-urls.outputs.urls }}
env:
KOMAC_FORK_OWNER: ${{ inputs.fork-user }}
KOMAC_CREATED_WITH: WinGet Releaser
KOMAC_CREATED_WITH_URL: ${{ github.server_url }}/${{ github.action_repository }}
GITHUB_TOKEN: ${{ inputs.token }}
shell: pwsh
- run: 'komac cleanup --only-merged # clean up stale branches (for which PRs have been merged)'
env:
KOMAC_FORK_OWNER: ${{ inputs.fork-user }}
GITHUB_TOKEN: ${{ inputs.token }}
shell: pwsh
- if: fromJSON(inputs.max-versions-to-keep) > 0 # https://docs.github.com/en/actions/learn-github-actions/expressions
run: |
# delete previous versions w.r.t. max-versions-to-keep (if any)
$ToNatural = { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) }
#[Issue #307] -NoEnumerate has been added so that $Versions does not get converted to a string, when only one version exists in winget-pkgs
$Versions = komac list-versions '${{ inputs.identifier }}' --json | ConvertFrom-Json -NoEnumerate | Sort-Object $ToNatural -Descending
$Reason = 'This version is older than what has been set in `max-versions-to-keep` by the publisher.'
If ($Versions.Count + 1 -gt ${{ inputs.max-versions-to-keep }}) {
$VersionsToDelete = $Versions[(${{ inputs.max-versions-to-keep }} - 1)..($Versions.Count - 1)]
Write-Output "Versions to delete: $($VersionsToDelete -join ', ')"
ForEach ($Version in $VersionsToDelete) {
Write-Output "Deleting version: $Version"
komac remove '${{ inputs.identifier }}' --version $Version --reason "$Reason" --submit
}
} Else {
Write-Output "No versions to delete. All good :)"
}
env:
KOMAC_FORK_OWNER: ${{ inputs.fork-user }}
KOMAC_CREATED_WITH: WinGet Releaser
KOMAC_CREATED_WITH_URL: ${{ github.server_url }}/${{ github.action_repository }}
GITHUB_TOKEN: ${{ inputs.token }}
shell: pwsh
branding:
color: blue
icon: package