-
Notifications
You must be signed in to change notification settings - Fork 5
130 lines (129 loc) · 5.22 KB
/
gem-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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