Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Rework chocolatey deployment script #103

Merged
merged 1 commit into from
May 24, 2023
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
35 changes: 9 additions & 26 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ jobs:
chocolatey:
runs-on: windows-latest
needs: build
defaults:
run:
shell: pwsh
working-directory: working-directory: ${{ github.workspace }}/setup/choco
env:
CHOCOLATEY_API_KEY: ${{ secrets.CHOCOLATEY_API_KEY }}

steps:
- name: Checkout
Expand All @@ -158,32 +164,9 @@ jobs:
with:
tagRegex: (?<version>\d.\d.\d)(?:-)(?<beta>.*) # Optional. Returns specified group text as tag name. Full tag string is returned if regex is not defined.

- name: 'Replace tokens Chocolatey files #1'
uses: datamonsters/replace-action@v2
with:
files: './src/Chocolatey-Packages/cosmosdbexplorer/tools/chocolateyinstall.ps1'
replacements: '$version=${{ steps.tag.outputs.version }},$tag-name=$GIT_TAG_NAME'

- name: 'Replace tokens Chocolatey files #2'
uses: datamonsters/replace-action@v2
with:
files: './src/Chocolatey-Packages/cosmosdbexplorer/cosmosdbexplorer.nuspec'
replacements: '$version=${{ steps.tag.outputs.version }},$tag-name=$GIT_TAG_NAME'

- name: Pack Chocolatey
uses: crazy-max/ghaction-chocolatey@v1
with:
args: pack ./src/Chocolatey-Packages/cosmosdbexplorer/cosmosdbexplorer.nuspec --out ./src/Chocolatey-Packages/cosmosdbexplorer/

- name: Upload chocolatey artifacts
uses: actions/upload-artifact@v2
with:
path: ./src/Chocolatey-Packages/cosmosdbexplorer/cosmosdbexplorer.${{ steps.tag.outputs.version }}.0.nupkg

- name: Push Chocolatey
uses: crazy-max/ghaction-chocolatey@v1
with:
args: push ./src/Chocolatey-Packages/cosmosdbexplorer/cosmosdbexplorer.${{ steps.tag.outputs.version }}.0.nupkg --source https://push.chocolatey.org/ --api-key=$CHOCOLATEY_API_KEY
- name: Create 📦 and submit to chocolatey
run: |
./build.ps1 -Version "${{ steps.tag.outputs.tag }}" -Token $env:CHOCOLATEY_API_KEY

# Autoupdater
autoupdater:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,4 @@ __pycache__/

**/Output/*

setup/choco/output/*
70 changes: 70 additions & 0 deletions setup/choco/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

Param
(
[parameter(Mandatory = $true)]
[string]
$Version,
[parameter(Mandatory = $false)]
[string]
$Token
)

function Get-HashForArchitecture {
param (
[parameter(Mandatory = $true)]
[string]
$Version
)
$hash = (new-object Net.WebClient).DownloadString("https://github.com/sachabruttin/CosmosDbExplorer/releases/download/v$Version/install.exe.sha256")
return $hash.Trim()
}

function Write-MetaData {
param (
[parameter(Mandatory = $true)]
[string]
$FileName,
[parameter(Mandatory = $true)]
[string]
$Version,
[parameter(Mandatory = $true)]
[string]
$Path,
[parameter(Mandatory = $true)]
[string]
$Hash
)

$outPath = $Path -eq 'templates' ? "./output/$FileName" : "./output/$Path/$FileName"
$filePath = $Path -like 'templates' ? "./templates/$FileName" : "./templates/$Path/$FileName"

$tagName = "v$Version"
$Version -match '(?<version>\d.\d.\d)(?:-)(?<beta>.*)'

$content = Get-Content $filePath -Raw
$content = $content.Replace('$version', $Matches.version)
$content = $content.Replace('$tag-name', $tagName)
$content = $content.Replace('<HASH>', $Hash)
$date = Get-Date -Format "yyyy-MM-dd"
$content = $content.Replace('<DATE>', $date)
$content | Out-File -Encoding 'UTF8' $outPath
}

New-Item -Path $PWD -Name "output/tools" -ItemType "directory"
# Get all files inside the folder and adjust the version/hash
$Hash = Get-HashForArchitecture -Version $Version

Get-ChildItem './templates/*' -Recurse -File | ForEach-Object -Process {
Write-MetaData -FileName $_.Name -Version $Version -Hash $Hash -Path $_.Directory.BaseName
}

if (-not $Token) {
return
}

# package
choco pack "./output/cosmosdbexplorer.nuspec" --out "./output" --allow-unofficial

# push
$nupkg = (Get-ChildItem '*.nupkg' -Recurse -File).FullName
choco push $nupkg --api-key=$Token --allow-unofficial
133 changes: 0 additions & 133 deletions src/Chocolatey-Packages/cosmosdbexplorer/ReadMe.md

This file was deleted.

Loading