diff --git a/.github/workflows/cd_chocolatey.yaml b/.github/workflows/cd_chocolatey.yaml new file mode 100644 index 0000000..8da6f30 --- /dev/null +++ b/.github/workflows/cd_chocolatey.yaml @@ -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/ diff --git a/.github/workflows/cd_github.yaml b/.github/workflows/cd_github.yaml index 34e1678..7f2709d 100644 --- a/.github/workflows/cd_github.yaml +++ b/.github/workflows/cd_github.yaml @@ -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 @@ -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 diff --git a/.github/workflows/cd_winget.yaml b/.github/workflows/cd_winget.yaml new file mode 100644 index 0000000..3225fce --- /dev/null +++ b/.github/workflows/cd_winget.yaml @@ -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 }} diff --git a/README.md b/README.md index 25fa408..8f546e1 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,7 @@ solaris_amd64 windows_386 windows_amd64 windows_arm +windows_arm64 ``` After choosing a platform `PLAT` from above, run: diff --git a/chocolatey-packages/ipinfo/ipinfo.nuspec b/chocolatey-packages/ipinfo/ipinfo.nuspec new file mode 100644 index 0000000..2fe3d1d --- /dev/null +++ b/chocolatey-packages/ipinfo/ipinfo.nuspec @@ -0,0 +1,29 @@ + + + + ipinfo + 1.0.0 + ipinfo + ipinfo + IPInfo + https://github.com/ipinfo/cli + https://github.com/ipinfo/cli/tree/master/chocolatey-packages/ipinfo + + false + ipinfo cli + Official Command Line Interface for the IPinfo API (IP geolocation and other types of IP data). + + + + + + diff --git a/chocolatey-packages/ipinfo/tools/chocolateyinstall.ps1 b/chocolatey-packages/ipinfo/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000..dfb1bd5 --- /dev/null +++ b/chocolatey-packages/ipinfo/tools/chocolateyinstall.ps1 @@ -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" diff --git a/chocolatey-packages/ipinfo/update.ps1 b/chocolatey-packages/ipinfo/update.ps1 new file mode 100644 index 0000000..f8dccd8 --- /dev/null +++ b/chocolatey-packages/ipinfo/update.ps1 @@ -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 diff --git a/scripts/build-all-platforms.sh b/scripts/build-all-platforms.sh index de4ce3a..e33ac1a 100755 --- a/scripts/build-all-platforms.sh +++ b/scripts/build-all-platforms.sh @@ -50,7 +50,8 @@ for t in \ solaris_amd64 \ windows_386 \ windows_amd64 \ - windows_arm ; + windows_arm \ + windows_arm64 ; do os="${t%_*}" arch="${t#*_}"