Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ jobs:
image: ${{ matrix.docker_container }}
mapping_path: 'c:\map'
entrypoint: powershell.exe
entrypoint_args: '-NoLogo -NonInteractive -NoProfile'
env_names: TEST_MAPPING_PATH
run: |
run: >-
c:\map\test\run_test.ps1 -testPath "c:\map\test\run_default.Tests.ps1";

- name: Test_ExtraArgs
Expand All @@ -48,28 +47,27 @@ jobs:
mapping_path: 'c:\map'
workspace_path: ${{ github.workspace }}
extra_args: --entrypoint cmd.exe
run: |
echo Hello world & exit %ERRORLEVEL%
run: >-
echo "Hello world";
exit %ERRORLEVEL%;

- name: Test_Environment
uses: ./
with:
image: ${{ matrix.docker_container }}
entrypoint: powershell.exe
entrypoint_args: '-NoLogo -NonInteractive -NoProfile'
mapping_path: 'c:\map'
env_names: TEST1, TEST2, TEST3
run: |
run: >-
c:\map\test\run_test.ps1 -testPath "c:\map\test\environment.Tests.ps1";

- name: Test_Default_Environment
uses: ./
with:
image: ${{ matrix.docker_container }}
entrypoint: powershell.exe
entrypoint_args: '-NoLogo -NonInteractive -NoProfile'
mapping_path: 'c:\map'
run: |
run: >-
c:\map\test\run_test.ps1 -testPath "c:\map\test\default_environment.Tests.ps1";

- name: Test_WorkPath
Expand All @@ -79,9 +77,8 @@ jobs:
mapping_path: 'c:\map'
work_path: 'c:\temp'
entrypoint: powershell.exe
entrypoint_args: '-NoLogo -NonInteractive -NoProfile'
memory: 3GB
run: |
run: >-
c:\map\test\run_test.ps1 -testPath "c:\map\test\work_path.Tests.ps1";

- name: Test_MappingPath
Expand All @@ -91,9 +88,8 @@ jobs:
mapping_path: 'c:\mapping'
work_path: 'c:\temp'
entrypoint: powershell.exe
entrypoint_args: '-NoLogo -NonInteractive -NoProfile'
memory: 3GB
run: |
run: >-
c:\mapping\test\run_test.ps1 -testPath "c:\mapping\test\mapping_path.Tests.ps1";

- name: Test_WorkSpacePath
Expand All @@ -103,10 +99,9 @@ jobs:
mapping_path: 'c:\map'
workspace_path: ${{ github.workspace }}/test
entrypoint: powershell.exe
entrypoint_args: '-NoLogo -NonInteractive -NoProfile'
memory: 3GB
env_names: TEST_MAPPING_PATH
run: |
run: >-
c:\map\run_test.ps1 -testPath "c:\map\workspace_path.Tests.ps1";

validate:
Expand All @@ -117,25 +112,25 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Install
shell: pwsh -NoLogo -NonInteractive -NoProfile -Command ". '{0}'"
run: |
shell: pwsh
run: >-
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted;
Install-Module -Name Pester -Force -SkipPublisherCheck;
Update-Module -Name Pester -Force;
Install-Module -Name PSScriptAnalyzer -Force;
Import-Module PSScriptAnalyzer -ErrorAction Stop
- name: Linter src
shell: pwsh -NoLogo -NonInteractive -NoProfile -Command ". '{0}'"
run: |
shell: pwsh
run: >-
Invoke-ScriptAnalyzer -Path src -EnableExit;
- name: Linter test
shell: pwsh -NoLogo -NonInteractive -NoProfile -Command ". '{0}'"
run: |
shell: pwsh
run: >-
Invoke-ScriptAnalyzer -Path test -EnableExit;
- name: Test-Action-Scripts
shell: pwsh -NoLogo -NonInteractive -NoProfile -Command ". '{0}'"
run: |
Set-Location src;
shell: pwsh
run: >-
cd src;
$config=New-PesterConfiguration;
$config.Run.Exit=$true;
Invoke-Pester -Configuration $config;
25 changes: 4 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,8 @@ Composite action for running commands in windows docker containers.

## Usage

Simple 'Hello world' example using the default `cmd.exe` ENTRYPOINT with the `/C` option:
```
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Test_Run
uses: philips-software/run-windows-docker-container-action@<version>
with:
image: mcr.microsoft.com/windows/servercore:20H2
entrypoint_args: /C
run: >-
echo Hello world &
call run-test-script.bat;
```
Very simple hello world example:

Simple 'Hello world' example overriding the default ENTRYPOINT:
```
steps:
- name: Checkout
Expand All @@ -41,7 +25,7 @@ Simple 'Hello world' example overriding the default ENTRYPOINT:
image: mcr.microsoft.com/windows/servercore:20H2
entrypoint: powershell.exe
run: >-
Write-Output "Hello world";
echo "Hello world";
./run-test-script.ps1;
```

