|
1 | | -# Template-Action |
| 1 | +# Install-PowerShell |
2 | 2 |
|
3 | | -A template repository for GitHub Actions |
| 3 | +A cross‑platform GitHub Action that installs a specific **PowerShell Core** version—or the latest stable release—on any GitHub‑hosted runner |
| 4 | +(Linux, macOS, or Windows). The action automatically skips installation when the requested version is already present. |
4 | 5 |
|
5 | 6 | ## Usage |
6 | 7 |
|
7 | | -### Inputs |
| 8 | +Add the action to a job in your workflow file: |
8 | 9 |
|
9 | | -### Secrets |
10 | | - |
11 | | -### Outputs |
| 10 | +```yaml |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
12 | 16 |
|
13 | | -### Example |
| 17 | + - name: Install PowerShell |
| 18 | + uses: PSModule/install-powershell@v1 |
| 19 | + with: |
| 20 | + Version: 7.5.0 |
14 | 21 |
|
15 | | -```yaml |
16 | | -Example here |
| 22 | + - name: Run a PowerShell script |
| 23 | + shell: pwsh |
| 24 | + run: | |
| 25 | + Write-Host "Using PowerShell $($PSVersionTable.PSVersion)" |
17 | 26 | ``` |
| 27 | +
|
| 28 | +## Inputs |
| 29 | +
|
| 30 | +| Input | Required | Default | Description | |
| 31 | +| ------- | -------- | ------- | ----------- | |
| 32 | +| `Version` | `false` | `latest` | Desired PowerShell Core version (e.g. `7.4.1`). Use `latest` to install the newest stable release. | |
| 33 | + |
| 34 | +## Secrets |
| 35 | + |
| 36 | +This action does **not** require any secrets. |
| 37 | + |
| 38 | +## Outputs |
| 39 | + |
| 40 | +This action does **not** generate any outputs. |
| 41 | + |
| 42 | +## How it works |
| 43 | + |
| 44 | +* **Version resolution** |
| 45 | + If `Version` is set to `latest` (case‑insensitive), the action queries the GitHub API for the newest stable release tag in the |
| 46 | + `PowerShell/PowerShell` repository and substitutes that version. |
| 47 | + |
| 48 | +* **Skip logic** |
| 49 | + Before installing, the action checks the current runner to see whether the requested version is already available |
| 50 | + (`pwsh -Command $($PSVersionTable.PSVersion)`). If it matches, the step ends immediately. |
| 51 | + |
| 52 | +* **Platform‑specific installers** |
| 53 | + | Runner OS | Install strategy | |
| 54 | + | --------- | ---------------- | |
| 55 | + | **Linux** (Debian/Ubuntu‑based) | Uses APT if available; otherwise downloads the `.deb` asset directly from the release page and installs with `dpkg`. | |
| 56 | + | **macOS** | Prefers Homebrew Cask (`brew install --cask powershell`) and falls back to downloading the `.pkg` installer. ARCH detection (`arm64` / `x64`) is automatic. | |
| 57 | + | **Windows** | Downloads the corresponding `.msi` package and installs silently with `msiexec`. | |
| 58 | + |
| 59 | +* **Error handling** |
| 60 | + The step fails with a clear error message if the requested version cannot be resolved or if the operating‑system distribution is unsupported (e.g., non‑APT Linux distros). |
0 commit comments