Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Release automation - Winget, Chocolatey #205

Merged
merged 11 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/cd_chocolatey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Publish to Chocolatey
on:
release:
types: [released]

jobs:
check-release:
runs-on: ubuntu-latest
outputs:
valid-cli: ${{ steps.cli-name.outputs.valid }}
cli-vsn: ${{ steps.cli-name.outputs.cli-vsn }}

steps:
- name: Confirm that this is the release of ipinfo cli
id: cli-name
run: |
releaseName="${{ github.event.release.name }}"

if [[ $releaseName =~ ^ipinfo-([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "Release name matches pattern 'ipinfo-x.x.x'"
echo "cli-vsn=${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}" >> "$GITHUB_OUTPUT"
echo "valid=true" >> "$GITHUB_OUTPUT"
else
echo "Invalid release name format: $releaseName"
echo "Release name should be of format ipinfo-x.x.x"
fi

publish:
needs: check-release
if: needs.check-release.outputs.valid-cli == true
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install au module
run: |
choco install au -y

- name: Update package version
run: |
cd chocolatey-packages\ipinfo
.\update.ps1

- name: Test installation
run: |
cd chocolatey-packages\ipinfo
Test-Package

- name: Upload to choco
run: |
cd chocolatey-packages\ipinfo
choco apikey --key ${{ secrets.CHOCO_API_KEY }} --source https://push.chocolatey.org/
choco push ipinfo.${{ needs.check-release.outputs.cli-vsn }}.nupkg --source https://push.chocolatey.org/
8 changes: 8 additions & 0 deletions .github/workflows/cd_github.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ jobs:
with:
go-version: '1.20'

- name: Get Github App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.G_APP_ID }}
private-key: ${{ secrets.G_APP_PRIVATE_KEY }}

- name: Extract CLI Name and Version
run: |
# Get the tag name from the event payload
Expand Down Expand Up @@ -54,6 +61,7 @@ jobs:
- name: Release
uses: softprops/action-gh-release@v1
with:
token: ${{ steps.app-token.outputs.token }}
body_path: changes.md
files: |
./build/${{ env.CLI_NAME }}_${{ env.CLI_VERSION }}*.tar.gz
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/cd_winget.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish to WinGet
on:
release:
types: [released]

jobs:
check-release:
runs-on: ubuntu-latest
outputs:
valid-cli: ${{ steps.cli-name.outputs.valid }}
cli-vsn: ${{ steps.cli-name.outputs.cli-vsn }}
steps:
- name: Confirm that this is the release of ipinfo cli
id: cli-name
run: |
releaseName="${{ github.event.release.name }}"

if [[ $releaseName =~ ^ipinfo-([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "Release name matches pattern 'ipinfo-x.x.x'"
echo "cli-vsn=${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}" >> "$GITHUB_OUTPUT"
echo "valid=true" >> "$GITHUB_OUTPUT"
else
echo "Invalid release name format: $releaseName"
echo "Release name should be of format ipinfo-x.x.x"
fi

publish:
needs: check-release
if: needs.check-release.outputs.valid-cli == true
runs-on: windows-latest
steps:
- name: Get Github App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.G_APP_ID }}
private-key: ${{ secrets.G_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}

- uses: vedantmgoyal2009/winget-releaser@v2
with:
identifier: ipinfo.ipinfo
installers-regex: '_windows_\w+\.zip$'
version: ${{ needs.check-release.outputs.cli-vsn }}
token: ${{ steps.app-token.outputs.token }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ solaris_amd64
windows_386
windows_amd64
windows_arm
windows_arm64
```

After choosing a platform `PLAT` from above, run:
Expand Down
29 changes: 29 additions & 0 deletions chocolatey-packages/ipinfo/ipinfo.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>ipinfo</id>
<version>1.0.0</version>
<owners>ipinfo</owners>
<title>ipinfo</title>
<authors>IPInfo</authors>
<projectUrl>https://github.com/ipinfo/cli</projectUrl>
<packageSourceUrl>https://github.com/ipinfo/cli/tree/master/chocolatey-packages/ipinfo</packageSourceUrl>
<!--<iconUrl>https://raw.github.com/jbpaux/chocolatey-packages/tree/master/ipinfo/ipinfo.png</iconUrl>-->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<tags>ipinfo cli</tags>
<summary>Official Command Line Interface for the IPinfo API (IP geolocation and other types of IP data).</summary>
<description><![CDATA[This is the official CLI for the IPinfo.io IP address API, allowing you to:

Look up IP details in bulk or one-by-one.
Look up ASN details.
Summarize the details of up to 1000 IPs at a time.
Open a map of IP locations for any set of IPs.
Filter IPv4/IPv6 addresses from any input.
Print out IP lists for any CIDR or IP range.
And more!
]]></description>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
22 changes: 22 additions & 0 deletions chocolatey-packages/ipinfo/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$ErrorActionPreference = 'Stop';

$packageName = 'ipinfo'
$toolsDir = Split-Path -Parent $MyInvocation.MyCommand.Definition

$packageArgs = @{
packageName = $packageName
url64 = ''
checksum64 = ''
checksumType64 = ''
url = ''
checksumType = ''
checksum = ''
destination = $toolsDir
}

$targetPath = Join-Path -Path $toolsDir -ChildPath "ipinfo.exe"
if (Test-Path $targetPath) {
Remove-Item $targetPath
}
Install-ChocolateyZipPackage @packageArgs
Get-ChildItem -Path $toolsDir -Filter "ipinfo*.exe" | Rename-Item -NewName "ipinfo.exe"
37 changes: 37 additions & 0 deletions chocolatey-packages/ipinfo/update.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import-module au

$repo = 'ipinfo/cli'

function global:au_SearchReplace {
@{
".\tools\chocolateyInstall.ps1" = @{
"(?i)(^\s*url64\s*=\s*)('.*')" = "`$1'$($Latest.URL64)'"
"(?i)(^\s*checksum64\s*=\s*)('.*')" = "`$1'$($Latest.Checksum64)'"
"(?i)(^\s*checksumType64\s*=\s*)('.*')" = "`$1'$($Latest.ChecksumType64)'"
"(?i)(^\s*url\s*=\s*)('.*')" = "`$1'$($Latest.URL32)'"
"(?i)(^\s*checksum\s*=\s*)('.*')" = "`$1'$($Latest.Checksum32)'"
"(?i)(^\s*checksumType\s*=\s*)('.*')" = "`$1'$($Latest.ChecksumType32)'"
}
}
}

function global:au_GetLatest {
$releases = Invoke-RestMethod "https://api.github.com/repos/$repo/releases"
if ($null -ne $releases) {
$release = $releases | Where-Object name -like "ipinfo*" | Sort-Object published_at -Descending | Select-Object -First 1
if ($null -ne $release) {
$url64 = ($release.assets | Where-Object name -like "ipinfo*_windows_amd64.zip").browser_download_url
$url32 = ($release.assets | Where-Object name -like "ipinfo*_windows_386.zip").browser_download_url

$version = $release.name.split('-')[1]

@{
URL64 = $url64
URL32 = $url32
Version = $version
}
}
}
}

update -ChecksumFor all
3 changes: 2 additions & 1 deletion scripts/build-all-platforms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ for t in \
solaris_amd64 \
windows_386 \
windows_amd64 \
windows_arm ;
windows_arm \
windows_arm64 ;
do
os="${t%_*}"
arch="${t#*_}"
Expand Down