Expand All @@ -60,17 +44,16 @@ and work path.
| parameter | description | required | default |
| - | - | - | - |
| image | Docker image. | `true` | |
| run | Command to execute. Must be single line for cmd.exe entry point (use &, && or \|\| operators to aggregate multiple commands). Can be multiline for entry points that support it, like powershell.exe. | `true` | |
| run | Command to execute. | `true` | |
| workspace_path | Workspace path. Default is root workspace path. | `false` | |
| mapping_path | Mapping path, i.e. path to where the workspace path is mapped in the docker container. Defaults to workspace_path. | `false` | |
| work_path | Work path, i.e. path where the command in the docker container is executed. Defaults to workspace_path. | `false` | |
| memory | Memory limit. See docker documentation on --memory. | `false` | 4GB |
| entrypoint | Overrides the default ENTRYPOINT in docker image. | `false` | |
| entrypoint_args | Optional arguments for the ENTRYPOINT (default or overriden). For instance, `/S /C` for cmd.exe or `-NoLogo -NonInteractive -NoProfile` for powershell.exe. | `false` | |
| env_names | Environment variable names passed to docker image as comma separated list, for example: NAME1, NAME2, NAME3 | `false` | |
| extra_args | Extra arguments for docker run command. | `false` | |
| pre-warm | Run a warming-up container (which might crash due to first time use failure) | `false` | true |
| pre-warm-cmd | Pre warm command to run inside the container | `false` | Write-Output "warming up!" |
| pre-warm-cmd | Pre warm command to run inside the container | `false` | echo "warming up!" |
| registry_authentication | Authenticate against registry server | `false` | false |
| registry_username | Docker registry username. | `false` | |
| registry_token | Docker registry token | `false` | |
Expand Down
55 changes: 19 additions & 36 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inputs:
description: 'Docker image.'
required: true
run:
description: 'Command to execute. Must be single line for cmd.exe entry point (use &, && or \|\| operators to aggregate multiple commands). Can be multiline for entry points that support it, like powershell.exe.'
description: 'Command to execute.'
required: true
workspace_path:
description: 'Workspace path. Default is root workspace path.'
Expand All @@ -29,10 +29,6 @@ inputs:
description: "Overrides the default ENTRYPOINT in docker image."
required: false
default: ''
entrypoint_args:
description: "Optional arguments for the ENTRYPOINT (default or overriden). For instance, `/S /C` for cmd.exe or `-NoLogo -NonInteractive -NoProfile` for powershell.exe."
required: false
default: ''
env_names:
description: 'Environment variable names passed to docker image as comma separated list, for example: NAME1, NAME2, NAME3'
required: false
Expand All @@ -48,7 +44,7 @@ inputs:
pre-warm-cmd:
description: 'Pre warm command to run inside the container'
required: false
default: 'Write-Output "warming up!"'
default: 'echo "warming up!"'
registry_authentication:
description : 'Authenticate against registry server'
required : false
Expand All @@ -74,41 +70,31 @@ runs:
shell: bash
- name: settings
id: settings
run: |
run: >-
${{ github.action_path }}/src/parse_input_paths.ps1 -githubWorkSpace "${{ github.workspace }}" -workspacePath "@${{ inputs.workspace_path }}" -mappingPath "@${{ inputs.mapping_path }}" -workPath "@${{ inputs.work_path }}";
${{ github.action_path }}/src/parse_input_extra_args.ps1 -envNames "@${{ inputs.env_names }}" -entryPoint "@${{ inputs.entrypoint }}" -extraArgs "@${{ inputs.extra_args }}";
${{ github.action_path }}/src/assign_default_environment_variables.ps1;
shell: powershell -NoLogo -NonInteractive -NoProfile -Command ". '{0}'"
shell: powershell
- name: docker_login
id: docker_login
if: inputs.registry_authentication == 'true'
shell: powershell -NoLogo -NonInteractive -NoProfile -Command ". '{0}'"
run: |
shell: powershell
run: >-
docker login ${{ inputs.registry_repository }} -u ${{ inputs.registry_username }} -p ${{ inputs.registry_token }}
- name: Pre-warm
if: inputs.pre-warm == 'true'
run: >-
docker run
${{ steps.settings.outputs.extra_args }}
--rm
--memory=${{ inputs.memory }}
-v ${{ steps.settings.outputs.workspace_path }}:${{ steps.settings.outputs.mapping_path }}
-w ${{ steps.settings.outputs.work_path }}
${{ inputs.image }}
${{ inputs.entrypoint_args }}
@"

${{ inputs.pre-warm-cmd }}

"@

run: |
docker run ${{ steps.settings.outputs.extra_args }} `
--rm --memory=${{ inputs.memory }} `
-v ${{ steps.settings.outputs.workspace_path }}:${{ steps.settings.outputs.mapping_path }} `
-w ${{ steps.settings.outputs.work_path }} `
${{ inputs.image }} { ${{ inputs.pre-warm-cmd }} }
exit 0
shell: powershell -NoLogo -NonInteractive -NoProfile -Command ". '{0}'"
shell: powershell
- name: Run
run: >-
$runnerPathSource = Split-Path -Path "${env:RUNNER_TEMP}" -Parent;

$runnerPathTarget = $runnerPathSource.replace('D:', 'C:');
$runnerPathTarget = $runnerPathSource.replace('D:', 'C:')

docker run
${{ steps.settings.outputs.default_environment_variables }}
Expand All @@ -119,16 +105,13 @@ runs:
-v ${{ steps.settings.outputs.workspace_path }}:${{ steps.settings.outputs.mapping_path }}
-w ${{ steps.settings.outputs.work_path }}
${{ inputs.image }}
${{ inputs.entrypoint_args }}
@"

{
${{ inputs.run }}

"@
shell: powershell -NoLogo -NonInteractive -NoProfile -Command ". '{0}'"
}
shell: powershell
- name: docker_logout
id: docker_logout
if: inputs.registry_authentication == 'true'
shell: powershell -NoLogo -NonInteractive -NoProfile -Command ". '{0}'"
run: |
shell: powershell
run: >-
docker logout ${{ inputs.registry_repository }}