diff --git a/.github/workflows/habitat-build.yml b/.github/workflows/habitat-build.yml index 4ed24d61..7a05750c 100644 --- a/.github/workflows/habitat-build.yml +++ b/.github/workflows/habitat-build.yml @@ -11,7 +11,7 @@ on: env: # BLDR URL Defined as: 'https://bldr.habitat.sh/' but as an env var in workspace settings. BLDR_URL: ${{vars.BLDR_URL}} - # HAB_ORIGIN Defined as: 'chef-platform' defined in workspace settings. + # HAB_ORIGIN Defined as: 'chef' defined in workspace settings. HAB_ORIGIN: ${{vars.HAB_ORIGIN}} # BLDR_CHANNEL defaulted to unstable, but can be switched to stable, it is defined via the environment setting https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#using-an-environment BLDR_CHANNEL: ${{ vars.BLDR_CHANNEL }} @@ -82,6 +82,16 @@ jobs: hab origin key download --auth $HAB_AUTH_TOKEN --secret $HAB_ORIGIN echo "--- running linux hab build" hab pkg build . + hartfile=$(ls ./results | grep "cookstyle" | tail -n 1) + sudo hab license accept + export CHEF_LICENSE="accept-no-persist" + export HAB_LICENSE="accept-no-persist" + export HAB_NONINTERACTIVE="true" + sudo hab pkg install ./results/$hartfile + . ./results/last_build.env + export pkg_ident + chmod +x habitat/tests/test.sh + habitat/tests/test.sh - name: Install Habitat on Windows if: ${{ matrix.os == 'windows-latest' }} shell: pwsh @@ -100,3 +110,7 @@ jobs: hab origin key download --auth ${{ secrets.HAB_AUTH_TOKEN }} --secret ${{ env.HAB_ORIGIN }} write-output "--- running windows hab build" hab pkg build . + hartfile=$(ls ./results | grep "cookstyle" | tail -n 1) + hab pkg install ./results/$hartfile + . ./results/last_build.env + habitat/tests/test.ps1 diff --git a/.github/workflows/habitat-publish.yml b/.github/workflows/habitat-publish.yml index d87e2463..1b821909 100644 --- a/.github/workflows/habitat-publish.yml +++ b/.github/workflows/habitat-publish.yml @@ -11,7 +11,7 @@ on: env: # BLDR URL Defined as: 'https://bldr.habitat.sh/' but as an env var in workspace settings. BLDR_URL: ${{vars.BLDR_URL}} - # HAB_ORIGIN Defined as: 'chef-platform' defined in workspace settings. + # HAB_ORIGIN Defined as: 'chef' defined in workspace settings. HAB_ORIGIN: ${{vars.HAB_ORIGIN}} # BLDR_CHANNEL defaulted to unstable, but can be switched to stable, it is defined via the environment setting https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#using-an-environment BLDR_CHANNEL: ${{ vars.BLDR_CHANNEL }} @@ -110,4 +110,3 @@ jobs: . results\last_build.ps1 hab pkg upload results\$pkg_artifact --auth ${{ secrets.HAB_AUTH_TOKEN }} write-output "--- push complete!!" - outreach diff --git a/habitat/tests/test.pester.ps1 b/habitat/tests/test.pester.ps1 new file mode 100644 index 00000000..65431ef6 --- /dev/null +++ b/habitat/tests/test.pester.ps1 @@ -0,0 +1,33 @@ +param( + [Parameter()] + [string]$PackageIdentifier = $(throw "Usage: test.ps1 [test_pkg_ident] e.g. test.ps1 ci/user-windows-default/1.0.0/20190812103929") +) + +$PackageVersion = $PackageIdentifier.split('/')[2] + +Describe "cookstyle" { + Context "cookstyle" { + It "is an executable" { + hab pkg exec $PackageIdentifier cookstyle.bat --version + $? | Should be $true + } + + <# + At some point hab's argument parsing changed and it started interpreting the trailing `--version` as being + an argument passed to hab instead of an argument to the command passed to `hab pkg exec`. + + Powershell 5.1 and 7 appear to differ in how they treat following arguments as well, such that these two + versions of the command fail in powershell 5.1 (which is currently what is running in the windows machines + in Buildkite) but pass in powershell 7 (which is currently what is running in a stock Windows 10 VM). + + $the_version = (hab pkg exec $PackageIdentifier cookstyle.bat '--version' | Out-String).split(':')[1].Trim() + $the_version = (hab pkg exec $PackageIdentifier cookstyle.bat --version | Out-String).split(':')[1].Trim() + + This version of the command passes in powershell 5.1 but fails in powershell 7. + #> + It "is the expected version" { + $the_version = (hab pkg exec $PackageIdentifier cookstyle.bat -- --version | Out-String).split(':')[1].Trim() + $the_version | Should be $PackageVersion + } + } +} \ No newline at end of file diff --git a/habitat/tests/test.ps1 b/habitat/tests/test.ps1 new file mode 100644 index 00000000..682fdfbb --- /dev/null +++ b/habitat/tests/test.ps1 @@ -0,0 +1,19 @@ +param ( + [Parameter()] + [string]$PackageIdentifier = $(throw "Usage: test.ps1 [test_pkg_ident] e.g. test.ps1 ci/user-windows/1.0.0/20190812103929") +) + +# ensure Pester is available for test use +if (-Not (Get-Module -ListAvailable -Name Pester)){ + hab pkg install core/pester + Import-Module "$(hab pkg path core/pester)\module\pester.psd1" +} + +Write-Host "--- :fire: Smokish Pestering" +# Pester the Package +$__dir=(Get-Item $PSScriptRoot) +$test_result = Invoke-Pester -Strict -PassThru -Script @{ + Path = "habitat/tests/test.pester.ps1"; + Parameters = @{PackageIdentifier=$PackageIdentifier} +} +if ($test_result.FailedCount -ne 0) { Exit $test_result.FailedCount } \ No newline at end of file diff --git a/habitat/tests/test.sh b/habitat/tests/test.sh new file mode 100644 index 00000000..763f347e --- /dev/null +++ b/habitat/tests/test.sh @@ -0,0 +1,24 @@ + +set -euo pipefail + + +project_root="$(git rev-parse --show-toplevel)" + +# print error message followed by usage and exit +error () { + local message="$1" + + echo -e "\nERROR: ${message}\n" >&2 + + exit 1 +} + +[[ -n "$pkg_ident" ]] || error 'no hab package identity provided' + +package_version=$(awk -F / '{print $3}' <<<"$pkg_ident") + +cd "${project_root}" + +echo "--- :mag_right: Testing ${pkg_ident} executables" +actual_version=$(hab pkg exec "${pkg_ident}" cookstyle -v | sed -E 's/.*version: ([0-9]+\.[0-9]+\.[0-9]+).*/\1/') +[[ "$package_version" = "$actual_version" ]] || error "cookstyle version is not the expected version. Expected '$package_version', got '$actual_version'" \ No newline at end of file