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
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BasedOnStyle: LLVM
IndentWidth: 4
ColumnLimit: 120
11 changes: 11 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": 1,
"isRoot": true,
"tools": {
"csharpier": {
"version": "1.3.0",
"commands": ["csharpier"],
"rollForward": false
}
}
}
94 changes: 94 additions & 0 deletions .dprint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"$schema": "https://dprint.dev/schemas/v0.json",
"lineWidth": 120,
"useTabs": false,
"newLineKind": "lf",
"includes": [
".dprint.jsonc",
".config/dotnet-tools.json",
"mise.toml",
".github/workflows/formatter-*.yml",
"Formatter/**/*.cs",
"Formatter/**/*.csproj",
"Formatter/**/*.json",
"Formatter/**/*.md",
"Formatter/**/*.mjs",
"Formatter/**/*.ps1",
"Formatter/**/*.sh",
"Formatter/**/*.ts",
"docs/FormatterWasm.md"
],
"powershell": {
"braceStyle": "nextLine",
"indentSize": 4,
"useTabs": false,
"correctKeywordCasing": true,
"spaceAroundOperators": true,
"spaceAroundPipe": true,
"spaceAfterSeparator": true
},
"json": {
"useTabs": false,
"indentWidth": 2
},
"markdown": {
"textWrap": "maintain",
"emphasisKind": "asterisks"
},
"typescript": {
"useTabs": false,
"indentWidth": 2,
"quoteStyle": "preferDouble"
},
"yaml": {
"indentWidth": 2,
"printWidth": 160
},
"shfmt": {
"useTabs": false,
"binaryNextLine": true,
"switchCaseIndent": true
},
"exec": {
"cwd": "${configDir}",
"lineWidth": 120,
"indentWidth": 4,
"useTabs": false,
"timeout": 120,
"commands": [
{
"command": "mise exec -- dotnet csharpier format --stdin-path {{cwd}}/{{file_path}} --log-level None",
"exts": ["cs", "csproj", "props", "targets", "resx", "ps1xml"],
"setupCommand": "mise exec -- dotnet tool restore --add-source https://api.nuget.org/v3/index.json --ignore-failed-sources",
"cacheKeyFiles": [".config/dotnet-tools.json"]
},
{
"command": "mise exec -- clang-format --assume-filename {{file_path}}",
"exts": ["c", "h"],
"cacheKeyFiles": [".clang-format", "mise.toml"]
},
{
"command": "mise exec -- tombi format - --stdin-filename {{file_path}}",
"exts": ["toml"],
"cacheKeyFiles": ["mise.toml"]
}
]
},
"excludes": [
"**/{bin,obj,out}/**",
"**/node_modules/**",
"PSCompatibilityCollector/{optional_profiles,profiles}/**",
"Formatter/Dprint/native/**",
"Formatter/Dprint/schema.json",
"Formatter/Dprint/tests/**"
],
"plugins": [
"Formatter/Dprint/bin/Release/net8.0/wasi-wasm/AppBundle/plugin.wasm",
"https://plugins.dprint.dev/kjanat/shfmt-1.0.0.wasm",
"https://plugins.dprint.dev/json-0.23.0.wasm",
"https://plugins.dprint.dev/markdown-0.22.1.wasm",
"https://plugins.dprint.dev/typescript-0.96.1.wasm",
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.6.0.wasm",
"https://plugins.dprint.dev/exec-0.7.3.json@a7898d5f1897e77bff474cec3d948c3ec3a7f455e32de2cc60c8adb9a5dd24aa"
]
}
38 changes: 32 additions & 6 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ jobs:
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Set up WASI SDK
if: matrix.os == 'ubuntu-latest'
uses: jdx/mise-action@v4
with:
install: true
install_args: github:WebAssembly/wasi-sdk
export_path: false

- name: Install dotnet
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v6
with:
cache: true
cache-dependency-path: '**/*.csproj'
Expand All @@ -31,6 +39,24 @@ jobs:
run: ./tools/installPSResources.ps1
shell: pwsh

- name: Install formatter workloads
run: |
$workloads = @("wasm-tools")
if ($IsLinux) {
$workloads += "wasi-experimental"
}
$arguments = @("workload", "install") + $workloads + @(
"--skip-manifest-update",
"--source", "https://api.nuget.org/v3/index.json"
)
& dotnet @arguments
if ($LASTEXITCODE -ne 0) {
$message = "Installing the formatter workloads failed with exit code $LASTEXITCODE."
"::error::$message"
throw $message
}
shell: pwsh

- name: Build
run: ./build.ps1 -Configuration Release -All -Verbose
shell: pwsh
Expand All @@ -46,12 +72,12 @@ jobs:
- name: Test Windows PowerShell
if: matrix.os == 'windows-latest'
run: |
Install-Module Pester -Scope CurrentUser -Force -SkipPublisherCheck
Install-Module Pester -RequiredVersion 5.7.1 -Scope CurrentUser -Force -SkipPublisherCheck
./build.ps1 -Test -Verbose
shell: powershell

