├── script.ps1 ├── .github └── workflows │ ├── ci.yaml │ ├── manual.yaml │ ├── fails.yaml │ ├── exitcode.yaml │ ├── inline.yaml │ ├── modules.yaml │ ├── windows.yaml │ ├── parameters.yaml │ ├── envvar.yaml │ ├── secrets.yaml │ ├── multiline.yaml │ └── installmodule.yaml ├── README.md └── LICENSE /script.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | [Switch]$Fail, 3 | [Switch]$ExitCode, 4 | $Parameter1 5 | ) 6 | 7 | if ($Fail) { 8 | throw "This script fails!" 9 | } 10 | 11 | if ($ExitCode) { 12 | exit 5 13 | } 14 | 15 | $Env:MyVariable 16 | $Parameter1 17 | $PSVersionTable -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: [push, pull_request] 3 | 4 | jobs: 5 | build: 6 | name: Run Script 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Script 11 | run: ./script.ps1 12 | shell: pwsh -------------------------------------------------------------------------------- /.github/workflows/manual.yaml: -------------------------------------------------------------------------------- 1 | name: Manual 2 | on: [workflow_dispatch] 3 | 4 | jobs: 5 | build: 6 | name: Run Script 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Script 11 | run: ./script.ps1 12 | shell: pwsh -------------------------------------------------------------------------------- /.github/workflows/fails.yaml: -------------------------------------------------------------------------------- 1 | name: Fails 2 | on: [workflow_dispatch] 3 | 4 | jobs: 5 | build: 6 | name: Run Script 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Script 11 | run: ./script.ps1 -Fail 12 | shell: pwsh -------------------------------------------------------------------------------- /.github/workflows/exitcode.yaml: -------------------------------------------------------------------------------- 1 | name: Exit Code 2 | on: [workflow_dispatch] 3 | 4 | jobs: 5 | build: 6 | name: Run Script 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Script 11 | run: ./script.ps1 -ExitCode 12 | shell: pwsh -------------------------------------------------------------------------------- /.github/workflows/inline.yaml: -------------------------------------------------------------------------------- 1 | name: Inline 2 | on: [workflow_dispatch] 3 | 4 | jobs: 5 | build: 6 | name: Run Script 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Script 11 | run: Write-Host 'Hello, World' 12 | shell: pwsh -------------------------------------------------------------------------------- /.github/workflows/modules.yaml: -------------------------------------------------------------------------------- 1 | name: List Modules 2 | on: [workflow_dispatch] 3 | 4 | jobs: 5 | build: 6 | name: Run Script 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Script 11 | run: Get-Module -ListAvailable 12 | shell: pwsh -------------------------------------------------------------------------------- /.github/workflows/windows.yaml: -------------------------------------------------------------------------------- 1 | name: Windows PowerShell 2 | on: [workflow_dispatch] 3 | 4 | jobs: 5 | build: 6 | name: Run Script 7 | runs-on: windows-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Script 11 | run: .\script.ps1 12 | shell: powershell -------------------------------------------------------------------------------- /.github/workflows/parameters.yaml: -------------------------------------------------------------------------------- 1 | name: Parameters 2 | on: [workflow_dispatch] 3 | 4 | jobs: 5 | build: 6 | name: Run Script 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Script 11 | run: .\script.ps1 -Parameter1 'Hi' 12 | shell: pwsh -------------------------------------------------------------------------------- /.github/workflows/envvar.yaml: -------------------------------------------------------------------------------- 1 | name: Environment Variables 2 | on: [workflow_dispatch] 3 | 4 | jobs: 5 | build: 6 | name: Run Script 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Script 11 | run: ./script.ps1 12 | shell: pwsh 13 | env: 14 | MyVariable: 'Hello, World' -------------------------------------------------------------------------------- /.github/workflows/secrets.yaml: -------------------------------------------------------------------------------- 1 | name: Secrets 2 | on: [workflow_dispatch] 3 | 4 | jobs: 5 | build: 6 | name: Run Script 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Script 11 | run: .\script.ps1 12 | shell: pwsh 13 | env: 14 | MyVariable: ${{ secrets.MY_VARIABLE }} -------------------------------------------------------------------------------- /.github/workflows/multiline.yaml: -------------------------------------------------------------------------------- 1 | name: Multiline 2 | on: [workflow_dispatch] 3 | 4 | jobs: 5 | build: 6 | name: Run Script 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Script 11 | run: | 12 | Write-Host "Line 1" 13 | Write-Host "Line 2" 14 | Write-Host "Line 3" 15 | shell: pwsh -------------------------------------------------------------------------------- /.github/workflows/installmodule.yaml: -------------------------------------------------------------------------------- 1 | name: Install Module 2 | on: [workflow_dispatch] 3 | 4 | jobs: 5 | build: 6 | name: Run Script 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Script 11 | run: | 12 | Set-PSRepository PSGallery -InstallationPolicy Trusted 13 | Install-Module Universal 14 | Get-Module Universal -ListAvailable 15 | shell: pwsh -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PowerShell GitHub Actions 2 | 3 | This repository contains examples of using PowerShell in GitHub actions. The list of examples is below. 4 | 5 | - [Continuous Integration](./.github/workflows/ci.yaml) 6 | - [Environment Variables](./.github/workflows/envvar.yaml) 7 | - [Exit Codes](./.github/workflows/exitcode.yaml) 8 | - [Failures](./.github/workflows/fails.yaml) 9 | - [Inline](./.github/workflows/inline.yaml) 10 | - [Install Module](./.github/workflows/installmodule.yaml) 11 | - [List Installed Modules](./.github/workflows/modules.yaml) 12 | - [Manual Execution](./.github/workflows/manual.yaml) 13 | - [Multiline](./.github/workflows/multiline.yaml) 14 | - [Parameters](./.github/workflows/parameters.yaml) 15 | - [Secrets](./.github/workflows/secrets.yaml) 16 | - [Windows PowerShell](./.github/workflows/windows.yaml) 17 | 18 | I'm always open to PRs! 19 | 20 | To see these actions, erm, in action, check out this [YouTube video](https://youtu.be/FU7w7We_hh8). 21 | 22 | You can also fork this repo if you want to execute the actions yourself. 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Adam Driscoll 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------