Skip to content

Commit

Permalink
Run Installer tests in cicd
Browse files Browse the repository at this point in the history
  • Loading branch information
twangboy committed May 23, 2024
1 parent bb94d15 commit e2814f9
Show file tree
Hide file tree
Showing 141 changed files with 370 additions and 3,516 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ jobs:
- prepare-workflow
with:
changed-files: ${{ needs.prepare-workflow.outputs.changed-files }}
installer:
name: Windows Installer
if: ${{ fromJSON(needs.prepare-workflow.outputs.runners)['github-hosted'] }}
uses: ./.github/workflows/test-installer-action-windows.yml
needs:
- prepare-workflow
with:
changed-files: ${{ needs.prepare-workflow.outputs.changed-files }}

prepare-release:
name: "Prepare Release: ${{ needs.prepare-workflow.outputs.salt-version }}"
Expand Down Expand Up @@ -2172,6 +2180,7 @@ jobs:
- prepare-workflow
- pre-commit
- lint
- installer
- build-docs
- build-deps-onedir
- build-salt-onedir
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ jobs:
- prepare-workflow
with:
changed-files: ${{ needs.prepare-workflow.outputs.changed-files }}
installer:
name: Windows Installer
if: ${{ fromJSON(needs.prepare-workflow.outputs.runners)['github-hosted'] }}
uses: ./.github/workflows/test-installer-action-windows.yml
needs:
- prepare-workflow
with:
changed-files: ${{ needs.prepare-workflow.outputs.changed-files }}

prepare-release:
name: "Prepare Release: ${{ needs.prepare-workflow.outputs.salt-version }}"
Expand Down Expand Up @@ -3080,6 +3088,7 @@ jobs:
- prepare-workflow
- pre-commit
- lint
- installer
- build-docs
- build-deps-onedir
- build-salt-onedir
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Do not edit these workflows directly as the changes made will be overwritten.
# Instead, edit the template '.github/workflows/templates/release.yml.jinja'
# Instead, edit the template '.github\workflows\templates\release.yml.jinja'
---

name: Release
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ jobs:
- prepare-workflow
with:
changed-files: ${{ needs.prepare-workflow.outputs.changed-files }}
installer:
name: Windows Installer
if: ${{ fromJSON(needs.prepare-workflow.outputs.runners)['github-hosted'] }}
uses: ./.github/workflows/test-installer-action-windows.yml
needs:
- prepare-workflow
with:
changed-files: ${{ needs.prepare-workflow.outputs.changed-files }}

prepare-release:
name: "Prepare Release: ${{ needs.prepare-workflow.outputs.salt-version }}"
Expand Down Expand Up @@ -2213,6 +2221,7 @@ jobs:
- prepare-workflow
- pre-commit
- lint
- installer
- build-docs
- build-deps-onedir
- build-salt-onedir
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ jobs:
- prepare-workflow
with:
changed-files: ${{ needs.prepare-workflow.outputs.changed-files }}
installer:
name: Windows Installer
if: ${{ fromJSON(needs.prepare-workflow.outputs.runners)['github-hosted'] }}
uses: ./.github/workflows/test-installer-action-windows.yml
needs:
- prepare-workflow
with:
changed-files: ${{ needs.prepare-workflow.outputs.changed-files }}

prepare-release:
name: "Prepare Release: ${{ needs.prepare-workflow.outputs.salt-version }}"
Expand Down Expand Up @@ -3085,6 +3093,7 @@ jobs:
- prepare-workflow
- pre-commit
- lint
- installer
- build-docs
- build-deps-onedir
- build-salt-onedir
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/templates/ci.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@

<%- endif %>

<%- set job_name = "installer" %>
<%- if includes.get(job_name, True) %>
<{ job_name }>:
<%- do conclusion_needs.append(job_name) %>
name: Windows Installer
if: ${{ fromJSON(needs.prepare-workflow.outputs.runners)['github-hosted'] }}
uses: ./.github/workflows/test-installer-action-windows.yml
needs:
- prepare-workflow
with:
changed-files: ${{ needs.prepare-workflow.outputs.changed-files }}

<%- endif %>


<%- set job_name = "prepare-release" %>
<%- if includes.get(job_name, True) %>
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/test-installer-action-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test Installer

on:
workflow_call:
inputs:
changed-files:
required: true
type: string
description: JSON string containing information about changed files
pull_request:
paths:
- 'pkg/windows/**'

jobs:

test:
name: Test NSIS Installer
runs-on: windows-latest

steps:
- name: Checkout Source Code
uses: actions/checkout@v4

- name: Install NSIS
run: pkg/windows/install_nsis.cmd -CICD

- name: Setup test environment
run: pkg/windows/nsis/tests/setup.ps1 -CICD

- name: Run Installer Tests
run: pkg/windows/nsis/tests/test.ps1 -CICD

- name: Clean up environment
run: pkg/windows/nsis/tests/clean.ps1 -CICD
38 changes: 0 additions & 38 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1981,41 +1981,3 @@ def ci_test_onedir_pkgs(session):
on_rerun=True,
)
sys.exit(0)


@nox.session(python="3", name="ci-test-installer")
def ci_test_installer(session):
"""
Test a dummy installer to make sure the installer logic is working correctly
"""
installers = ["nsis", "msi"]
if not session.posargs or session.posargs[0] not in installers:
installer = "nsis"
session.log("Choosing default 'nsis' installer type")
else:
installer = session.posargs.pop(0)

# Build dummy installer
tests_root = REPO_ROOT / "tests" / "pytests" / "pkg" / "installer" / installer
setup_file = tests_root / "setup.ps1"
session.run("PowerShell", "-ExecutionPolicy", "RemoteSigned", "-File", setup_file)

