psake Build System

website·Indexed 32 days ago

https://psake.dev

A PowerShell-based build system for orchestrating workflows, featuring declarative task syntax, two-phase compilation, and local file-based caching. It includes an official VS Code extension (v1.0), integration with CI/CD platforms like GitHub Actions, Azure Pipelines, and GitLab, and a companion module called PowerShellBuild for managing release workflows.

Tokens
71.1K
Snippets
382
Records
431
Agent score
61%

What's inside psake

  1. Overview of PowerShellBuild

    PowerShellBuild is a curated library of pre-built psake tasks designed to handle the lifecycle of a PowerShell module. It eliminates the need to write repetitive scaffolding for common tasks such as cleaning output directories, staging files, running PSScriptAnalyzer and Pester tests, generating MAML help via PlatyPS, and publishing to the PowerShell Gallery.
  2. Overview of the psake Agent Skill

    The psake Agent Skill is a specialized knowledge package built on the open Agent Skills standard. It enables AI coding assistants to provide expert, context-aware guidance on psake build automation, including patterns, syntax, and best practices. It is designed to be portable across different AI platforms.
  3. Understand psake's output and scoping model

    psake executes build scripts in their own isolated scope. This has critical implications for data retrieval:

    • Invoke-psake does not return custom objects or data structures.
    • Variables defined inside a psakefile (including those with $script: scope) are not accessible to the calling script after Invoke-psake completes.
    • The primary indicator of success or failure is the exit code (0 for success, 1 for failure).
  4. Understand the structure of a psake build script

    A psake build script consists of calls to specific engine functions. The script follows a specific BNF structure allowing for includes, properties, setup/teardown blocks, and task definitions. Tasks can have dependencies and various action/condition blocks.
    Task default -Depends Test
    
    Task Test -Depends Compile, Clean {
       "This is a test"
     }
    
    Task Compile -Depends Clean {
       "Compile"
     }
    
    Task Clean {
       "Clean"
     }
  5. Use the psake VS Code extension for build automation

    The psake VS Code extension (v1.0+) allows developers to discover, navigate, and execute psake build tasks directly within the Visual Studio Code editor, removing the need to run tasks exclusively from the terminal.
  6. Access build context via the $psake object

    The $psake variable is a global context object available in all build scripts. It provides metadata about the module, the script's location, and the current execution state.
    # Useful properties:
    $psake.version             # Module version
    $psake.build_script_file    # Full path to the build script
    $psake.build_script_dir    # Directory of the build script
    $psake.build_success       # Boolean: has the build succeeded so far
    $psake.context             # Object containing currentTaskName, tasks, and properties
  7. Extract task metadata using Get-PSakeScriptTasks

    The Get-PSakeScriptTasks cmdlet returns metadata about all tasks defined in a specified psake script. It loads the build file and evaluates task definitions without executing the tasks themselves, making it suitable for IDE integrations, tooling, and tab completion.
    Get-PSakeScriptTasks -BuildFile '.\build.ps1'
  8. Debug and inspect running Docker containers

    Use the following tasks to interact with and monitor the .NET application container: Exec for shell access, Logs for streaming output, and Inspect for image metadata (ID, size, architecture).
    Task Exec {
        # Ensures container is running before executing
        $container = docker ps --filter "name=$ContainerName" --format "{{.Names}}" 2>$null
        if ($container -ne $ContainerName) { throw "Container not running" }
        exec { docker exec -it $ContainerName /bin/sh }
    }
    
    Task Logs {
        exec { docker logs -f $ContainerName }
    }
    
    Task Inspect -depends Build {
        $imageInfo = docker inspect $ImageFullName | ConvertFrom-Json
        Write-Host "  Size: $([math]::Round($imageInfo[0].Size / 1MB, 2)) MB"
    }
  9. Access build context via the $psake variable

    The $psake variable provides metadata about the current build execution, including the script path, directory, and version.
    Properties {
        $ProjectRoot = Split-Path $psake.build_script_file
    }
    
    Task Info {
        Write-Host "psake version: $($psake.version)"
        Write-Host "Build script: $($psake.build_script_file)"
    }
  10. Publish NuGet packages to Azure Artifacts

    Combine psake's packing capabilities with the NuGetCommand@2 task to push generated .nupkg files to an internal Azure Artifacts feed.
    steps:
      - pwsh: |
          Invoke-psake -taskList Build, Pack
        displayName: 'Build and pack NuGet packages'
    
      - task: NuGetCommand@2
        inputs:
          command: 'push'
          packagesToPush: '$(Build.SourcesDirectory)/build/*.nupkg'
          nuGetFeedType: 'internal'
          publishVstsFeed: 'MyProject/MyFeed'
        displayName: 'Publish to Azure Artifacts feed'