Skip to content
Draft
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
21 changes: 21 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "./node_modules/@typescript-eslint/eslint-plugin/dist/configs/recommended.js",
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-function-return-type": [
"error",
{
"allowExpressions": true
}
],
"semi": ["error", "never"],
"no-console": "warn"
},
"env": {
"node": true,
"es6": true
}
}
101 changes: 101 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Build
run: npm run build

- name: Test
run: npm test

- name: Package
run: npm run package

- name: Verify dist is up to date
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. Please run 'npm run all' and commit the changes."
git diff --ignore-space-at-eol dist/
exit 1
fi

test-action:
name: Test Action (Linux)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- name: Run setup-dsc action
uses: ./
id: setup-dsc

- name: Verify DSC installed
run: dsc --version

- name: Print installed version
run: echo "DSC version ${{ steps.setup-dsc.outputs.dsc-version }} installed"

test-action-windows:
name: Test Action (Windows)
runs-on: windows-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- name: Run setup-dsc action
uses: ./
id: setup-dsc

- name: Verify DSC installed
run: dsc --version

- name: Print installed version
run: echo "DSC version ${{ steps.setup-dsc.outputs.dsc-version }} installed"

test-action-macos:
name: Test Action (macOS)
runs-on: macos-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- name: Run setup-dsc action
uses: ./
id: setup-dsc

- name: Verify DSC installed
run: dsc --version

- name: Print installed version
run: echo "DSC version ${{ steps.setup-dsc.outputs.dsc-version }} installed"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
lib/
*.js.map
coverage/
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,68 @@
# setup-dsc
GitHub Action for installing DSCv3

## Usage

### Install the latest stable DSC

```yaml
- name: Setup DSC
uses: PowerShell/setup-dsc@v1
```

### Install a specific version of DSC

```yaml
- name: Setup DSC
uses: PowerShell/setup-dsc@v1
with:
dsc-version: '3.0.0'
```

## Inputs

| Name | Description | Default |
|------|-------------|---------|
| `dsc-version` | Version of DSC to install. Supports exact versions (e.g. `3.0.0`) or `latest` to get the latest stable release. | `latest` |

## Outputs

| Name | Description |
|------|-------------|
| `dsc-version` | The version of DSC that was installed |

## Supported Platforms

| OS | Architecture |
|----|-------------|
| Windows | x64, arm64 |
| Linux | x64, arm64 |
| macOS | x64, arm64 |

## Example Workflow

```yaml
name: DSC Configuration

on: [push]

jobs:
configure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup DSC
uses: PowerShell/setup-dsc@v1
id: setup-dsc

- name: Verify DSC version
run: dsc --version

- name: Apply configuration
run: dsc config apply --path ./config.dsc.yaml
```

## License

This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
48 changes: 48 additions & 0 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {getAssetName, getDownloadUrl} from '../src/utils'

describe('installer', () => {
describe('asset name generation', () => {
it('should generate correct asset name for windows x64', () => {
const name = getAssetName('3.0.0', 'windows', 'x86_64')
expect(name).toBe('DSC-3.0.0-x86_64-pc-windows-msvc.zip')
})

it('should generate correct asset name for linux x64', () => {
const name = getAssetName('3.0.0', 'linux', 'x86_64')
expect(name).toBe('DSC-3.0.0-x86_64-unknown-linux-gnu.tar.gz')
})

it('should generate correct asset name for darwin x64', () => {
const name = getAssetName('3.0.0', 'darwin', 'x86_64')
expect(name).toBe('DSC-3.0.0-x86_64-apple-darwin.tar.gz')
})

it('should generate correct asset name for darwin arm64', () => {
const name = getAssetName('3.0.0', 'darwin', 'aarch64')
expect(name).toBe('DSC-3.0.0-aarch64-apple-darwin.tar.gz')
})

it('should generate correct asset name for linux arm64', () => {
const name = getAssetName('3.0.0', 'linux', 'aarch64')
expect(name).toBe('DSC-3.0.0-aarch64-unknown-linux-gnu.tar.gz')
})

it('should throw for unsupported platform', () => {
expect(() => getAssetName('3.0.0', 'freebsd', 'x86_64')).toThrow(
'Unsupported platform: freebsd'
)
})
})

describe('download URL generation', () => {
it('should generate correct download URL', () => {
const url = getDownloadUrl(
'3.0.0',
'DSC-3.0.0-x86_64-pc-windows-msvc.zip'
)
expect(url).toBe(
'https://github.com/PowerShell/DSC/releases/download/v3.0.0/DSC-3.0.0-x86_64-pc-windows-msvc.zip'
)
})
})
})
21 changes: 21 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Setup DSC'
description: 'Install the latest stable DSCv3 package and add it to the PATH'
author: 'Microsoft Corporation'

inputs:
dsc-version:
description: 'Version of DSC to install. Defaults to latest stable.'
required: false
default: 'latest'

outputs:
dsc-version:
description: 'The version of DSC that was installed'

runs:
using: 'node20'
main: 'dist/index.js'

branding:
icon: 'package'
color: 'blue'
54 changes: 54 additions & 0 deletions dist/index.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"preset": "ts-jest",
"testEnvironment": "node",
"testMatch": ["**/__tests__/**/*.test.ts"],
"transform": {
"^.+\\.ts$": "ts-jest"
},
"verbose": true,
"clearMocks": true
}
Loading