Skip to content

Commit

Permalink
Merge pull request #414 from LerianStudio/feat/publish_choco_win
Browse files Browse the repository at this point in the history
feat: publish cli midaz in the choco
  • Loading branch information
maxwelbm authored Dec 20, 2024
2 parents aab8bc5 + c492236 commit 91ff413
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 10 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/packages-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,86 @@ jobs:
with:
token: ${{ secrets.RELEASE_GITHUB_TOKEN }}
formula: mdz

choco_release:
if: github.ref == 'refs/heads/main'
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.LERIAN_STUDIO_MIDAZ_PUSH_BOT_APP_ID }}
private-key: ${{ secrets.LERIAN_STUDIO_MIDAZ_PUSH_BOT_PRIVATE_KEY }}

- name: Fetch Latest Tag
id: latest_tag
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
$RawRelease = gh release list --repo $env:GITHUB_REPOSITORY --limit 1 --json tagName --jq '.[0].tagName'
$FormattedRelease = $RawRelease -replace '^v', ''
Write-Host "Formatted release: $FormattedRelease"
echo "tag=$FormattedRelease" >> $env:GITHUB_ENV
shell: pwsh

- name: Set up Chocolatey
run: |
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
shell: pwsh

- name: Update nuspec version
run: |
$nuspecPath = Resolve-Path .\chocolatey\mdz.nuspec
if (-Not (Test-Path $nuspecPath)) {
Write-Error "The nuspec file was not found at $nuspecPath"
exit 1
}

$version = '${{ env.tag }}'
Write-Host "Updating nuspec version to $version"
(Get-Content $nuspecPath) -replace '<version>.*</version>', "<version>$version</version>" | Set-Content $nuspecPath
shell: pwsh

- name: Download and extract ZIP
run: |
$toolsDir = "$(Resolve-Path .\chocolatey\tools)"
New-Item -ItemType Directory -Force -Path $toolsDir | Out-Null
$zipFile = Join-Path $toolsDir 'mdz.zip'
$outputFile = Join-Path $toolsDir 'mdz.exe'
$url = 'https://github.com/LerianStudio/midaz/releases/download/v${{ env.version }}/mdz_{{ env.version }}_windows_amd64.zip'
# Download the ZIP file
Write-Host "Downloading ZIP from $url to $zipFile"
Invoke-WebRequest -Uri $url -OutFile $zipFile
# Extract the ZIP file
Write-Host "Extracting $zipFile to $toolsDir"
Expand-Archive -Path $zipFile -DestinationPath $toolsDir -Force
shell: pwsh

- name: Calculate checksum
id: calculate-checksum
run: |
$outputFile = "$(Resolve-Path .\chocolatey\tools\mdz.exe)"
$checksum = (Get-FileHash -Path $outputFile -Algorithm SHA256).Hash
echo "::set-output name=checksum::$checksum"
shell: pwsh

- name: Replace checksum in chocolateyinstall.ps1
run: |
(Get-Content .\chocolatey\tools\chocolateyinstall.ps1) -replace '{{CHECKSUM}}', '${{ steps.calculate-checksum.outputs.checksum }}' | Set-Content .\chocolatey\tools\chocolateyinstall.ps1
shell: pwsh

- name: Publish Chocolatey package
env:
CHOCO_API_KEY: ${{ secrets.CHOCO_TOKEN }}
run: |
choco pack chocolatey/mdz.nuspec
choco push mdz.${{ env.version }}.nupkg --source https://push.chocolatey.org/ --api-key $env:CHOCO_API_KEY
shell: pwsh
7 changes: 1 addition & 6 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ builds:
- -X github.com/LerianStudio/midaz/components/mdz/pkg/environment.Version={{.Version}}

archives:
- id: "mdz"
builds:
- "mdz"
format: tar.gz
name_template: "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
wrap_in_directory: true
- format: zip

nfpms:
- id: packages
Expand Down
22 changes: 22 additions & 0 deletions chocolatey/mdz.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>mdz</id>
<version>2.0.0</version>
<title>mdz</title>
<authors>Lerian Studio</authors>
<projectUrl>https://github.com/LerianStudio/midaz</projectUrl>
<licenseUrl>https://github.com/LerianStudio/midaz/blob/main/LICENSE<licenseUrl/>
<iconUrl>https://avatars.githubusercontent.com/u/148895005?s=200&v=4</iconUrl>
<tags>mdz cli ledger golang financial</tags>
<summary>An open-source ledger for multi-asset, multi-currency financial systems.</summary>
<description>
Midaz is part of Lerian's Core Banking Platform, offering an immutable ledger to modernize financial operations.
Currently under development and not production-ready.
This package provides a CLI tool to manage APIs and services from the ledger.
</description>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
40 changes: 40 additions & 0 deletions chocolatey/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
$ErrorActionPreference = 'Stop';

