applyTo:
- .github/**/*.yml
- .github/**/*.yaml
Build and Checkout Prerequisites for PowerShell CI
This document describes the checkout and build prerequisites used in PowerShell's CI workflows. It is intended for GitHub Copilot sessions working with the build system.
Overview
The PowerShell repository uses a standardized build process across Linux, Windows, and macOS CI workflows. Understanding the checkout configuration and the Sync-PSTags operation is crucial for working with the build system.
Checkout Configuration
Fetch Depth
All CI workflows that build or test PowerShell use fetch-depth: 1000 in the checkout step:
- name: checkout
uses: actions/checkout@v5
with:
fetch-depth: 1000
Why 1000 commits?
- The build system needs access to Git history to determine version information
Sync-PSTagsrequires sufficient history to fetch and work with tags- 1000 commits provides a reasonable balance between clone speed and having enough history for version calculation
- Shallow clones (fetch-depth: 1) would break versioning logic
Exceptions:
- The
changesjob uses default fetch depth (no explicitfetch-depth) since it only needs to detect file changes - The
analyzejob (CodeQL) usesfetch-depth: '0'(full history) for comprehensive security analysis - Linux packaging uses
fetch-depth: 0to ensure all tags are available for package version metadata
Workflows Using fetch-depth: 1000
- Linux CI (
.github/workflows/linux-ci.yml): All build and test jobs - Windows CI (
.github/workflows/windows-ci.yml): All build and test jobs - macOS CI (
.github/workflows/macos-ci.yml): All build and test jobs
Sync-PSTags Operation
What is Sync-PSTags?
Sync-PSTags is a PowerShell function defined in build.psm1 that ensures Git tags from the upstream PowerShell repository are synchronized to the local clone.
Location
- Function Definition:
build.psm1(line 36-76) - Called From:
.github/actions/build/ci/action.yml(Bootstrap step, line 24)tools/ci.psm1(Invoke-CIInstall function, line 146)
How It Works
Sync-PSTags -AddRemoteIfMissing
The function:
Searches for a Git remote pointing to the official PowerShell repository:
https://github.com/PowerShell/PowerShellgit@github.com:PowerShell/PowerShell
If no upstream remote exists and
-AddRemoteIfMissingis specified:- Adds a remote named
upstreampointing tohttps://github.com/PowerShell/PowerShell.git
- Adds a remote named
Fetches all tags from the upstream remote:
git fetch --tags --quiet upstreamSets
$script:tagsUpToDate = $trueto indicate tags are synchronized
Why Sync-PSTags is Required
Tags are critical for:
- Version Calculation:
Get-PSVersionusesgit describe --abbrev=0to find the latest tag - Build Numbering: CI builds use tag-based versioning for artifacts
- Changelog Generation: Release notes are generated based on tags
- Package Metadata: Package versions are derived from Git tags
Without synchronized tags:
- Version detection would fail or return incorrect versions
- Builds might have inconsistent version numbers
- The build process would error when trying to determine the version
Bootstrap Step in CI Action
The .github/actions/build/ci/action.yml includes this in the Bootstrap step:
- name: Bootstrap
if: success()
run: |-
Write-Verbose -Verbose "Running Bootstrap..."
Import-Module .\tools\ci.psm1
Invoke-CIInstall -SkipUser
Write-Verbose -Verbose "Start Sync-PSTags"
Sync-PSTags -AddRemoteIfMissing
Write-Verbose -Verbose "End Sync-PSTags"
shell: pwsh
Note: Sync-PSTags is called twice:
- Once by
Invoke-CIInstall(intools/ci.psm1) - Explicitly again in the Bootstrap step
This redundancy ensures tags are available even if the first call encounters issues.
Best Practices for Copilot Sessions
When working with the PowerShell CI system:
Always use
fetch-depth: 1000or greater when checking out code for build or test operationsUnderstand that
Sync-PSTagsrequires network access to fetch tags from the upstream repositoryDon't modify the fetch-depth without understanding the impact on version calculation
If adding new CI workflows, follow the existing pattern:
- Use
fetch-depth: 1000for build/test jobs - Call
Sync-PSTags -AddRemoteIfMissingduring bootstrap - Ensure the upstream remote is properly configured
- Use
For local development, developers should:
- Have the upstream remote configured
- Run
Sync-PSTags -AddRemoteIfMissingbefore building - Or use
Start-PSBuildwhich handles this automatically
Related Files
.github/actions/build/ci/action.yml- Main CI build action.github/workflows/linux-ci.yml- Linux CI workflow.github/workflows/windows-ci.yml- Windows CI workflow.github/workflows/macos-ci.yml- macOS CI workflowbuild.psm1- Contains Sync-PSTags function definitiontools/ci.psm1- CI-specific build functions that call Sync-PSTags
Summary
The PowerShell CI system depends on:
- Adequate Git history (fetch-depth: 1000) for version calculation
- Synchronized Git tags via
Sync-PSTagsfor accurate versioning - Upstream remote access to fetch official repository tags
These prerequisites ensure consistent, accurate build versioning across all CI platforms.