Skip to content

Commit

Permalink
Getting builds working.
Browse files Browse the repository at this point in the history
  • Loading branch information
splatteredbits committed Jan 29, 2021
1 parent e36622f commit 630dd49
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 16 deletions.
2 changes: 0 additions & 2 deletions Tests/.password

This file was deleted.

39 changes: 39 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: 0.0.{build}

skip_tags: true

skip_branch_with_pr: true

image:
- Visual Studio 2015
- Visual Studio 2017
- Visual Studio 2019
- Ubuntu
- macOS

build:
verbosity: minimal

build_script:
- pwsh: .\build.ps1 -Verbose

for:
- matrix:
only:
- image: Visual Studio 2015
- image: Visual Studio 2017
build_script:
- ps: .\build.ps1 -Verbose
- pwsh: .\build.ps1 -Verbose

- matrix:
only:
- image: Ubuntu
environment:
LANG: us_US.UTF-8

- matrix:
only:
- image: Visual Studio 2019
environment:
PUBLISH: True
15 changes: 15 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,19 @@ if( $Initialize )
}

$context = New-WhiskeyContext -Environment 'Dev' -ConfigurationPath $configPath
$apiKeys = @{
'AppVeyorBearerToken' = 'WHS_APPVEYOR_BEARER_TOKEN';
'GitHubAccessToken' = 'WHS_GITHUB_ACCESS_TOKEN';
'PowerShellGalleryApiKey' = 'WHS_POWERSHELL_GALLERY_API_KEY';
}
foreach( $apiKeyName in $apiKeys.Keys )
{
$envVarName = $apiKeys[$apiKeyName]
$path = "env:$($envVarName)"
if( -not (Test-Path -Path $path) )
{
continue
}
Add-WhiskeyApiKey -Context $context -ID $apiKeyName -Value (Get-Item -Path $path).Value
}
Invoke-WhiskeyBuild -Context $context @optionalArgs
26 changes: 14 additions & 12 deletions init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ param(
#Requires -RunAsAdministrator
Set-StrictMode -Version 'Latest'

Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'PSModules\Carbon' -Resolve)

if( -not (Test-Path -Path 'variable:IsWindows') )Carbon.Core
{
$IsWindows = $true
$IsLinux = $false
$IsMacOS = $false
& {
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'PSModules\Carbon' -Resolve) -Verbose:$false
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'Carbon.Core' -Resolve) -Verbose:$false
}

$passwordPath = Join-Path -Path $PSScriptRoot -ChildPath 'Tests\.password'
Expand All @@ -21,18 +17,24 @@ if( -not (Test-Path -Path $passwordPath) )
$randomBytes = [byte[]]::New(9)
do
{
Write-Verbose -Message ('Generating random password for test accounts.')
$rng.GetBytes($randomBytes);
$password = [Convert]::ToBase64String($randomBytes)
}
# Password needs to contain uppercase letter, lowercase letter, and a number.
while( $password -cnotmatch '[A-Z]' -and $password -cnotmatch '[a-z]' -and $password -notmatch '\d' )
$password | Set-Content -Path $passwordPath

Write-Verbose -Message ('Generating IV for encrypting test account password on Linux.')
$randomBytes = [byte[]]::New(6)
$rng.GetBytes($randomBytes)
$salt = [Convert]::ToBase64String($randomBytes)
$salt | Add-Content -Path $passwordPath
}
else
{
Get-Content -Path $passwordPath -Raw | Write-Verbose
}

$password,$salt = Get-Content -Path $passwordPath -TotalCount 2
$users =
Expand All @@ -45,7 +47,7 @@ $users =

foreach( $user in $users )
{
if( $IsWindows )
if( (Test-COperatingSystem -IsWindows) )
{
$maxLength = $user.Description.Length
if( $maxLength -gt 48 )
Expand All @@ -56,19 +58,19 @@ foreach( $user in $users )
$credential = [pscredential]::New($user.Name, (ConvertTo-SecureString $password -AsPlainText -Force))
Install-CUser -Credential $credential -Description $description -UserCannotChangePassword
}
elseif( $IsMacOS )
elseif( (Test-COperatingSystem -IsMacOS) )
{
$newUid =
sudo dscl . -list /Users UniqueID |
ForEach-Object { $username,$uid = $_ -split ' +' ; return [int]$uid } |
Sort-Object |
Select-Object -Last 1
Write-Verbose " Found highest user ID ""$($newUid)""." -Verbose
Write-Verbose " Found highest user ID ""$($newUid)""."
$newUid += 1

$username = $user.Name

Write-Verbose " Creating $($username) (uid: $($newUid))" -Verbose
Write-Verbose " Creating $($username) (uid: $($newUid))"
# Create the user account
sudo dscl . -create /Users/$username
sudo dscl . -create /Users/$username UserShell /bin/bash
Expand All @@ -79,7 +81,7 @@ foreach( $user in $users )
sudo dscl . -passwd /Users/$username $password
sudo createhomedir -c
}
elseif( $IsLinux )
elseif( (Test-COperatingSystem -IsLinux) )
{
$userExists = Get-Content '/etc/passwd' | Where-Object { $_ -match "^$([regex]::Escape($user.Name))\b"}
if( $userExists )
Expand Down
14 changes: 12 additions & 2 deletions whiskey.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Build:
# works.
- MergeFile:
OnlyBy: BuildServer
IfExists: Carbon.Core\Functions\*.ps1
Path:
- Carbon.Core\Functions\*.ps1
DestinationPath: Carbon.Core\Carbon.Core.psm1
Expand All @@ -34,18 +35,26 @@ Build:
Path: reset.ps1
- Pester4:
Script: Tests\*.Tests.ps1
- Delete:
Path: .output\*.zip
- Zip:
ArchivePath: .output\Carbon.Core.zip
Path:
- Carbon.Core

Publish:
- AppVeyorWaitForBuildJobs:
IfExists: env:PUBLISH
UnlessExists: env:APPVEYOR_PULL_REQUEST_NUMBER
ApiKeyID: AppVeyorBearerToken

- PublishPowerShellModule:
IfExists: env:PUBLISH
UnlessExists: env:APPVEYOR_PULL_REQUEST_NUMBER
RepositoryName: PSGallery
RepositoryUri: https://powershellgallery.com/api/v2/
Path: Carbon.Core
ApiKeyID: PowerShellGallery
ApiKeyID: PowerShellGalleryApiKey

- SetVariableFromPowerShellDataFile:
Path: Carbon.Core\Carbon.Core.psd1
Expand All @@ -55,9 +64,10 @@ Publish:
ReleaseNotes: RELEASE_NOTES

- GitHubRelease:
IfExists: env:PUBLISH
UnlessExists: env:APPVEYOR_PULL_REQUEST_NUMBER
RepositoryName: webmd-health-services/Carbon.Core
ApiKeyID: github.com
ApiKeyID: GitHubAccessToken
Tag: $(WHISKEY_SEMVER2_NO_BUILD_METADATA)
Commitish: $(WHISKEY_SCM_COMMIT_ID)
Name: $(WHISKEY_SEMVER2_NO_BUILD_METADATA)
Expand Down

0 comments on commit 630dd49

Please sign in to comment.