$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$binDir = Join-Path $env:ChocolateyInstall 'bin'
$outputFile = Join-Path $toolsDir 'mdz.exe'

# URL do arquivo zipado
$url = 'https://github.com/maxwelbm/mdz/releases/download/v0.5.7/mdz_0.5.7_windows_amd64.zip'
$checksum = '{{CHECKSUM}}'
$silentArgs = ''

# Argumentos do pacote
$packageArgs = @{
packageName = 'mdz'
unzipLocation = $toolsDir
url = $url
softwareName = 'mdz*'
checksum = $checksum
checksumType = 'sha256'
}

# Instalar e descompactar o pacote
Install-ChocolateyZipPackage @packageArgs

# Verificar se o arquivo .exe foi extraído corretamente
if (-Not (Test-Path $outputFile)) {
throw "O arquivo mdz.exe não foi encontrado após a extração do zip."
}

# Certificar-se de que o diretório global 'bin' existe
if (-Not (Test-Path $binDir)) {
New-Item -ItemType Directory -Path $binDir | Out-Null
}

# Mover o executável para o diretório global
Write-Host "Copiando $outputFile para $binDir"
Copy-Item -Path $outputFile -Destination $binDir -Force

# Confirmar a instalação
Write-Host "Instalação completa. O executável mdz está disponível globalmente."
36 changes: 36 additions & 0 deletions chocolatey/tools/chocolateyuninstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
$ErrorActionPreference = 'Stop'; # Stop on all errors

# Define the paths
$binDir = Join-Path $env:ChocolateyInstall 'bin'
$mdzExecutable = Join-Path $binDir 'mdz.exe'

# Uninstallation process
Write-Host "Attempting to remove Mdz executable from $binDir..."

if (Test-Path $mdzExecutable) {
try {
Remove-Item -Path $mdzExecutable -Force
Write-Host "Successfully removed Mdz executable from $binDir."
} catch {
Write-Warning "Failed to remove Mdz executable from $binDir. Error: $_"
}
} else {
Write-Warning "Mdz executable not found in $binDir. Nothing to remove."
}

# Clean up additional files in the tools directory
$toolsDir = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)"
Write-Host "Cleaning up tools directory: $toolsDir"

if (Test-Path $toolsDir) {
try {
Remove-Item -Path $toolsDir -Recurse -Force
Write-Host "Successfully cleaned up tools directory."
} catch {
Write-Warning "Failed to clean up tools directory. Error: $_"
}
} else {
Write-Warning "Tools directory not found. Nothing to clean up."
}

Write-Host "Uninstallation complete."
2 changes: 1 addition & 1 deletion components/audit/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ENV_NAME=production

# APP
VERSION=v1.36.0
VERSION=v1.37.0
SERVER_PORT=3005
SERVER_ADDRESS=:${SERVER_PORT}

Expand Down
2 changes: 1 addition & 1 deletion components/ledger/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ENV_NAME=production

# APP
VERSION=v1.36.0
VERSION=v1.37.0
SERVER_PORT=3000
SERVER_ADDRESS=:${SERVER_PORT}

Expand Down
2 changes: 1 addition & 1 deletion components/mdz/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ CLIENT_ID=9670e0ca55a29a466d31
CLIENT_SECRET=dd03f916cacf4a98c6a413d9c38ba102dce436a9
URL_API_AUTH=http://127.0.0.1:8080
URL_API_LEDGER=http://127.0.0.1:3000
VERSION=v1.36.0
VERSION=v1.37.0
2 changes: 1 addition & 1 deletion components/transaction/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ENV_NAME=production

# APP
VERSION=v1.36.0
VERSION=v1.37.0
APP_CONTEXT=/transaction/v1
SERVER_PORT=3002
SERVER_ADDRESS=:${SERVER_PORT}
Expand Down

0 comments on commit 91ff413

Please sign in to comment.