Skip to content

Updating VCTools pathing, much simpler #139

Updating VCTools pathing, much simpler

Updating VCTools pathing, much simpler #139

Workflow file for this run

name: Chef-PowerShell Builder
# on: [push]
# working dir : D:\a\chef-powershell-shim\chef-powershell-shim
on:
pull_request:
branches:
- main
types: [closed]
jobs:
Build-And-Push-Chef-PowerShell-Gem:
if: github.event.pull_request.merged == true
runs-on: windows-latest
steps:
- name: Check out repo
uses: actions/checkout@v2
- name: Install Habitat
run: choco install habitat -y
shell: powershell
- name: Install Chef Client
run: choco install chef-client -y
shell: powershell
- name: Update the Gem version
run: |
$project_root = $pwd
$update_type = $null
try {
$file = (Get-Content $("$project_root\chef-powershell\lib\chef-powershell\version.rb"))
}
catch {
Write-Error "Failed to Get the Version from version.rb"
}
[version]$Version = [regex]::matches($file, "\s*VERSION\s=\s\`"(\d*.\d*.\d*)\`"\s*").groups[1].value
$update_type = [System.Environment]::GetEnvironmentVariable("CHEF_POWERSHELL_VERSION_UPDATE", "Machine")
# Add one to the build of the version number
if ($update_type -eq "Major") {
[version]$NewVersion = "{0}.{1}.{2}" -f ($Version.Major + 1), $Version.Minor, $Version.Build
}
elseif ($update_type -eq "Minor") {
[version]$NewVersion = "{0}.{1}.{2}" -f $Version.Major, ($Version.Minor + 1), $Version.Build
}
elseif (([string]::IsNullOrEmpty($update_type)) -or ($update_type -eq "Version")) {
[version]$NewVersion = "{0}.{1}.{2}" -f $Version.Major, $Version.Minor, ($Version.Build + 1)
}
else {
Write-Error "failed to update the version string"
}
# Replace Old Version Number with New Version number in the file
try {
(Get-Content .\chef-powershell\lib\chef-powershell\version.rb) -replace $version, $NewVersion | Out-File .\chef-powershell\lib\chef-powershell\version.rb -Encoding utf8
Write-Output "Updated Module Version from $Version to $NewVersion"
}
catch {
$_
Write-Error "failed to set file"
}
shell: powershell
- name: Setup Habitat Environment
env:
HAB_ORIGIN: ci
HAB_LICENSE: accept-no-persist
FORCE_FFI_YAJL: ext
run: |
if (Test-Path -PathType leaf "/hab/cache/keys/ci-*.sig.key") {
Write-Output "--- Using existing fake '$env:HAB_ORIGIN' origin key"
}
else {
Write-Output "--- Generating fake '$env:HAB_ORIGIN' origin key"
hab origin key generate $env:HAB_ORIGIN
}
shell: powershell
- name: Building 64-bit PowerShell DLL's
env:
HAB_ORIGIN: ci
HAB_LICENSE: accept-no-persist
FORCE_FFI_YAJL: ext
run: hab pkg build Habitat
shell: powershell
- name: Installing the 64-bit DLL's
env:
HAB_ORIGIN: ci
HAB_LICENSE: accept-no-persist
FORCE_FFI_YAJL: ext
run: |
$project_root = $pwd
. results/last_build.ps1
hab pkg install results/$pkg_artifact
$x64 = hab pkg path ci/chef-powershell-shim
$x64_bin_path = $("$project_root/chef-powershell/bin/ruby_bin_folder/AMD64")
if (Test-Path -PathType Container $x64_bin_path) {
Get-ChildItem -Path $x64_bin_path -Recurse | Foreach-object { Remove-item -Recurse -path $_.FullName -Force }
Copy-Item "$x64\bin\*" -Destination $x64_bin_path -Force -Recurse
}
else {
New-Item -Path $x64_bin_path -ItemType Directory -Force
Copy-Item "$x64\bin\*" -Destination $x64_bin_path -Force -Recurse
}
shell: powershell
- name: Building the Gem
run: |
$project_name = "chef-powershell"
$project_root = $pwd
Set-Location "$project_root\chef-powershell"
gem build $("$project_name.gemspec")
shell: powershell
- name: Pushing the gem to RubyGems.org
env:
GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
run: |
$project_name = "chef-powershell"
$project_root = $pwd
Set-Location "$project_root\chef-powershell"
$api_key = $env:GEM_HOST_API_KEY
$content = ":rubygems_api_key: $api_key"
if(-not(Test-Path -path ~/.gem)){
New-Item -Path ~/ -Name .gem -ItemType Directory
}
if(-not(Test-Path -path ~/.gem/credentials)){
New-Item -Path ~/.gem/credentials -ItemType File -Value $content
}
try {
$file = (Get-Content $("$project_root\chef-powershell\lib\chef-powershell\version.rb"))
}
catch {
Write-Error "Failed to Get the Version from version.rb"
}
[string]$Version = [regex]::matches($file, "\s*VERSION\s=\s\`"(\d*.\d*.\d*)\`"\s*").groups[1].value
$gemfIle = $([string]$project_root + "\" + [string]$project_name + "\" + [string]$project_name + "-" + [string]$Version + ".gem" )
gem push $($gemfIle)
shell: powershell