session.install("--progress-bar=off", "psutil", silent=PIP_INSTALL_SILENT)

requirements_file = os.path.join("requirements", "pytest.txt")
install_command = ["--progress-bar=off", "-r", requirements_file]
session.install(*install_command, silent=PIP_INSTALL_SILENT)

# Install the Salt requirements, though they're not needed for these tests
requirements_file = _get_pip_requirements_file(session, requirements_type="ci")
install_command = ["--progress-bar=off", "-r", requirements_file]
session.install(*install_command, silent=PIP_INSTALL_SILENT)

# Run installer tests
cmd_args = ["-vvv", "--rootdir", str(tests_root), "--"]
if not session.posargs:
cmd_args.append(str(tests_root / "config_tests"))
else:
cmd_args.extend(session.posargs)
# os.chdir(tests_root)
session.run("python", "-m", "pytest", *cmd_args)
File renamed without changes.
1 change: 1 addition & 0 deletions pkg/windows/buildenv/python.exe
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
binary
1 change: 1 addition & 0 deletions pkg/windows/buildenv/ssm.exe
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
binary
3 changes: 0 additions & 3 deletions pkg/windows/nsis/clean.cmd

This file was deleted.

78 changes: 0 additions & 78 deletions pkg/windows/nsis/clean.ps1

This file was deleted.

3 changes: 0 additions & 3 deletions pkg/windows/nsis/test.cmd

This file was deleted.

34 changes: 31 additions & 3 deletions pkg/windows/nsis/tests/clean.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,37 @@ clean.ps1
clean.ps1
#>
param(
[Parameter(Mandatory=$false)]
[Alias("c")]
# Don't pretify the output of the Write-Result
[Switch] $CICD
)

#-------------------------------------------------------------------------------
# Script Preferences
#-------------------------------------------------------------------------------

$ProgressPreference = "SilentlyContinue"
$ErrorActionPreference = "Stop"

#-------------------------------------------------------------------------------
# Script Variables
#-------------------------------------------------------------------------------

$SCRIPT_DIR = (Get-ChildItem "$($myInvocation.MyCommand.Definition)").DirectoryName
$SCRIPT_DIR = (Get-ChildItem "$($myInvocation.MyCommand.Definition)").DirectoryName

#-------------------------------------------------------------------------------
# Script Functions
#-------------------------------------------------------------------------------

function Write-Result($result, $ForegroundColor="Green") {
$position = 80 - $result.Length - [System.Console]::CursorLeft
Write-Host -ForegroundColor $ForegroundColor ("{0,$position}$result" -f "")
if ( $CICD ) {
Write-Host $result -ForegroundColor $ForegroundColor
} else {
$position = 80 - $result.Length - [System.Console]::CursorLeft
Write-Host -ForegroundColor $ForegroundColor ("{0,$position}$result" -f "")
}
}

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -61,6 +74,7 @@ if ( Test-Path -Path "$SCRIPT_DIR\venv" ) {
Write-Result "Success" -ForegroundColor Green
}
}

#-------------------------------------------------------------------------------
# Remove test-setup.exe
#-------------------------------------------------------------------------------
Expand All @@ -75,6 +89,20 @@ if ( Test-Path -Path "$SCRIPT_DIR\test-setup.exe" ) {
}
}

#-------------------------------------------------------------------------------
# Remove custom_conf
#-------------------------------------------------------------------------------
if ( Test-Path -Path "$SCRIPT_DIR\custom_conf" ) {
Write-Host "Removing custom_conf: " -NoNewline
Remove-Item -Path "$SCRIPT_DIR\custom_conf" -Recurse -Force
if ( Test-Path -Path "$SCRIPT_DIR\custom_conf" ) {
Write-Result "Failed" -ForegroundColor Red
exit 1
} else {
Write-Result "Success" -ForegroundColor Green
}
}

#-------------------------------------------------------------------------------
# Script Completed
#-------------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions pkg/windows/nsis/tests/config_tests/test_custom_full_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ def install():
pytest.helpers.clean_env()

# Create a custom config
pytest.helpers.custom_config()

full_path_conf = rf"{pytest.REPO_DIR}\custom_conf"

full_path_conf = pytest.helpers.custom_config()
# Install salt with custom config
pytest.helpers.run_command(
[pytest.INST_BIN, "/S", f"/custom-config={full_path_conf}"]
)
Expand All @@ -20,6 +18,8 @@ def install():


def test_binaries_present(install):
# This will show the contents of the directory on failure
dir_contents = pytest.helpers.run_command(f'cmd /c dir "{pytest.INST_DIR}"')
assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe")


Expand All @@ -29,7 +29,7 @@ def test_config_present(install):

def test_config_correct(install):
# The config file should be the custom config, unchanged
with open(rf"{pytest.REPO_DIR}\custom_conf") as f:
with open(rf"{pytest.SCRIPT_DIR}\custom_conf") as f:
expected = f.readlines()

with open(rf"{pytest.DATA_DIR}\conf\minion") as f:
Expand Down
2 changes: 2 additions & 0 deletions pkg/windows/nsis/tests/config_tests/test_custom_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def install():


def test_binaries_present(install):
# This will show the contents of the directory on failure
dir_contents = pytest.helpers.run_command(f'cmd /c dir "{pytest.INST_DIR}"')
assert os.path.exists(rf"{pytest.INST_DIR}\ssm.exe")


Expand Down
Loading

0 comments on commit e2814f9

Please sign in to comment.