From f38a95ebf90f50ae028252c6bd5c4ec5792f76a7 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 24 Dec 2020 02:38:33 +0300 Subject: initial commit --- .github/workflows/test.yml | 99 ++++++++++++++++++++++++++++++++++++++++++++++ LICENSE.txt | 21 ++++++++++ action.yml | 49 +++++++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 LICENSE.txt create mode 100644 action.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a836a09 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,99 @@ +name: Test + +on: + push: + pull_request: + schedule: + # Weekly, at 5:45 AM on Friday (somewhat randomly chosen). + - cron: '45 5 * * 5' + workflow_dispatch: + +jobs: + test: + strategy: + fail-fast: false + matrix: + os: [windows-2019, windows-2016] + python: [0, 1] + default: [0, 1] + + include: + # Prettier run names. + - {os: windows-2019, name: 2019} + - {os: windows-2016, name: 2016} + - {default: 0, default_descr: ''} + - {default: 1, default_descr: ' + C:\Windows'} + - {python: 0, python_descr: ''} + - {python: 1, python_descr: ' + setup-python'} + + runs-on: '${{ matrix.os }}' + + name: '${{ matrix.name }}${{ matrix.default_descr }}${{ matrix.python_descr }}' + + defaults: + run: + shell: pwsh + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + if: matrix.python + + - name: Show %PATH% + run: | + $env:PATH.Split([IO.Path]::PathSeparator) | %{ echo $_ } + + # There should be plenty of MinGW distributions in PATH, some kind of GCC + # should be there. + - name: gcc.exe should be found + run: | + $(Get-Command gcc -ErrorAction SilentlyContinue) -or $(throw "gcc.exe wasn't found!") + + - name: python.exe should be found + run: | + $(Get-Command python -ErrorAction SilentlyContinue) -or $(throw "python.exe wasn't found!") + if: matrix.python + + - name: Clean up PATH + uses: ./ + with: + dirs: C:\foo;C:\bar + default: '${{ matrix.default }}' + + - name: Show %PATH% + run: | + $env:PATH.Split([IO.Path]::PathSeparator) | %{ echo $_ } + + - name: gcc.exe shouldn't be found + run: | + $(Get-Command gcc -ErrorAction SilentlyContinue) -and $(throw "cl.exe was found!") + + # I'm not sure how this works actually. + # Do these setup-* actions use a different API? + - name: python.exe should _still_ be found + run: | + $(Get-Command python -ErrorAction SilentlyContinue) -or $(throw "python.exe wasn't found!") + if: matrix.python + + - name: Check %PATH% + run: | + $env:PATH.Split([IO.Path]::PathSeparator) | %{ + if ($_.StartsWith('C:\Program Files\PowerShell')) { + # Thanks to `shell: pwsh`, C:\Program Files\PowerShell should + # be there. + } elseif ('${{ matrix.default }}' -eq '1' -and $_.StartsWith('C:\Windows')) { + # If the default paths are added, they all should start with + # C:\Windows. + } elseif ('${{ matrix.python }}' -eq '1' -and $_.Contains('\Python\')) { + # If we're testing w/ setup-python, it should still be there. + } elseif ($_ -eq 'C:\foo' -or $_ -eq 'C:\bar') { + # Our custom directories. + } else { + throw "Unexpected path: $_" + } + } diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..ab8c3ff --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Egor Tensin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..b262f8b --- /dev/null +++ b/action.yml @@ -0,0 +1,49 @@ +name: Clean up %PATH% +description: Clean up PATH environment variable on Windows workers + +inputs: + dirs: + description: Additional paths, separated by a semicolon (;) + required: false + default: + description: Add the default paths + required: false + default: 1 + +runs: + using: composite + steps: + - run: | + New-Variable os -Value ('${{ runner.os }}') -Option Constant + + New-Variable windows_host -Value ($os -eq 'Windows') -Option Constant + + New-Variable dirs -Value ('${{ inputs.dirs }}') -Option Constant + New-Variable default -Value ('${{ inputs.default }}' -eq '1') -Option Constant + + if ($windows_host) { + $sep = [IO.Path]::PathSeparator + + $new_path = $dirs.Split($sep, [System.StringSplitOptions]::RemoveEmptyEntries) + + if ($default) { + # This seems to be the default on new installations. + # Also, MSYS2 does this. + $new_path += @( + 'C:\Windows\system32', + 'C:\Windows', + 'C:\Windows\System32\Wbem', + 'C:\Windows\System32\WindowsPowerShell\v1.0\' + ) + } + + $new_path = $new_path -join $sep + echo "PATH=$new_path" >> $env:GITHUB_ENV + } else { + echo "::warning ::Not going to clean up PATH variable on $os" + } + shell: pwsh + +branding: + icon: star + color: green -- cgit v1.2.3