- name: Download PowerShell install script
uses: actions/checkout@v4
uses: actions/checkout@v7
with:
repository: PowerShell/PowerShell
path: pwsh
Expand All @@ -70,14 +96,14 @@ jobs:
shell: pwsh

- name: Upload build artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
if: always()
with:
name: PSScriptAnalyzer-package-${{ matrix.os }}
path: out/**/*.nupkg

- name: Upload test results
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
if: always()
with:
name: PSScriptAnalyzer-tests-${{ matrix.os }}
Expand Down
114 changes: 114 additions & 0 deletions .github/workflows/formatter-npm-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Release PowerShell formatter npm package
on: { push: { tags: ["npm-[0-9]+.[0-9]+.[0-9]+"] } }
permissions: { contents: write }
defaults: { run: { shell: pwsh } }
jobs:
release:
if: github.repository == 'kjanat/PSScriptAnalyzer'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up mise and install tools
uses: jdx/mise-action@v4
with: { install: true }
- name: Verify release version
working-directory: Formatter/Wasm
run: |
$package = Get-Content -LiteralPath package.json -Raw | ConvertFrom-Json
$packageVersion = [string] $package.version
$expectedTag = "npm-$packageVersion"
if ($env:GITHUB_REF_NAME -cne $expectedTag) {
$message = "Tag {0} does not match npm package tag {1}." -f $env:GITHUB_REF_NAME, $expectedTag
"::error::$message"
throw $message
}
Add-Content -LiteralPath $env:GITHUB_ENV -Value "NPM_PACKAGE_VERSION=$packageVersion"
- name: Install .NET WebAssembly workload
run: |
$arguments = @(
"workload", "install", "wasm-tools",
"--skip-manifest-update",
"--source", "https://api.nuget.org/v3/index.json"
)
& dotnet @arguments
if ($LASTEXITCODE -ne 0) {
"::error::Installing the .NET WebAssembly workload failed with exit code $LASTEXITCODE."
throw "Installing the .NET WebAssembly workload failed with exit code $LASTEXITCODE."
}
- name: Build browser and Node.js package
run: |
$arguments = @(
"publish", "Formatter/Wasm/Formatter.Wasm.csproj",
"--configuration", "Release",
"--source", "https://api.nuget.org/v3/index.json"
)
& dotnet @arguments
if ($LASTEXITCODE -ne 0) {
"::error::Publishing the browser and Node.js package failed with exit code $LASTEXITCODE."
throw "Publishing the browser and Node.js package failed with exit code $LASTEXITCODE."
}
- name: Validate Node.js package
run: |
Formatter/Wasm/scripts/Test-Package.ps1 `
-PackageDirectory Formatter/Wasm/bin/Release/net8.0/browser-wasm/AppBundle
- name: Assemble npm release assets
run: |
$packageDirectory = Join-Path $PWD "Formatter/Wasm/bin/Release/net8.0/browser-wasm/AppBundle"
$releaseDirectory = Join-Path $env:RUNNER_TEMP "npm-release"
$null = New-Item -ItemType Directory -Path $releaseDirectory -Force

& npm pack $packageDirectory --pack-destination $releaseDirectory
if ($LASTEXITCODE -ne 0) {
"::error::Packing the npm package failed with exit code $LASTEXITCODE."
throw "Packing the npm package failed with exit code $LASTEXITCODE."
}

$tarballs = @(Get-ChildItem -LiteralPath $releaseDirectory -Filter *.tgz)
if ($tarballs.Count -ne 1) {
"::error::Expected one npm tarball, got $($tarballs.Count)."
throw "Expected one npm tarball, got $($tarballs.Count)."
}

$entries = @(& tar -tzf $tarballs[0].FullName)
if ($LASTEXITCODE -ne 0) {
"::error::Reading the npm tarball failed with exit code $LASTEXITCODE."
throw "Reading the npm tarball failed with exit code $LASTEXITCODE."
}
foreach ($requiredEntry in "package/LICENSE", "package/index.d.ts", "package/index.mjs") {
if ($requiredEntry -cnotin $entries) {
"::error::The npm tarball is missing $requiredEntry."
throw "The npm tarball is missing $requiredEntry."
}
}
if (-not ($entries -cmatch '^package/_framework/.*\.wasm$')) {
"::error::The npm tarball does not contain a WebAssembly runtime file."
throw "The npm tarball does not contain a WebAssembly runtime file."
}

$checksumsPath = Join-Path $releaseDirectory "checksums.txt"
$hash = (Get-FileHash -LiteralPath $tarballs[0].FullName -Algorithm SHA256).Hash.ToLowerInvariant()
Set-Content -LiteralPath $checksumsPath -Value "$hash $($tarballs[0].Name)"
Add-Content -LiteralPath $env:GITHUB_ENV -Value "NPM_TARBALL=$($tarballs[0].FullName)"
Add-Content -LiteralPath $env:GITHUB_ENV -Value "NPM_CHECKSUMS=$checksumsPath"
- name: Publish GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
$assets = @(
"$($env:NPM_TARBALL)#PowerShell formatter for WebAssembly $($env:NPM_PACKAGE_VERSION), npm package",
"$($env:NPM_CHECKSUMS)#PowerShell formatter for WebAssembly $($env:NPM_PACKAGE_VERSION), SHA-256 checksums"
)
$arguments = @("release", "create", $env:GITHUB_REF_NAME) + $assets + @(
"--repo", $env:GITHUB_REPOSITORY,
"--verify-tag",
"--prerelease",
"--latest=false",
"--title", "PowerShell formatter for WebAssembly $($env:NPM_PACKAGE_VERSION)",
"--notes-file", "Formatter/Wasm/release-notes.md"
)
& gh @arguments
if ($LASTEXITCODE -ne 0) {
"::error::Creating the GitHub release failed with exit code $LASTEXITCODE."
throw "Creating the GitHub release failed with exit code $LASTEXITCODE."
}
95 changes: 95 additions & 0 deletions .github/workflows/formatter-wasm-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Release dprint PowerShell formatter
on: { push: { tags: ["dprint-[0-9]+.[0-9]+.[0-9]+"] } }
permissions: { contents: write }
defaults: { run: { shell: pwsh } }
jobs:
release:
if: github.repository == 'kjanat/PSScriptAnalyzer'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up mise and install tools
uses: jdx/mise-action@v4
with:
install: true
- name: Verify release version
run: |
$version = (& dotnet msbuild Formatter/Dprint/Formatter.Dprint.csproj `
-nologo `
-getProperty:Version).Trim()
if ($LASTEXITCODE -ne 0) {
$message = "Reading the dprint plugin version failed with exit code $LASTEXITCODE."
"::error::$message"
throw $message
}
$expectedTag = "dprint-$version"
if ($env:GITHUB_REF_NAME -cne $expectedTag) {
$message = "Tag {0} does not match dprint plugin tag {1}." -f $env:GITHUB_REF_NAME, $expectedTag
"::error::$message"
throw $message
}
Add-Content -LiteralPath $env:GITHUB_ENV -Value "DPRINT_PLUGIN_VERSION=$version"
- name: Install .NET WASI workload
run: |
$arguments = @(
"workload", "install", "wasi-experimental",
"--skip-manifest-update",
"--source", "https://api.nuget.org/v3/index.json"
)
& dotnet @arguments
if ($LASTEXITCODE -ne 0) {
$message = "Installing the .NET WASI workload failed with exit code $LASTEXITCODE."
"::error::$message"
throw $message
}
- name: Build and validate plugin
run: |
& ./Formatter/Dprint/scripts/e2e.sh
if ($LASTEXITCODE -ne 0) {
$message = "Building and validating the dprint plugin failed with exit code $LASTEXITCODE."
"::error::$message"
throw $message
}
- name: Assemble release assets
run: |
$releaseDirectory = Join-Path $env:RUNNER_TEMP "dprint-release"
$null = New-Item -ItemType Directory -Path $releaseDirectory -Force
$assets = @(
@{ Source = "Formatter/Dprint/bin/Release/net8.0/wasi-wasm/AppBundle/plugin.wasm"; Name = "plugin.wasm" },
@{ Source = "Formatter/Dprint/schema.json"; Name = "schema.json" },
@{ Source = "Formatter/Dprint/LICENSE"; Name = "LICENSE" }
)
foreach ($asset in $assets) {
Copy-Item -LiteralPath $asset.Source -Destination (Join-Path $releaseDirectory $asset.Name)
}
$checksums = foreach ($asset in $assets) {
$path = Join-Path $releaseDirectory $asset.Name
$hash = (Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash.ToLowerInvariant()
"$hash $($asset.Name)"
}
Set-Content -LiteralPath (Join-Path $releaseDirectory "checksums.txt") -Value $checksums
- name: Publish GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
$releaseDirectory = Join-Path $env:RUNNER_TEMP "dprint-release"
$assets = @(
"$(Join-Path $releaseDirectory 'plugin.wasm')#dprint PowerShell formatter $($env:DPRINT_PLUGIN_VERSION), WebAssembly",
"$(Join-Path $releaseDirectory 'schema.json')#dprint PowerShell formatter $($env:DPRINT_PLUGIN_VERSION), configuration schema",
"$(Join-Path $releaseDirectory 'LICENSE')#dprint PowerShell formatter $($env:DPRINT_PLUGIN_VERSION), MIT license",
"$(Join-Path $releaseDirectory 'checksums.txt')#dprint PowerShell formatter $($env:DPRINT_PLUGIN_VERSION), SHA-256 checksums"
)
$arguments = @("release", "create", $env:GITHUB_REF_NAME) + $assets + @(
"--repo", $env:GITHUB_REPOSITORY,
"--verify-tag",
"--latest",
"--title", "dprint PowerShell formatter $($env:DPRINT_PLUGIN_VERSION)",
"--notes-file", "Formatter/Dprint/release-notes.md"
)
& gh @arguments
if ($LASTEXITCODE -ne 0) {
$message = "Creating the dprint GitHub release failed with exit code $LASTEXITCODE."
"::error::$message"
throw $message
}
Loading