diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index c8958b07..023e2085 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -3,12 +3,3 @@ contact_links: - name: "IdLE Documentation" url: "https://blindzero.github.io/IdentityLifecycleEngine/" about: "Read the official Identity Lifecycle Engine documentation." - - name: "Report a bug" - url: "https://github.com/blindzero/IdentityLifecycleEngine/issues/new?template=bug_report.md" - about: "Create a bug report for Identity Lifecycle Engine." - - name: "Report a feature request" - url: "https://github.com/blindzero/IdentityLifecycleEngine/issues/new?template=feature_request.md" - about: "Create a feature request for Identity Lifecycle Engine." - - name: "Any other issue" - url: "https://github.com/blindzero/IdentityLifecycleEngine/issues/new?template=other.md" - about: "Create an issue for anything else regarding Identity Lifecycle Engine." diff --git a/.github/ISSUE_TEMPLATE/other.md b/.github/ISSUE_TEMPLATE/other.md index 41589346..299323b4 100644 --- a/.github/ISSUE_TEMPLATE/other.md +++ b/.github/ISSUE_TEMPLATE/other.md @@ -8,12 +8,10 @@ assignees: - blindzero --- ---- > ⚠️ Note — Please use the dedicated templates > > - Bug report: https://github.com/blindzero/IdentityLifecycleEngine/issues/new?template=bug_report.md > - Feature request: https://github.com/blindzero/IdentityLifecycleEngine/issues/new?template=feature_request.md ---- # Description diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from .github/PULL_REQUEST_TEMPLATE/pull_request_template.md rename to .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cd0e025..705d3857 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: os: [ubuntu-latest, windows-latest] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Run Pester shell: pwsh @@ -37,7 +37,7 @@ jobs: - name: Upload test results if: always() continue-on-error: true - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v6 with: name: test-results-${{ matrix.os }} path: artifacts/test-results.xml @@ -47,7 +47,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Install platyPS shell: pwsh @@ -98,7 +98,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Generate step reference shell: pwsh diff --git a/.github/workflows/issue-auto-assign.yml b/.github/workflows/issue-auto-assign.yml deleted file mode 100644 index 6a49bb04..00000000 --- a/.github/workflows/issue-auto-assign.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Auto label and assign new issues - -on: workflow_dispatch -jobs: - label_and_assign: - if: github.event.issue.user.login != 'blindzero' - runs-on: ubuntu-latest - permissions: - issues: write - - steps: - - name: Add label and assign issue - uses: actions/github-script@v7 - with: - script: | - const issueNumber = context.payload.issue.number; - const repo = context.repo.repo; - const owner = context.repo.owner; - - await github.rest.issues.addLabels({ - owner, - repo, - issue_number: issueNumber, - labels: ["new"] - }); - - await github.rest.issues.addAssignees({ - owner, - repo, - issue_number: issueNumber, - assignees: ["blindzero"] - }); diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b47c4556..6f98c9c7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,19 +23,23 @@ on: permissions: contents: write + actions: read jobs: release: name: Build artifact (and optionally publish release) runs-on: ubuntu-latest + outputs: + tag: ${{ steps.tag.outputs.value }} + is_prerelease: ${{ steps.semver.outputs.is_prerelease }} + is_stable: ${{ steps.semver.outputs.is_stable }} + steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - # Always checkout the workflow ref (branch/tag selected in the UI or the pushed tag ref). - # Never treat the "tag" input as a git ref. ref: ${{ github.ref }} - name: Show PowerShell version @@ -61,6 +65,116 @@ jobs: "value=$refName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 + - name: Classify tag (stable vs prerelease) + id: semver + shell: pwsh + run: | + $tag = '${{ steps.tag.outputs.value }}' + $isStable = $tag -match '^v\d+\.\d+\.\d+$' + $isPrerelease = $tag -match '^v\d+\.\d+\.\d+-[0-9A-Za-z][0-9A-Za-z\.\-]*$' + + "is_stable=$($isStable.ToString().ToLowerInvariant())" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 + "is_prerelease=$($isPrerelease.ToString().ToLowerInvariant())" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 + + - name: Require tag to point to main HEAD + if: ${{ startsWith(github.ref, 'refs/tags/v') }} + shell: pwsh + run: | + Set-StrictMode -Version Latest + $ErrorActionPreference = 'Stop' + + git fetch origin main --depth 1 | Out-Null + + $tagSha = (git rev-parse '${{ github.ref }}^{}').Trim() + $mainSha = (git rev-parse 'origin/main').Trim() + + if ($tagSha -ne $mainSha) { + throw "Tag does not point to origin/main HEAD. Tag SHA=$tagSha, main SHA=$mainSha" + } + + Write-Host "Tag points to origin/main HEAD ($mainSha)." + + - name: Require green CI on the target commit + if: ${{ inputs.publish_release == true || inputs.publish_psgallery == true || startsWith(github.ref, 'refs/tags/v') }} + shell: pwsh + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + Set-StrictMode -Version Latest + $ErrorActionPreference = 'Stop' + + $repo = '${{ github.repository }}' + $sha = '${{ github.sha }}' + + # NOTE: This must match the workflow filename for CI. + # In this repository it is: .github/workflows/ci.yml + $uri = "https://api.github.com/repos/$repo/actions/workflows/ci.yml/runs?per_page=100&head_sha=$sha" + + $headers = @{ + Authorization = "Bearer $env:GH_TOKEN" + Accept = "application/vnd.github+json" + "X-GitHub-Api-Version" = "2022-11-28" + } + + $resp = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers + $run = $resp.workflow_runs | Sort-Object run_number -Descending | Select-Object -First 1 + + if (-not $run) { + throw "No completed CI workflow run found for SHA $sha. If CI is currently running for this commit, wait for it to complete successfully on main before releasing." + } + + if ($run.status -ne 'completed' -or $run.conclusion -ne 'success') { + throw "CI is not green for SHA $sha. Status=$($run.status), Conclusion=$($run.conclusion)." + } + + Write-Host "CI is green for SHA $sha (run #$($run.run_number))." + + - name: Validate tag version matches module manifest version(s) + shell: pwsh + run: | + $tag = '${{ steps.tag.outputs.value }}' + + if ($tag -notmatch '^v(\d+\.\d+\.\d+)(?:-[0-9A-Za-z][0-9A-Za-z\.\-]*)?$') { + Write-Host "Tag '$tag' is not SemVer-like. Skipping module version validation." + exit 0 + } + + $expectedVersion = $Matches[1] + Write-Host "Expected module version from tag: $expectedVersion" + + $manifestPaths = @( + 'src/IdLE/IdLE.psd1', + 'src/IdLE.Core/IdLE.Core.psd1', + 'src/IdLE.Steps.Common/IdLE.Steps.Common.psd1', + 'src/IdLE.Provider.Mock/IdLE.Provider.Mock.psd1' + ) + + $mismatches = @() + + foreach ($path in $manifestPaths) { + if (-not (Test-Path -LiteralPath $path)) { + throw "Module manifest not found: $path" + } + + $data = Import-PowerShellDataFile -LiteralPath $path + $actualVersion = [string]$data.ModuleVersion + + if ($actualVersion -ne $expectedVersion) { + $mismatches += [pscustomobject]@{ + Path = $path + Expected = $expectedVersion + ModuleVersion = $actualVersion + } + } + } + + if ($mismatches.Count -gt 0) { + $mismatches | Format-Table -AutoSize | Out-String | Write-Host + throw "Tag '$tag' does not match module manifest version(s). Run the version bump before tagging." + } + + Write-Host "Manifest versions match tag version ($expectedVersion)." + - name: Build release artifact shell: pwsh run: | @@ -77,8 +191,6 @@ jobs: } Get-Item -LiteralPath $path | Format-List FullName, Length, LastWriteTimeUtc - # For manual dry-runs we upload expanded contents (folder) to avoid a ZIP-in-ZIP experience. - # For tag-triggered runs (or manual publish_release=true) we also upload the ZIP itself. - name: Expand artifact for dry-run upload if: ${{ inputs.publish_release != true && !startsWith(github.ref, 'refs/tags/v') }} shell: pwsh @@ -91,15 +203,16 @@ jobs: Remove-Item -LiteralPath $staging -Recurse -Force } - New-Item -Path $staging -ItemType Directory -Force | Out-Null - Expand-Archive -LiteralPath $zipPath -DestinationPath $staging -Force + New-Item -ItemType Directory -Path $staging -Force | Out-Null + Expand-Archive -Path $zipPath -DestinationPath $staging -Force + Get-ChildItem -LiteralPath $staging -Recurse | Select-Object FullName | Format-List - - name: Upload workflow artifact (dry run - expanded) + - name: Upload workflow artifact (expanded folder) if: ${{ inputs.publish_release != true && !startsWith(github.ref, 'refs/tags/v') }} uses: actions/upload-artifact@v4 with: - name: IdLE-${{ steps.tag.outputs.value }} - path: artifacts/staging-${{ steps.tag.outputs.value }}/ + name: IdLE-${{ steps.tag.outputs.value }}-expanded + path: artifacts/staging-${{ steps.tag.outputs.value }} if-no-files-found: error - name: Upload workflow artifact (zip) @@ -117,21 +230,81 @@ jobs: tag_name: ${{ steps.tag.outputs.value }} name: ${{ steps.tag.outputs.value }} generate_release_notes: true + prerelease: ${{ steps.semver.outputs.is_prerelease == 'true' }} files: | artifacts/IdLE-${{ steps.tag.outputs.value }}.zip + psgallery_local_test: + name: Test module publish (local repository) + runs-on: ubuntu-latest + needs: release + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.ref }} + + - name: Show PowerShell version + shell: pwsh + run: | + $PSVersionTable.PSVersion + pwsh -v + + - name: Install PowerShellGet + shell: pwsh + run: | + Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted + Install-Module -Name PowerShellGet -Scope CurrentUser -Force -AllowClobber + Import-Module PowerShellGet -Force + Get-Module PowerShellGet | Select-Object Name, Version, Path | Format-List + + - name: Build publishable module package + shell: pwsh + run: | + ./tools/New-IdleModulePackage.ps1 -Clean | Format-List FullName + + - name: Publish module to local PSRepository and verify install/import + shell: pwsh + run: | + $modulePath = Join-Path $env:GITHUB_WORKSPACE 'artifacts/IdLE' + if (-not (Test-Path -LiteralPath $modulePath)) { + throw "Staged module path not found: $modulePath" + } + + $repoPath = Join-Path $env:RUNNER_TEMP 'psrepo' + New-Item -ItemType Directory -Path $repoPath -Force | Out-Null + + Register-PSRepository -Name 'LocalRepo' -SourceLocation $repoPath -PublishLocation $repoPath -InstallationPolicy Trusted + + Publish-Module -Path $modulePath -Repository 'LocalRepo' -ErrorAction Stop + + $published = Find-Module -Name 'IdLE' -Repository 'LocalRepo' -ErrorAction Stop + Write-Host "Published to LocalRepo: $($published.Name) $($published.Version)" + + Install-Module -Name 'IdLE' -Repository 'LocalRepo' -Scope CurrentUser -Force -AllowClobber -ErrorAction Stop + Import-Module IdLE -Force -ErrorAction Stop + + $m = Get-Module IdLE + if (-not $m) { throw 'IdLE did not import successfully.' } + Write-Host "Imported IdLE: $($m.Name) $($m.Version)" + + Unregister-PSRepository -Name 'LocalRepo' -ErrorAction SilentlyContinue + psgallery: name: Publish to PowerShell Gallery runs-on: ubuntu-latest - needs: release + needs: [release, psgallery_local_test] + environment: psgallery-prod - # Safety: - # - Auto-publish only on real tag pushes (v*). - # - Allow manual publish only when explicitly requested via workflow_dispatch + publish_psgallery=true. if: >- ${{ - startsWith(github.ref, 'refs/tags/v') - || (github.event_name == 'workflow_dispatch' && inputs.publish_psgallery == true) + needs.release.outputs.is_stable == 'true' + && ( + startsWith(github.ref, 'refs/tags/v') + || (github.event_name == 'workflow_dispatch' && inputs.publish_psgallery == true && inputs.tag != '') + ) }} steps: diff --git a/docs/advanced/releases.md b/docs/advanced/releases.md index 57e48951..e69c2c0b 100644 --- a/docs/advanced/releases.md +++ b/docs/advanced/releases.md @@ -1,79 +1,145 @@ # Releasing IdLE -This document describes how maintainers cut a release using the GitHub Actions workflow. +This document describes the **maintainer** release process for IdLE. -> This is part of the **advanced** documentation because it is maintainer-focused and describes repository -> operations (tags, GitHub Releases, release artifacts) rather than end-user usage. +IdLE currently ships release artifacts in two channels: -## Prerequisites +- **GitHub Releases** (always) +- **PowerShell Gallery** (stable releases only, guarded by environment approval) -- You have write permissions to the repository. -- CI is green on `main`. -- The repository uses **immutable releases** (recommended). Once a release is published, its assets and tag should be treated as write-once. +Pre-release tags are **GitHub-only** (no PowerShell Gallery publish). + +## Principles and guardrails + +- **No direct commits to `main`.** Release prep is done via a Pull Request. +- Tags must be created on the intended `main` commit. +- The Release workflow validates that the tag version matches the module manifest versions (fail-fast). +- Publishing to PowerShell Gallery is protected via a GitHub **Environment** (`psgallery-prod`) and requires approval. +- A local end-to-end publish test runs in CI (publishes to a local repository, then installs/imports the module). + +## Release workflow safety gates + +The Release workflow enforces additional guardrails for tagged releases: + +- **Tag must point to `origin/main` HEAD** (fail-fast). +- **CI must be green for the tag commit** (`ci.yml` must have a successful run for the same SHA). +- **Tag base version must match all shipped module manifests**. + +These checks prevent "broken" releases (e.g., tagging the wrong commit or forgetting the version bump). + +## Versioning policy + +### Stable tags + +Stable releases use tags in the form: + +- `vMAJOR.MINOR.PATCH` (example: `v1.2.0`) + +For stable releases, all shipped module manifests must have: + +- `ModuleVersion = MAJOR.MINOR.PATCH` + +### Pre-release tags (GitHub only) + +Pre-releases use tags in the form: + +- `vMAJOR.MINOR.PATCH-