diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..98ff85f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,131 @@ +name: PowerShell module validation + +on: + push: + branches: [master, '**/develop', '**/release/**', 'fix/**', 'ci/**'] + pull_request: + branches: [master, '**/develop', '**/release/**'] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + plan: + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + matrix: ${{ steps.select.outputs.matrix }} + steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + fetch-depth: 0 + - name: Test CI automation offline + shell: pwsh + run: | + ./tests/Test-CiSelection.ps1 + ./tests/Test-CiSources.ps1 + ./tests/Test-CiRunner.ps1 + ./tests/Test-CiStructure.ps1 + ./tests/Test-ReleaseSelection.ps1 + ./tests/Test-GalleryAutomation.ps1 + ./tests/Test-GalleryKeySetup.ps1 + ./tests/Test-ReleaseOutput.ps1 + ./tests/Test-ReleaseEvidence.ps1 + ./tests/Test-GalleryVerification.ps1 + node ./tests/Test-IssueCompletion.cjs + if ($LASTEXITCODE -ne 0) { throw 'Issue completion tests failed' } + node ./tests/Test-WorkflowSafety.cjs + if ($LASTEXITCODE -ne 0) { throw 'Workflow safety tests failed' } + node ./tests/Test-ReleaseCreation.cjs + if ($LASTEXITCODE -ne 0) { throw 'Release creation tests failed' } + - id: select + name: Select modules and immutable source snapshots + shell: pwsh + env: + TARGET_BRANCH: ${{ github.base_ref || github.ref_name }} + CURRENT_SHA: ${{ github.sha }} + PR_BASE: ${{ github.event.pull_request.base.sha }} + PUSH_BASE: ${{ github.event.before }} + REF_NAME: ${{ github.ref_name }} + run: | + $checkedOut = git rev-parse HEAD + if ($LASTEXITCODE -ne 0 -or $checkedOut -cne $env:CURRENT_SHA) { throw 'Automation checkout does not match workflow commit' } + $baseCandidate = if ($env:PR_BASE) { $env:PR_BASE } elseif ($env:REF_NAME -eq 'master' -and $env:PUSH_BASE -match '^[0-9a-f]{40}$' -and $env:PUSH_BASE -ne ('0' * 40)) { $env:PUSH_BASE } else { 'origin/master' } + $base = git merge-base HEAD $baseCandidate + if ($LASTEXITCODE -ne 0) { throw 'Cannot determine source comparison base' } + $changed = @(git diff --name-only -z $base HEAD) + if ($LASTEXITCODE -ne 0) { throw 'Cannot inspect source changes' } + $paths = @((($changed -join "`n").Split([char]0, [StringSplitOptions]::RemoveEmptyEntries))) + $remote = @(git ls-remote origin 'refs/heads/*') + if ($LASTEXITCODE -ne 0) { throw 'Cannot resolve maintained module refs' } + $refs = @{} + foreach ($line in $remote) { + if ($line -match '^([0-9a-f]{40})\s+refs/heads/(.+)$') { $refs[$Matches[2]] = $Matches[1] } + } + $json = ./scripts/ci/Resolve-CiSources.ps1 -Branch $env:TARGET_BRANCH -CurrentSha $env:CURRENT_SHA -RemoteRefs $refs -ChangedPaths $paths + 'Module | Source ref | Commit | Mode' >> $env:GITHUB_STEP_SUMMARY + '--- | --- | --- | ---' >> $env:GITHUB_STEP_SUMMARY + foreach ($entry in (($json | ConvertFrom-Json).include | Sort-Object module -Unique)) { + "$($entry.module) | $($entry.source_ref) | $($entry.source_sha) | $($entry.source_mode)" >> $env:GITHUB_STEP_SUMMARY + } + + test: + needs: plan + name: ${{ matrix.module }} / ${{ matrix.os }} + runs-on: ${{ matrix.os }} + timeout-minutes: 15 + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.plan.outputs.matrix) }} + steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: Check out the exact module source + uses: actions/checkout@v7.0.1 + with: + ref: ${{ matrix.source_sha }} + path: module-source + persist-credentials: false + - name: Test release snapshot selection on Windows + if: ${{ matrix.module == 'Base64String' && matrix.os == 'windows-latest' }} + shell: pwsh + run: ./tests/Test-ReleaseSelection.ps1 + - name: Run module checks + shell: pwsh + env: + MODULE: ${{ matrix.module }} + SOURCE_SHA: ${{ matrix.source_sha }} + SOURCE_REF: ${{ matrix.source_ref }} + SOURCE_MODE: ${{ matrix.source_mode }} + AUTOMATION_SHA: ${{ github.sha }} + run: | + New-Item ./module-source/TestResults -ItemType Directory -Force | Out-Null + @{module=$env:MODULE; sourceSha=$env:SOURCE_SHA; sourceRef=$env:SOURCE_REF; sourceMode=$env:SOURCE_MODE; automationSha=$env:AUTOMATION_SHA} | ConvertTo-Json | Set-Content ./module-source/TestResults/source-identity.json + ./scripts/ci/Invoke-ModuleTests.ps1 -Module $env:MODULE -SourceRoot ./module-source + - name: Upload test results + if: always() + uses: actions/upload-artifact@v7.0.2 + with: + name: tests-${{ matrix.module }}-${{ matrix.os }} + path: module-source/TestResults/ + if-no-files-found: ignore + + status: + name: CI status + if: always() + needs: [plan, test] + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Require successful planning and module checks + env: + PLAN_RESULT: ${{ needs.plan.result }} + TEST_RESULT: ${{ needs.test.result }} + run: test "$PLAN_RESULT" = success && test "$TEST_RESULT" = success diff --git a/.github/workflows/release-gallery.yml b/.github/workflows/release-gallery.yml new file mode 100644 index 0000000..815958d --- /dev/null +++ b/.github/workflows/release-gallery.yml @@ -0,0 +1,263 @@ +name: Tested release and protected Gallery deployment +on: + workflow_dispatch: + inputs: + module: + description: Module to release + type: choice + required: true + options: [Bookmarks, 7zip-Archive, Currency-Conv, Base64String, Pipe] + version: + description: Prepared version number (for example, 1.3.0) + type: string + required: true + create_release: + description: Also create the GitHub release during a dry-run + type: boolean + default: false + dry_run: + description: Validate only; uncheck to publish to PowerShell Gallery + type: boolean + default: true +permissions: + contents: read +concurrency: + group: release-gallery-${{ inputs.module }} + cancel-in-progress: false +jobs: + package: + runs-on: windows-latest + timeout-minutes: 20 + outputs: + source_sha: ${{ steps.snapshot.outputs.sha }} + steps: + - uses: actions/checkout@v7.0.1 + with: + path: automation + persist-credentials: false + - name: Validate request + shell: pwsh + env: + VERSION: ${{ inputs.version }} + MUTATE: ${{ inputs.create_release || !inputs.dry_run }} + REF: ${{ github.ref }} + run: | + if ($env:VERSION -notmatch '^\d+\.\d+\.\d+(\.\d+)?$') { throw 'Stable version required' } + if ($env:MUTATE -eq 'true' -and $env:REF -ne 'refs/heads/master') { throw 'Mutations require master' } + - name: Resolve the selected module's reviewed release snapshot + id: snapshot + shell: pwsh + env: + MODULE: ${{ inputs.module }} + VERSION: ${{ inputs.version }} + run: ./automation/scripts/gallery/Resolve-ReleaseSnapshot.ps1 -Module $env:MODULE -Version $env:VERSION -RepositoryRoot ./automation + - uses: actions/checkout@v7.0.1 + with: + ref: ${{ steps.snapshot.outputs.sha }} + path: source + fetch-depth: 0 + persist-credentials: false + - name: Require configured release ancestry and matching source/package + shell: pwsh + env: + MODULE: ${{ inputs.module }} + SHA: ${{ steps.snapshot.outputs.sha }} + VERSION: ${{ inputs.version }} + run: | + $config = ./automation/scripts/gallery/Get-ReleaseConfig.ps1 -Module $env:MODULE + git -C source merge-base --is-ancestor $env:SHA "origin/$($config.ReleaseBranch)" + if ($LASTEXITCODE -ne 0) { throw 'Snapshot is not on the configured release branch' } + ./automation/scripts/gallery/Build-GalleryPackage.ps1 -Module $env:MODULE -SourceRoot ./source -OutputRoot ./stage -ExpectedVersion $env:VERSION + ./automation/scripts/gallery/Assert-SourcePackage.ps1 -Module $env:MODULE -SourceRoot ./source -PackageRoot ./stage + ./automation/scripts/gallery/Package-Evidence.ps1 -Module $env:MODULE -Version $env:VERSION -SourceSha $env:SHA -PackageRoot ./stage -EvidencePath ./stage/evidence.json + ./automation/scripts/gallery/New-ReleaseOutput.ps1 -Module $env:MODULE -SourceRoot ./source -OutputRoot ./generated -ExpectedVersion $env:VERSION + ./automation/scripts/gallery/Build-GalleryPackage.ps1 -Module $env:MODULE -SourceRoot ./generated -OutputRoot ./reproduced -ExpectedVersion $env:VERSION + ./automation/scripts/gallery/Package-Evidence.ps1 -Module $env:MODULE -Version $env:VERSION -SourceSha $env:SHA -PackageRoot ./reproduced -EvidencePath ./stage/evidence.json -Verify + - uses: actions/upload-artifact@v7.0.2 + with: + name: gallery-package + path: stage/ + if-no-files-found: error + + test: + needs: package + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + shell: pwsh + - os: windows-latest + shell: powershell + - os: ubuntu-latest + shell: pwsh + - os: macos-latest + shell: pwsh + runs-on: ${{ matrix.os }} + timeout-minutes: 25 + steps: + - uses: actions/checkout@v7.0.1 + with: + path: automation + persist-credentials: false + - uses: actions/checkout@v7.0.1 + with: + ref: ${{ needs.package.outputs.source_sha }} + path: source + persist-credentials: false + - uses: actions/download-artifact@v8.0.2 + with: + name: gallery-package + path: stage + - name: Test source and installed package + if: ${{ matrix.shell == 'pwsh' && (inputs.module != '7zip-Archive' || matrix.os == 'windows-latest') }} + shell: pwsh + env: + MODULE: ${{ inputs.module }} + VERSION: ${{ inputs.version }} + SHA: ${{ needs.package.outputs.source_sha }} + run: | + ./automation/scripts/gallery/Package-Evidence.ps1 -Module $env:MODULE -Version $env:VERSION -SourceSha $env:SHA -PackageRoot ./stage -EvidencePath ./stage/evidence.json -Verify + ./automation/scripts/gallery/Test-ReleasePackage.ps1 -Module $env:MODULE -SourceRoot ./source -PackageRoot ./stage -ExpectedVersion $env:VERSION + - name: Test source and installed package on Windows PowerShell 5.1 + if: ${{ matrix.shell == 'powershell' }} + shell: powershell + env: + MODULE: ${{ inputs.module }} + VERSION: ${{ inputs.version }} + SHA: ${{ needs.package.outputs.source_sha }} + run: | + ./automation/scripts/gallery/Package-Evidence.ps1 -Module $env:MODULE -Version $env:VERSION -SourceSha $env:SHA -PackageRoot ./stage -EvidencePath ./stage/evidence.json -Verify + ./automation/scripts/gallery/Test-ReleasePackage.ps1 -Module $env:MODULE -SourceRoot ./source -PackageRoot ./stage -ExpectedVersion $env:VERSION + - uses: actions/upload-artifact@v7.0.2 + if: always() + with: + name: release-tests-${{ matrix.os }}-${{ matrix.shell }} + path: source/TestResults/*.xml + if-no-files-found: ignore + + release: + needs: [package, test] + if: ${{ github.ref == 'refs/heads/master' && (inputs.create_release || !inputs.dry_run) }} + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write + steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - uses: actions/download-artifact@v8.0.2 + with: + name: gallery-package + path: stage + - name: Create immutable version release or verify existing release + env: + GH_TOKEN: ${{ github.token }} + MODULE: ${{ inputs.module }} + VERSION: ${{ inputs.version }} + SHA: ${{ needs.package.outputs.source_sha }} + run: node scripts/gallery/Create-Release.cjs + + publish: + needs: [package, test, release] + if: ${{ !inputs.dry_run && github.ref == 'refs/heads/master' }} + runs-on: windows-latest + timeout-minutes: 15 + environment: powershell-gallery + outputs: + published: ${{ steps.upload.outputs.published }} + steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - uses: actions/download-artifact@v8.0.2 + with: + name: gallery-package + path: stage + - name: Select configured Gallery account (no credentials) + id: account + shell: pwsh + env: + MODULE: ${{ inputs.module }} + run: | + $config = ./scripts/gallery/Get-ReleaseConfig.ps1 -Module $env:MODULE + "name=$($config.GalleryAccount)" >> $env:GITHUB_OUTPUT + "secret=$($config.GallerySecret)" >> $env:GITHUB_OUTPUT + "Gallery route: $env:MODULE -> $($config.GalleryAccount) ($($config.GallerySecret))" >> $env:GITHUB_STEP_SUMMARY + - name: Publish tested package + id: upload + shell: pwsh + env: + PSGALLERY_API_KEY: ${{ secrets[steps.account.outputs.secret] }} + PSGALLERY_ACCOUNT: ${{ steps.account.outputs.name }} + MODULE: ${{ inputs.module }} + VERSION: ${{ inputs.version }} + SOURCE_SHA: ${{ needs.package.outputs.source_sha }} + run: | + ./scripts/gallery/Package-Evidence.ps1 -Module $env:MODULE -Version $env:VERSION -SourceSha $env:SOURCE_SHA -PackageRoot ./stage -EvidencePath ./stage/evidence.json -Verify + ./scripts/gallery/Publish-GalleryPackage.ps1 -Module $env:MODULE -PackageRoot ./stage -ExpectedVersion $env:VERSION + 'published=true' >> $env:GITHUB_OUTPUT + + verify: + needs: [package, publish] + if: ${{ !inputs.dry_run && needs.publish.result == 'success' && needs.publish.outputs.published == 'true' }} + runs-on: windows-latest + timeout-minutes: 20 + outputs: + verified: ${{ steps.verify.outputs.verified }} + steps: + - uses: actions/checkout@v7.0.1 + with: + path: automation + persist-credentials: false + - uses: actions/checkout@v7.0.1 + with: + ref: ${{ needs.package.outputs.source_sha }} + path: source + persist-credentials: false + - uses: actions/download-artifact@v8.0.2 + with: + name: gallery-package + path: stage + - name: Verify exact Gallery bytes and installed behavior without credentials + id: verify + shell: pwsh + env: + MODULE: ${{ inputs.module }} + VERSION: ${{ inputs.version }} + SHA: ${{ needs.package.outputs.source_sha }} + run: | + ./automation/scripts/gallery/Verify-GalleryPackage.ps1 -Module $env:MODULE -Version $env:VERSION -SourceSha $env:SHA -SourceRoot ./source -EvidencePath ./stage/evidence.json -OutputRoot ./download + Copy-Item ./stage/evidence.json ./verified.json + 'verified=true' >> $env:GITHUB_OUTPUT + - uses: actions/upload-artifact@v7.0.2 + with: + name: gallery-verification + path: verified.json + if-no-files-found: error + + complete-issues: + needs: [package, publish, verify] + if: ${{ !inputs.dry_run && github.ref == 'refs/heads/master' && needs.publish.result == 'success' && needs.publish.outputs.published == 'true' && needs.verify.result == 'success' && needs.verify.outputs.verified == 'true' }} + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + issues: write + steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - uses: actions/github-script@v8 + env: + MODULE: ${{ inputs.module }} + VERSION: ${{ inputs.version }} + SHA: ${{ needs.package.outputs.source_sha }} + with: + script: | + const {complete} = require('./scripts/gallery/Complete-Issues.cjs'); + await complete({github, context, + mapping: require('./scripts/gallery/issue-map.json'), + identity: {repository: process.env.GITHUB_REPOSITORY, module: process.env.MODULE, + version: process.env.VERSION, sourceSha: process.env.SHA}}); diff --git a/.github/workflows/validate-module-source.yml b/.github/workflows/validate-module-source.yml new file mode 100644 index 0000000..6f00b75 --- /dev/null +++ b/.github/workflows/validate-module-source.yml @@ -0,0 +1,52 @@ +name: Read-only module source validation +on: + workflow_call: + inputs: + module: + required: true + type: string + source_sha: + required: true + type: string + automation_sha: + required: true + type: string +permissions: + contents: read +jobs: + test: + runs-on: ${{ matrix.os }} + timeout-minutes: 15 + strategy: + fail-fast: false + matrix: + os: ${{ fromJSON(inputs.module == '7zip-Archive' && '["windows-latest"]' || '["windows-latest","ubuntu-latest","macos-latest"]') }} + steps: + - uses: actions/checkout@v7.0.1 + with: + ref: ${{ inputs.automation_sha }} + path: automation + persist-credentials: false + - name: Require exact commits + shell: pwsh + env: + SOURCE_SHA: ${{ inputs.source_sha }} + AUTOMATION_SHA: ${{ inputs.automation_sha }} + run: | + if ($env:SOURCE_SHA -cnotmatch '^[0-9a-f]{40}$' -or $env:AUTOMATION_SHA -cnotmatch '^[0-9a-f]{40}$') { throw 'Full commit SHAs required' } + - uses: actions/checkout@v7.0.1 + with: + ref: ${{ inputs.source_sha }} + path: source + persist-credentials: false + - name: Test the actual module source snapshot + shell: pwsh + env: + MODULE: ${{ inputs.module }} + run: ./automation/scripts/ci/Invoke-ModuleTests.ps1 -Module $env:MODULE -SourceRoot ./source + - uses: actions/upload-artifact@v7.0.2 + if: always() + with: + name: source-${{ inputs.module }}-${{ matrix.os }} + path: source/TestResults/*.xml + if-no-files-found: ignore diff --git a/.github/workflows/validate-release-candidate.yml b/.github/workflows/validate-release-candidate.yml new file mode 100644 index 0000000..c53611a --- /dev/null +++ b/.github/workflows/validate-release-candidate.yml @@ -0,0 +1,98 @@ +name: Read-only release candidate validation +on: + workflow_call: + inputs: + module: + required: true + type: string + version: + required: true + type: string + source_sha: + required: true + type: string + require_committed_package: + type: boolean + default: true + automation_sha: + required: true + type: string +permissions: + contents: read +jobs: + validate: + runs-on: ${{ matrix.os }} + timeout-minutes: 25 + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + shell: pwsh + - os: windows-latest + shell: powershell + - os: ubuntu-latest + shell: pwsh + - os: macos-latest + shell: pwsh + steps: + - uses: actions/checkout@v7.0.1 + with: + ref: ${{ inputs.automation_sha }} + path: automation + persist-credentials: false + - name: Require immutable validation inputs + shell: pwsh + env: + SOURCE_SHA: ${{ inputs.source_sha }} + AUTOMATION_SHA: ${{ inputs.automation_sha }} + MODULE: ${{ inputs.module }} + VERSION: ${{ inputs.version }} + run: | + if ($env:SOURCE_SHA -cnotmatch '^[0-9a-f]{40}$' -or $env:AUTOMATION_SHA -cnotmatch '^[0-9a-f]{40}$') { throw 'Full commit SHAs required' } + if ($env:VERSION -notmatch '^\d+\.\d+\.\d+(\.\d+)?$') { throw 'Stable version required' } + ./automation/scripts/gallery/Get-ReleaseConfig.ps1 -Module $env:MODULE | Out-Null + - uses: actions/checkout@v7.0.1 + with: + ref: ${{ inputs.source_sha }} + path: source + persist-credentials: false + - name: Reproduce committed package and record hashes + shell: pwsh + env: + MODULE: ${{ inputs.module }} + VERSION: ${{ inputs.version }} + SHA: ${{ inputs.source_sha }} + REQUIRE_PACKAGE: ${{ inputs.require_committed_package }} + run: | + if ($env:REQUIRE_PACKAGE -eq 'true') { + ./automation/scripts/gallery/Build-GalleryPackage.ps1 -Module $env:MODULE -SourceRoot ./source -OutputRoot ./stage -ExpectedVersion $env:VERSION + ./automation/scripts/gallery/Assert-SourcePackage.ps1 -Module $env:MODULE -SourceRoot ./source -PackageRoot ./stage + } + ./automation/scripts/gallery/New-ReleaseOutput.ps1 -Module $env:MODULE -SourceRoot ./source -OutputRoot ./generated -ExpectedVersion $env:VERSION + ./automation/scripts/gallery/Build-GalleryPackage.ps1 -Module $env:MODULE -SourceRoot ./generated -OutputRoot ./reproduced -ExpectedVersion $env:VERSION + if ($env:REQUIRE_PACKAGE -ne 'true') { Copy-Item ./reproduced ./stage -Recurse } + ./automation/scripts/gallery/Package-Evidence.ps1 -Module $env:MODULE -Version $env:VERSION -SourceSha $env:SHA -PackageRoot ./stage -EvidencePath ./stage/evidence.json + ./automation/scripts/gallery/Package-Evidence.ps1 -Module $env:MODULE -Version $env:VERSION -SourceSha $env:SHA -PackageRoot ./reproduced -EvidencePath ./stage/evidence.json -Verify + - name: Test source and installed candidate + if: ${{ matrix.shell == 'pwsh' && (inputs.module != '7zip-Archive' || matrix.os == 'windows-latest') }} + shell: pwsh + env: + MODULE: ${{ inputs.module }} + VERSION: ${{ inputs.version }} + run: ./automation/scripts/gallery/Test-ReleasePackage.ps1 -Module $env:MODULE -SourceRoot ./source -PackageRoot ./stage -ExpectedVersion $env:VERSION + - name: Test source and installed candidate on Windows PowerShell 5.1 + if: ${{ matrix.shell == 'powershell' }} + shell: powershell + env: + MODULE: ${{ inputs.module }} + VERSION: ${{ inputs.version }} + run: ./automation/scripts/gallery/Test-ReleasePackage.ps1 -Module $env:MODULE -SourceRoot ./source -PackageRoot ./stage -ExpectedVersion $env:VERSION + - uses: actions/upload-artifact@v7.0.2 + if: always() + with: + name: candidate-${{ matrix.os }}-${{ matrix.shell }} + path: | + stage/ + source/TestResults/*.xml + if-no-files-found: ignore diff --git a/.gitignore b/.gitignore index 931f30c..e4d962c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # File types to ignore globally .history .vscode +TestResults/ diff --git a/7Zip/README.md b/7Zip/README.md index ede9c64..3123c9d 100644 --- a/7Zip/README.md +++ b/7Zip/README.md @@ -1,7 +1,6 @@ # 7zip-Archive - 7zip archiver ps1 wrapper -[![PowerShell 3](https://dev.azure.com/Stadub-Gh/PowershellScripts/_apis/build/status/7Zip?branchName=master)](https://dev.azure.com/Stadub-Gh/PowershellScripts/_build/latest?definitionId=4&branchName=master) [![latest version](https://img.shields.io/powershellgallery/v/7zip-Archive.svg?label=latest+version)](https://www.powershellgallery.com/packages/7zip-Archive) [![downloads](https://img.shields.io/powershellgallery/dt/7zip-Archive.svg?label=downloads)](https://www.powershellgallery.com/packages/7zip-Archive) diff --git a/7Zip/azure-pipelines.yml b/7Zip/azure-pipelines.yml deleted file mode 100644 index d16c686..0000000 --- a/7Zip/azure-pipelines.yml +++ /dev/null @@ -1,27 +0,0 @@ -trigger: - - master -pr: - - master - -resources: - - repo: self - clean: true - fetchDepth: 1 - -jobs: - - job: szip - displayName: 7zip - continueOnError: false - pool: - vmImage: 'windows-2019' - workspace: - clean: all - timeoutInMinutes: 3 - steps: - - powershell: | - $global:PesterDebugPreference_ShowFullErrors = $true - $errorActionPreference = 'stop' - Set-StrictMode -Version Latest - Install-Module -Name Pester -Force - Import-Module Pester - . .\7zip\7Zip-Archive.Tests.ps1 \ No newline at end of file diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..bde6b4d --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,298 @@ +# Project instructions + +## Review component branches before choosing a worktree base + +This repository is a PowerShell monorepo with eleven functional components: eight +modules, a script tool, a script bundle, and shared infrastructure. Components have +development branches; packaged modules may also have release branches. Do not +assume `master` contains every module fix or that release branches contain only +generated files. + +Before starting component work: + +1. Check the working tree and live remote branch tips. Refresh remote refs when + needed before comparing them. +2. Compare the module's source, manifests, tests, and release `out/` directory with + `master`. Commit ancestry alone is insufficient: packaged files can contain + functional changes absent from source. +3. Review relevant GitHub issues, pull requests, and visible coding-agent tasks to + avoid duplicating work. Check existing Orca worktrees and agents as well. +4. Choose the base using the module-specific guidance below, after verifying it + still applies. Use the Orca CLI skill for Orca-managed worktrees. +5. Keep release artifacts out of source merges unless the task explicitly calls + for them. Recover individual fixes selectively rather than merging an entire + old release branch. + +## Branch map and review baseline + +Reviewed on 2026-11-11. Live remote tips matched the local remote-tracking refs; +`master` was `b3968f6`. These are historical findings, not substitutes for checking +the current remote state. + +| Component / classification / source | Development / feature PR target | Reviewed release source | Findings | +| --- | --- | --- | --- | +| 7Zip — manifest module (`7Zip/7zip-Archive.psd1`, Gallery: 7zip-Archive) | `7Zip/develop` | `7-Zip/release/1.1`; historical `7Zip/release/1.0` | Development recreated from release 1.1; module source matches reviewed master. | +| Bookmarks — manifest module (`Bookmarks/Bookmarks.psd1`) | `Bookmarks/develop` | `Bookmarks/release/latest`; historical `Bookmarks/release/v2.1` | Development source matches master 2.2.0; release output has different shared helpers. | +| Currency-Conv — manifest module (`Currency-Conv/Currency-Conv.psd1`) | `Currency-Conv/develop` | `Currency-Conv/release/1.5`; historical `Currency-Conv/release/1.0` | Development recreated from release 1.5; source matches reviewed master. | +| Pipe — manifest module (`Shared-Functions/Pipe/Pipe.psd1`) | `Pipe/develop` | `Pipe/release/latest` | Release output has functional packaging/alias changes absent from source. | +| Base64String — manifest module (`Shared-Functions/Base64String/Base64String.psd1`) | `base64tring/develop` | `base64String/release/latest` | Both retain 1.2.0 decoder changes absent from master; preserve the actual spelling `base64tring`. | +| FolderEncoder — manifest module (`FolderEncoder/FolderEncoder.psd1`) | `FolderEncoder/develop` | None; publication not configured | New development branch from master `b3968f6`; no module-specific release ref. | +| Shell-Functions — manifest module (`Shell-Functions/Shell-Function.psd1`) | `Shell-Functions/develop` | None; publication not configured | New development branch from master `b3968f6`; no module-specific release ref. | +| Uninstall — standalone module (`Uninstall.psm1`, standalone root module) | `Uninstall/develop` | None; publication not configured | New development branch from master `b3968f6`; no module-specific release ref. | +| EXportGithub — script tool (`EXportGithub/EXportGithub.ps1`) | `EXportGithub/develop` | None; publication not configured | New development branch from master `b3968f6`; historical manifest removed in `01697f7`. | +| Git-Functions — script bundle (`Git-Functions/Git-Function.ps1`, `Git-Alias.ps1`) | `Git-Functions/develop` | None; publication not configured | New development branch from master `b3968f6`; plain scripts and aliases. | +| Shared-Functions — shared infrastructure (`Shared-Functions/Shared-Functions.ps1`, `ModuleLoader.ps1`) | `Shared-Functions/develop` | None; publication not configured | New development branch from master `b3968f6`; excludes the independently managed Base64String and Pipe modules. | + +The eleven-component inventory includes eight formal modules and three script or +infrastructure components, excluding `out/` package duplicates. The latter three +have development branches for source work without claiming packaged-module status. +Root `install.ps1` and `App-Alias.ps1` are setup/configuration helpers maintained +with repository-wide work on master; they have no separate component branches. +Historical CurrencyConv, EncodeVia7z, Bookmarks.ps1, 7zip.psd1, and +Shell-Function.psd1 names are predecessors, not additional independent components. +EXportGithub's deleted manifest is historical; branch setup does not restore it. +Shared infrastructure changes require separate reviewed ports to module helper +copies; do not merge whole component branches to distribute helpers. + +Shell-Functions is a manifest module +whose current manifest loads no implementation and exports no commands; +FolderEncoder's manifest references a missing `Functions.ps1`. These existing +limitations were found by static inspection, not fixed or runtime-tested here. +Uninstall exports `Uninstall-Application` and uses Windows registry/msiexec APIs. + +FolderEncoder, Shell-Functions, and Uninstall were newly branched from the latest +integrated master source (`b3968f6`) on 2026-11-11, not recovered deleted tips. +Their module histories and all live release refs were reviewed; no newer +module-specific source or release package was found. Source files are unchanged. + +EXportGithub, Git-Functions, and Shared-Functions were newly branched from master +`b3968f6` on 2026-11-11 after reviewing reachable history and live branch contents. +No distinct newer source or component release branch was found for these paths. +All eleven development tips carry the same inventory instructions; this follow-up +changes only AGENTS.md on those branches and preserves existing module baselines. + +The release policy for configured packaged modules is: feature/issue PR -> +module development branch -> reviewed release snapshot/package -> PowerShell Gallery. Selectively port reviewed +module changes to the established release source, including version/release notes +and package validation; never publish directly from a feature/development branch. +For components without a release branch, establish and review packaging separately +before configuring publication; do not invent release refs or deploy entries. + +CI now covers all eight formal modules: Bookmarks, 7zip-Archive, Currency-Conv, +Base64String, Pipe, FolderEncoder, Shell-Functions, and Uninstall. The user explicitly +authorized this expansion after the independent release-pipeline handoff. The three +new entries run syntax, manifest (where present), import and export checks, and +source Pester suites when available. Do not hide current FolderEncoder missing-file +or Shell-Functions empty-export failures with allow-failure rules. + +Gallery publication remains limited to the original five configured packages. +FolderEncoder, Shell-Functions and Uninstall have no reviewed release branches or +publication configuration. EXportGithub, Git-Functions and shared infrastructure +are script/infrastructure components rather than formal modules; they do not gain +module or publishing entries from this CI expansion. + +## Code and packaging concerns to verify + +### Pipe + +- `Shared-Functions/Pipe/Pipe.psd1` references scripts beside the manifest, while + source scripts live under `Functions/`. Verify source imports and packaged + imports separately. +- `Pipe/release/latest` flattens the scripts into `out/`, redirects `wtype` to + `Limit-Type`, and adds `filter-type` and `where-type` aliases absent from source. +- Release `out/Limit-Type.ps1` still executes a stray `Where-Type` example. Do not + copy that defect into the reconciled source or package. + +### Base64String + +- Commit `1f3e1fb` adds a decoder padding fallback missing from master. Review its + behavior and tests alongside encoding issue #22; do not assume the fallback is + a complete padding solution. +- That commit also adds an unrelated 344-line `PSM-Release.ps1`, subsequently + deleted by `b057dda`. Recover module changes selectively. +- Test padded and unpadded input, URL-safe input, invalid input, encoding options, + and compatibility with existing UTF-16 behavior when changing the decoder. + +### Bookmarks + +- Release `out/Shared-Functions.ps1` differs from source: update notifications use + console output rather than pipeline output, and a profile-folder parameter is + removed. Review those differences before regenerating or copying helpers. +- Source and release manifests contain a trailing space in + `'Update-PSBookmark '`. Verify exported commands and aliases against the module + implementation, including save/restore behavior. + +### Shared packaging and installation + +- No reviewed current branch tip contains `PSM-Release.ps1`; it exists in history. + Establish a reproducible packaging process before relying on regenerated output. +- `install.ps1` downloads `master`, bypassing release-branch `out/` packages. Check + the installed layout and imports when changing installation or packaging. +- Validate source and packaged manifests, file references, exported commands, + aliases, and import-time side effects. +- PowerShell was unavailable locally during this review. Findings above are from + static inspection; do not describe them as runtime-tested. + +## Suggested worktrees + +Follow the per-component development workflow: branch feature and issue work from +the component's development branch, and target that same branch for its pull request. +Being behind `master` does not make a module development branch the wrong base. +Bring in unrelated master changes only when needed and reviewed separately. + +The user confirmed that the missing development branches were deleted and +authorized recreating them. `Currency-Conv/develop` starts from +`Currency-Conv/release/1.5` (`372e316`); `7Zip/develop` starts from +`7-Zip/release/1.1` (`6f8e8f6`). Both include these instructions. These are new +development branches, not recovered copies of an unknown deleted tip. + +Use `/develop` branches for component changes and issue PRs. Use `/release/` branches +for reviewed release snapshots/package output and Gallery publishing. Do not use +a release branch as the default feature base just because development is missing. +If a development branch is missing again, inspect history and release/source +differences, propose a documented recreation base, and recreate it when authorized. +Keep older numbered releases as historical baselines. Release-only package output +still requires review before source changes are ported. + +Recheck branch state before using the listed starting points. These instructions +do not automatically authorize creating worktrees or launching agents. + +| Worktree | Suggested starting point | Scope | +| --- | --- | --- | +| `base64-reconcile` | `origin/base64tring/develop` | Build on existing 1.2.0 changes; address padding, encoding (#22), and tests. | +| `pipe-reconcile` | `origin/Pipe/develop` | Bring reviewed release-only fixes into source; repair imports and aliases. | +| `bookmarks-review` | `origin/Bookmarks/develop` | Reconcile packaged helpers; check exports and session behavior. | +| `7zip-maintenance` | `origin/7Zip/develop` | Address installed-runtime discovery (#23), Linux support (#25), and help metadata (#26). | +| `currency-maintenance` | `origin/Currency-Conv/develop` | Repair cache expiration (#17). | +| `exportgithub-maintenance` | `origin/EXportGithub/develop` | Maintain the script tool; no packaged-module or Gallery support implied. | +| `git-functions-maintenance` | `origin/Git-Functions/develop` | Maintain the script bundle and aliases. | +| `shared-functions-maintenance` | `origin/Shared-Functions/develop` | Maintain common helpers/loader; coordinate separate ports to module copies. | +| `module-packaging` | `origin/master` | Restore reproducible packaging and validate source/package imports and installer behavior. | + +Use separate worktrees tracking `Bookmarks/release/latest`, `Pipe/release/latest`, +and `base64String/release/latest` when package comparison or validation requires +them. Retain the numbered release branches for maintenance and historical comparison. + +Slow import/update-check issues #24 and #27 span module helper copies. Coordinate +that work across Bookmarks, 7Zip, Currency-Conv, and packaging so source and release +helpers do not diverge further. Coordinate packaging changes with module work; +these scopes can overlap. The current #24/#27 issue branch starts from +`Bookmarks/develop`: implement the Bookmarks change there, then port reviewed +changes separately to the 7Zip and Currency maintenance branches. Do not merge an +entire module branch into another module branch to share a helper fix. + +## Existing issue worktrees + +| Branch | Starting ref and intended PR target | Issues | +| --- | --- | --- | +| `fix/base64-encoding` | `base64tring/develop` | #22 | +| `fix/update-check-startup` | `Bookmarks/develop` | #24, #27 | +| `fix/currency-cache-expiry` | `Currency-Conv/develop` | #17 | +| `fix/7zip-runtime-help` | `7Zip/develop` | #23, #25, #26 | + +Use the table's intended target explicitly when creating a PR; a Git upstream or +Orca's historical creation-base metadata does not set a GitHub PR base. These +worktrees were initially created from master and corrected before implementation. + +## GitHub Actions migration and Gallery publishing + +The user requested separate worktrees for CI migration and publishing: + +- `ci/github-actions` in `github-actions-ci`: `.github/workflows/ci.yml`, module + routing and Pester runners, removal of legacy CI configs, and rollout notes in + `docs/github-actions-ci.md`. It targets master as repository-wide automation; + its workflow/scripts must also be ported to maintained module branches. +- `ci/psgallery-publish` in `psgallery-deploy`: manual release workflow, package + staging/publishing helpers, offline tests, and setup in + `docs/powershell-gallery.md`. It checks out the module's release package branch + explicitly; publishing sources are not module development/PR targets. + +Keep these changes in their separate worktrees. Do not extend the superseded +Azure filter edits in issue worktrees. CI is read-only and receives no Gallery +secret. Publishing defaults to dry-run and only the actual publish job receives +the selected API key as `PSGALLERY_API_KEY`. The `powershell-gallery` environment +stores distinct `PSGALLERY_API_KEY_STADUB` and `PSGALLERY_API_KEY_MINIMODULES` +secrets. `Get-ReleaseConfig.ps1` maps Bookmarks, 7zip-Archive and Currency-Conv to +Stadub, and Base64String and Pipe to MiniModules; usernames and secret names are +public configuration. The workflow has no generic-key or other-account fallback. +The environment has deployments restricted to master; both account secret names +were present at the 2026-11-12 metadata check. Values/rights remain unverified. +Never put a key in files or +chat. Do not publish packages while implementing or testing this automation. + +Local validation used portable PowerShell 7.7.0 and actionlint 1.7.12. Module +routing, offline publishing checks, workflow lint, and staging/manifest validation +of all five configured release packages passed. This does not mean the legacy +functional Pester suites or hosted GitHub Actions runs have passed. + +## Independent release-pipeline handoff (#29) + +The user assigned `ci/release-pipeline` ownership of integrated automation, explicitly +allowing selective reuse from the uncommitted `github-actions-ci` and +`psgallery-deploy` implementations. Preserve those sibling worktrees read-only. +This handoff supersedes the earlier split ownership for the files delivered here; +coordinate rollout to avoid merging duplicate workflows. Keep legacy CI deletion +and external AppVeyor trigger cutover in their existing owner scopes. + +No live upload is authorized by implementation or tests. Keep #22 open until an +actual successful Gallery publish and exact downloaded package verification. +Completion mappings belong to trusted automation on master, keyed by repository, +module, exact version and full release SHA; never derive them from dispatch issue +numbers or release-branch code. See docs/release-pipeline.md for rollout blockers. + +All five Gallery package paths now follow `/out`, including +`7Zip/out` and `Currency-Conv/out`. The configured latest release snapshots must +contain reviewed output there; never fall back to publishing module source roots. + +Use `scripts/gallery/New-ReleaseOutput.ps1` with reviewed source and a fresh output +root to generate the flat out/ package. Review and commit it on the configured +release branch; do not overwrite stale output automatically or substitute master. +The workflow checks committed package hashes against an independent regeneration. + +Base64String 1.3.0 is prepared on `base64String/release/latest` at +`6d30dbc22de8bfb8bccda5cd3880ffb9a6655f5f` (PRs #30/#34). The original encoding +fix is preserved; PR #32 adds a Windows/.NET Framework padding follow-up through +development. Exact-tip hosted validation passed 34 source + 34 installed tests on +Windows PowerShell 5.1, Windows pwsh, Linux and macOS; downloaded payload hashes +agree across all four artifacts. See docs/releases/base64string-1.3.0.md. +The owner confirmed module-local WTFPL; preserve it during generation/staging and +use the repository license only as a fallback. Do not relicense other components. +The trusted completion entry maps only #22 to this exact version/SHA, still gated +on actual successful Gallery publish and verification. No upload or issue closure +has occurred; production workflow integration into master remains pending. + +CI source selection now pins each unchanged module's maintained development ref +to a full SHA and records the identity with test artifacts. Component/release runs +and changed module sources use the actual proposal snapshot; cross-component +changes add coverage. Never substitute an unreviewed passing feature ref for a +maintained baseline. With explicit owner approval on 2026-11-12, repair PRs #40–45 +were merged only into their module development branches. Source fixes remain +separate from this automation branch. The maintained-source matrix now resolves +those merge commits. See docs/ci-component-merges.json for exact merge/source SHAs, +docs/ci-build-repairs.md for the failure inventory and docs/ci-matrix-verified.json +for the earlier review-only validation evidence. + +`scripts/gallery/Set-GalleryApiKey.ps1` is an owner-operated setup/rotation helper. +It resolves account/secret names through Get-ReleaseConfig.ps1 and delegates hidden +key entry/encryption to gh. Never pass keys in arguments, files, environment values +or chat. -WhatIf performs no network or update. It is not called by deployment +workflows; implementation/tests use mocked gh and must not change live secrets. + +On 2026-11-12 the owner explicitly authorized Azure DevOps and AppVeyor removal. +Both GitHub app installations were uninstalled after verifying each selected only +stadub/PowershellScripts (one repository each). This branch removes remaining Azure +YAML and obsolete status badges; approved AppVeyor YAML removal is preserved. +The owner has no external service access. Internal definitions/history remain; +GitHub has no supported individual deletion for their old check/status results. +Preserve historical evidence and replacement Actions results. See +docs/ci/legacy-ci-removal/README.md for exact scope and limitations. + +The owner clarified that GitHub Releases `/releases/latest` is a repository-wide +URL alias, not a required branch suffix. Gallery sources for 7Zip and Currency +use their verified `7-Zip/release/1.1` and `Currency-Conv/release/1.5` refs with +the same out-only package paths. Existing literal release/latest branches for the +other three modules remain preparation sources. Do not invent missing latest refs. +The manual release form now selects module and prepared version; it resolves the +configured release tip once, records the full SHA, and reuses it throughout the +run. It does not rewrite source/package versions or publish development directly. +The form becomes visible only after reviewed automation is integrated into master. diff --git a/Bookmarks/README.md b/Bookmarks/README.md index f4960ad..5b8d931 100644 --- a/Bookmarks/README.md +++ b/Bookmarks/README.md @@ -1,6 +1,5 @@ # Bookmarks - Directory bookmarks -[![PowerShell 3](https://Stadub-Gh.visualstudio.com/PowershellScripts/_apis/build/status/Bookmarks?branchName=master)](https://Stadub-Gh.visualstudio.com/PowershellScripts/_build/latest?definitionId=3?branchName=master) [![Linux & MacOS build](https://img.shields.io/travis/stadub/PowershellScripts/master.svg?label=linux/macos+build)](https://travis-ci.org/stadub/PowershellScripts) [![latest version](https://img.shields.io/powershellgallery/v/Bookmarks.svg?label=latest+version)](https://www.powershellgallery.com/packages/Bookmarks/) [![downloads](https://img.shields.io/powershellgallery/dt/Bookmarks.svg?label=downloads)](https://www.powershellgallery.com/packages/Bookmarks) diff --git a/Bookmarks/azure-pipelines.yml b/Bookmarks/azure-pipelines.yml deleted file mode 100644 index a46d37e..0000000 --- a/Bookmarks/azure-pipelines.yml +++ /dev/null @@ -1,28 +0,0 @@ -trigger: - - master -pr: - - master - -resources: - - repo: self - clean: true - fetchDepth: 1 - -jobs: - - job: Bookmarks - displayName: Bookmarks - continueOnError: false - pool: - vmImage: 'windows-2019' - workspace: - clean: all - timeoutInMinutes: 3 - steps: - - powershell: | - $global:PesterDebugPreference_ShowFullErrors = $true - $errorActionPreference = 'stop' - Set-StrictMode -Version Latest - $DebugPreference = "Continue" - Install-Module -Name Pester -Force - Import-Module Pester - . .\Bookmarks\Bookmarks.Tests.ps1 \ No newline at end of file diff --git a/Bookmarks/out/README.md b/Bookmarks/out/README.md index f9a9342..d65840b 100644 --- a/Bookmarks/out/README.md +++ b/Bookmarks/out/README.md @@ -1,7 +1,5 @@ # Bookmarks - Directory bookmarks -[![PowerShell 3](https://Stadub-Gh.visualstudio.com/PowershellScripts/_apis/build/status/Bookmarks?branchName=master)](https://Stadub-Gh.visualstudio.com/PowershellScripts/_build/latest?definitionId=3?branchName=master) -[![PowerShell 4, 5 & Core on Windows build](https://ci.appveyor.com/api/projects/status/7tmg8wy30ipanjsd?svg=true)](https://ci.appveyor.com/project/stadub/powershellscripts) [![Linux & MacOS build](https://img.shields.io/travis/stadub/PowershellScripts/master.svg?label=linux/macos+build)](https://travis-ci.org/stadub/PowershellScripts) [![latest version](https://img.shields.io/powershellgallery/v/Bookmarks.svg?label=latest+version)](https://www.powershellgallery.com/packages/Bookmarks/) [![downloads](https://img.shields.io/powershellgallery/dt/Bookmarks.svg?label=downloads)](https://www.powershellgallery.com/packages/Bookmarks) diff --git a/Currency-Conv/README.md b/Currency-Conv/README.md index 77833ee..e7835b0 100644 --- a/Currency-Conv/README.md +++ b/Currency-Conv/README.md @@ -1,6 +1,5 @@ # Currency-Conv - Currecny converter -[![PowerShell 3](https://dev.azure.com/Stadub-Gh/PowershellScripts/_apis/build/status/Currency-Conv?branchName=master)](https://dev.azure.com/Stadub-Gh/PowershellScripts/_build/latest?definitionId=5&branchName=master) [![Linux & MacOS build](https://img.shields.io/travis/stadub/PowershellScripts/master.svg?label=linux/macos+build)](https://travis-ci.org/stadub/PowershellScripts) [![latest version](https://img.shields.io/powershellgallery/v/Currency-Conv.svg?label=latest+version)](https://www.powershellgallery.com/packages/Currency-Conv/) [![downloads](https://img.shields.io/powershellgallery/dt/Currency-Conv.svg?label=downloads)](https://www.powershellgallery.com/packages/Currency-Conv) diff --git a/Currency-Conv/azure-pipelines.yml b/Currency-Conv/azure-pipelines.yml deleted file mode 100644 index 6b8d4a9..0000000 --- a/Currency-Conv/azure-pipelines.yml +++ /dev/null @@ -1,28 +0,0 @@ -trigger: - - master -pr: - - master - -resources: - - repo: self - clean: true - fetchDepth: 1 - -jobs: - - job: Currency_Conv - displayName: Currency-Conv - continueOnError: false - pool: - vmImage: 'windows-2019' - workspace: - clean: all - timeoutInMinutes: 3 - steps: - - powershell: | - $global:PesterDebugPreference_ShowFullErrors = $true - $errorActionPreference = 'stop' - Set-StrictMode -Version Latest - $DebugPreference = "Continue" - Install-Module -Name Pester -Force - Import-Module Pester - . .\Currency-Conv\Currency-Conv.Tests.ps1 \ No newline at end of file diff --git a/FolderEncoder/README.md b/FolderEncoder/README.md index 201736d..875f7f0 100644 --- a/FolderEncoder/README.md +++ b/FolderEncoder/README.md @@ -4,7 +4,6 @@ Used as backups encoding solution. Encoding performed with 7z password protection -[![PowerShell 3](https://Stadub-Gh.visualstudio.com/PowershellScripts/_apis/build/status/Bookmarks?branchName=master)](https://Stadub-Gh.visualstudio.com/PowershellScripts/_build/latest?definitionId=3?branchName=master) [![Linux & MacOS build](https://img.shields.io/travis/stadub/PowershellScripts/master.svg?label=linux/macos+build)](https://travis-ci.org/stadub/PowershellScripts) [![latest version](https://img.shields.io/powershellgallery/v/FolderEncoder.svg?label=latest+version)](https://www.powershellgallery.com/packages/FolderEncoder/) [![downloads](https://img.shields.io/powershellgallery/dt/FolderEncoder.svg?label=download)](https://www.powershellgallery.com/packages/FolderEncoder) diff --git a/Shared-Functions/Base64String/README.md b/Shared-Functions/Base64String/README.md index 79ddcf9..b861762 100644 --- a/Shared-Functions/Base64String/README.md +++ b/Shared-Functions/Base64String/README.md @@ -1,6 +1,5 @@ # Base64String - Convert text from/to Base 64 String -[![PowerShell 3](https://dev.azure.com/Stadub-Gh/PowershellScripts/_apis/build/status/SharedFunctions?branchName=master)](https://dev.azure.com/Stadub-Gh/PowershellScripts/_build/latest?definitionId=6&branchName=master) [![Linux & MacOS build](https://img.shields.io/travis/stadub/PowershellScripts/master.svg?label=linux/macos+build)](https://travis-ci.org/stadub/PowershellScripts) [![latest version](https://img.shields.io/powershellgallery/v/Base64String.svg?label=latest+version)](https://www.powershellgallery.com/packages/Base64String/) [![downloads](https://img.shields.io/powershellgallery/dt/Base64String.svg?label=downloads)](https://www.powershellgallery.com/packages/Base64String) diff --git a/Shared-Functions/Pipe/README.md b/Shared-Functions/Pipe/README.md index 3953f7e..8a7ad1e 100644 --- a/Shared-Functions/Pipe/README.md +++ b/Shared-Functions/Pipe/README.md @@ -1,6 +1,5 @@ # Pipe - Powershell Pipe filtering functions -[![PowerShell 3](https://dev.azure.com/Stadub-Gh/PowershellScripts/_apis/build/status/SharedFunctions?branchName=master)](https://dev.azure.com/Stadub-Gh/PowershellScripts/_build/latest?definitionId=6&branchName=master) [![Linux & MacOS build](https://img.shields.io/travis/stadub/PowershellScripts/master.svg?label=linux/macos+build)](https://travis-ci.org/stadub/PowershellScripts) [![latest version](https://img.shields.io/powershellgallery/v/Pipe.svg?label=latest+version)](https://www.powershellgallery.com/packages/Pipe/) [![downloads](https://img.shields.io/powershellgallery/dt/Pipe.svg?label=downloads)](https://www.powershellgallery.com/packages/Pipe) diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 13bd563..0000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,27 +0,0 @@ -trigger: - - master -pr: - - master - -resources: - - repo: self - clean: true - fetchDepth: 1 - -jobs: - - job: Bookmarks - displayName: Bookmarks - continueOnError: false - pool: - vmImage: 'windows-2019' - workspace: - clean: all - timeoutInMinutes: 3 - steps: - - powershell: | - $global:PesterDebugPreference_ShowFullErrors = $true - $errorActionPreference = 'stop' - Set-StrictMode -Version Latest - Install-Module -Name Pester -Force - Import-Module Pester - . .\Bookmarks\Bookmarks.Tests.ps1 \ No newline at end of file diff --git a/docs/ci-build-repairs.json b/docs/ci-build-repairs.json new file mode 100644 index 0000000..1043275 --- /dev/null +++ b/docs/ci-build-repairs.json @@ -0,0 +1,225 @@ +{ + "date": "2026-11-12", + "baselineRun": "https://github.com/stadub/PowershellScripts/actions/runs/43087475163", + "componentRepairs": [ + { + "module": "Bookmarks", + "path": "Bookmarks", + "head": "fix/build-bookmarks", + "base": "Bookmarks/develop", + "tests": 26, + "sha": "8f122965e7fcc515ba6487901cc5860b6bc99a0a", + "number": 40, + "url": "https://github.com/stadub/PowershellScripts/pull/40", + "hostedRun": { + "conclusion": "success", + "databaseId": 43114997026, + "headSha": "8f122965e7fcc515ba6487901cc5860b6bc99a0a", + "status": "completed", + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43114997026" + }, + "hostedJobs": [ + { + "name": "source / test (macos-latest)", + "status": "completed", + "conclusion": "success" + }, + { + "name": "source / test (windows-latest)", + "status": "completed", + "conclusion": "success" + }, + { + "name": "source / test (ubuntu-latest)", + "status": "completed", + "conclusion": "success" + } + ] + }, + { + "module": "Pipe", + "path": "Shared-Functions/Pipe", + "head": "fix/build-pipe", + "base": "Pipe/develop", + "tests": 8, + "sha": "ed386fb0c70539917fd90f629aee91d49c04ad37", + "number": 41, + "url": "https://github.com/stadub/PowershellScripts/pull/41", + "hostedRun": { + "conclusion": "success", + "databaseId": 43115004981, + "headSha": "ed386fb0c70539917fd90f629aee91d49c04ad37", + "status": "completed", + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43115004981" + }, + "hostedJobs": [ + { + "name": "source / test (windows-latest)", + "status": "completed", + "conclusion": "success" + }, + { + "name": "source / test (ubuntu-latest)", + "status": "completed", + "conclusion": "success" + }, + { + "name": "source / test (macos-latest)", + "status": "completed", + "conclusion": "success" + } + ] + }, + { + "module": "Currency-Conv", + "path": "Currency-Conv", + "head": "fix/build-currency", + "base": "Currency-Conv/develop", + "tests": 15, + "sha": "91ec76d0dd2a2d1c74c3c2613cef9c9b12c2e0b6", + "number": 42, + "url": "https://github.com/stadub/PowershellScripts/pull/42", + "hostedRun": { + "conclusion": "success", + "databaseId": 43115009752, + "headSha": "91ec76d0dd2a2d1c74c3c2613cef9c9b12c2e0b6", + "status": "completed", + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43115009752" + }, + "hostedJobs": [ + { + "name": "source / test (windows-latest)", + "status": "completed", + "conclusion": "success" + }, + { + "name": "source / test (macos-latest)", + "status": "completed", + "conclusion": "success" + }, + { + "name": "source / test (ubuntu-latest)", + "status": "completed", + "conclusion": "success" + } + ] + }, + { + "module": "7zip-Archive", + "path": "7Zip", + "head": "fix/build-7zip", + "base": "7Zip/develop", + "tests": 19, + "sha": "06cabf8d6296cfe5ac5c806e66b0b81d8bf87339", + "number": 43, + "url": "https://github.com/stadub/PowershellScripts/pull/43", + "hostedRun": { + "conclusion": "success", + "databaseId": 43115017582, + "headSha": "06cabf8d6296cfe5ac5c806e66b0b81d8bf87339", + "status": "completed", + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43115017582" + }, + "hostedJobs": [ + { + "name": "source / test (windows-latest)", + "status": "completed", + "conclusion": "success" + } + ] + }, + { + "module": "FolderEncoder", + "path": "FolderEncoder", + "head": "fix/build-folderencoder", + "base": "FolderEncoder/develop", + "tests": 3, + "sha": "f3175178e7a4ce19ab368cfa05e5ef0e6e78c002", + "number": 44, + "url": "https://github.com/stadub/PowershellScripts/pull/44", + "hostedRun": { + "conclusion": "success", + "databaseId": 43115021526, + "headSha": "f3175178e7a4ce19ab368cfa05e5ef0e6e78c002", + "status": "completed", + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43115021526" + }, + "hostedJobs": [ + { + "name": "source / test (ubuntu-latest)", + "status": "completed", + "conclusion": "success" + }, + { + "name": "source / test (macos-latest)", + "status": "completed", + "conclusion": "success" + }, + { + "name": "source / test (windows-latest)", + "status": "completed", + "conclusion": "success" + } + ] + }, + { + "module": "Shell-Functions", + "path": "Shell-Functions", + "head": "fix/build-shell-functions", + "base": "Shell-Functions/develop", + "tests": 6, + "sha": "b31f26740aba6ed9d74a478de992a3f2f50b6dca", + "number": 45, + "url": "https://github.com/stadub/PowershellScripts/pull/45", + "hostedRun": { + "conclusion": "success", + "databaseId": 43115030061, + "headSha": "b31f26740aba6ed9d74a478de992a3f2f50b6dca", + "status": "completed", + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43115030061" + }, + "hostedJobs": [ + { + "name": "source / test (windows-latest)", + "status": "completed", + "conclusion": "success" + }, + { + "name": "source / test (macos-latest)", + "status": "completed", + "conclusion": "success" + }, + { + "name": "source / test (ubuntu-latest)", + "status": "completed", + "conclusion": "success" + } + ] + } + ], + "finalCombinedRun": { + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43120956188", + "sha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "conclusion": "success", + "moduleOsJobs": 22, + "pesterAssertions": 295, + "structureAssertions": 24, + "failures": 0, + "skipped": 0, + "evidence": "ci-matrix-verified.json" + }, + "maintainedBaselineRun": { + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43120912939", + "automationSha": "06ee2deb2bc11affb7dfa18f7b7098013964f479", + "conclusion": "failure", + "passingModuleOsJobs": 6, + "failingModuleOsJobs": 16, + "reason": "Six component repair drafts require review and integration into their development branches" + }, + "integration": { + "status": "merged with explicit owner approval", + "date": "2026-11-12", + "evidence": "ci-component-merges.json", + "aggregateCheck": "https://github.com/stadub/PowershellScripts/pull/31/checks" + } +} diff --git a/docs/ci-build-repairs.md b/docs/ci-build-repairs.md new file mode 100644 index 0000000..05f9f14 --- /dev/null +++ b/docs/ci-build-repairs.md @@ -0,0 +1,122 @@ +# Aggregate build failures and component repairs + +Recorded 2026-11-12. [The original aggregate run](https://github.com/stadub/PowershellScripts/actions/runs/43087475163) +passed its automation planning/contracts and Uninstall checks, but failed 19 of +22 module/OS jobs. The aggregate branch still carried historical master copies, +while maintained module source and existing focused fixes lived elsewhere. +No failure was changed into a skip or allow-failure result. + +| Module | Original failure | +| --- | --- | +| Base64String | Old 1.1 source/contradictory legacy test: 1 failed assertion per OS; corrected development/release snapshots already pass 34 cases | +| Bookmarks | 8 persistence assertions per OS and a trailing-space manifest export | +| Currency-Conv | 3 stale cache/API assertions per OS | +| 7zip-Archive | 6 legacy runtime-discovery assertions on Windows | +| Pipe | Manifest references scripts missing beside the source manifest | +| FolderEncoder | Manifest references deleted Functions.ps1 and exports the wrong command name | +| Shell-Functions | Manifest loads no implementation and exports no commands | +| Uninstall | No failure; syntax/import/public-parameter checks pass | + +## Source selection correction + +Repository-wide automation must not assume master has every module fix. CI now +resolves the eight maintained development refs to immutable SHAs for unchanged +modules. Component/release runs test the actual workflow source snapshot. Any +module runtime source/manifests/tests changed by a proposal are also tested from +that proposal's commit; cross-component changes expand coverage rather than being +ignored. Documentation-only changes and out/ copies do not replace source baselines. + +For PRs, change detection uses the merge base with the PR target. For feature/CI +pushes, it uses the merge base with master, so earlier unmerged source changes stay +covered across later commits. A direct master push compares against the previous +push tip. NUL-separated Git paths handle whitespace in source filenames. Missing +or malformed maintained SHAs fail planning; there is no stale-root fallback. + +Every matrix entry contains source ref, mode and exact SHA. Each job checks out +that source separately, uses the current automation runner, and publishes a +source-identity.json with its NUnit reports. This explicitly describes what was +tested; it does not claim the historical source copies on master are repaired. +Source selection has offline contracts for changed-source coverage, component and +release snapshots, all eight maintained baselines, immutable refs and single output. + +## Reviewable component fixes + +Existing focused owner commits were reused in new module-targeted branches. Original +owner checkouts and branches were preserved. All component hosted matrices pass: +three OS jobs each, except the established Windows-only 7zip-Archive route. + +| Module | Merged PR / target | Pester cases | Hosted source checks | +| --- | --- | ---: | --- | +| Bookmarks | [40](https://github.com/stadub/PowershellScripts/pull/40) → Bookmarks/develop | 26 | [passed](https://github.com/stadub/PowershellScripts/actions/runs/43114997026) | +| Pipe | [41](https://github.com/stadub/PowershellScripts/pull/41) → Pipe/develop | 8 | [passed](https://github.com/stadub/PowershellScripts/actions/runs/43115004981) | +| Currency-Conv | [42](https://github.com/stadub/PowershellScripts/pull/42) → Currency-Conv/develop | 15 | [passed](https://github.com/stadub/PowershellScripts/actions/runs/43115009752) | +| 7zip-Archive | [43](https://github.com/stadub/PowershellScripts/pull/43) → 7Zip/develop | 19 | [passed](https://github.com/stadub/PowershellScripts/actions/runs/43115017582) | +| FolderEncoder | [44](https://github.com/stadub/PowershellScripts/pull/44) → FolderEncoder/develop | 3 | [passed](https://github.com/stadub/PowershellScripts/actions/runs/43115021526) | +| Shell-Functions | [45](https://github.com/stadub/PowershellScripts/pull/45) → Shell-Functions/develop | 6 | [passed](https://github.com/stadub/PowershellScripts/actions/runs/43115030061) | + +Bookmarks preserves **both** 8eb0476 update-check throttling and b4a0e6f persistence/ +export repairs (14 + 12 tests). Pipe reuses 2431e39, Currency 53ca85d and 7Zip cdb6c2e. +No whole component branch was merged to distribute common helpers. + +FolderEncoder restores its historical Functions.ps1 byte-for-byte from before +4a336c7 and exports the documented Invoke-FolderEncode. Its three cases cover +manifest/import/export/parameter contracts and import-time filesystem safety. +They do **not** execute or validate the legacy encoder, downloads or archive +roundtrip. This import repair does not establish production encoder correctness. + +Shell wires the existing implementation into its manifest, preserves the protected +fl alias, omits the dangling pb alias and scopes aliases to the module. It fixes +Split-String's method-property typo and the undefined link enum/provider item types. +Six cases cover actual text filters and mocked provider argument routing, not +Windows batch helpers, interactive prompts or real link creation. + +## Combined validation and rollout + +A separate **review-only** snapshot on ci/module-fixes-preview combines the exact +candidate source files with automation. It does not promote source into master, +module development branches or ci/release-pipeline. Its source ledger is +`docs/ci-module-preview.json` on that branch. The initial combined run +[43117606572](https://github.com/stadub/PowershellScripts/actions/runs/43117606572) +passed all 22 module/OS jobs, planning and aggregate status. + +The final source-selection run [43120956188](https://github.com/stadub/PowershellScripts/actions/runs/43120956188) +at `9f6273bf9198dec336f56fe565665a37f7c84758` also passed all 24 jobs. Downloaded +artifacts independently confirm 22 source identities and 28 NUnit reports: +295 Pester assertions plus 24 structural assertions, zero failures and zero skips. +The seven changed modules use that exact review snapshot; Uninstall uses its pinned +development SHA. The file ledger links the snapshot's module files to their +component candidates. See [verified report hashes and source identities](ci-matrix-verified.json). + +The owner explicitly approved merging PRs #40–45 on 2026-11-12. Each exact reviewed +head and base SHA, active source checks, required-check configuration and +mergeability was rechecked immediately before its normal merge commit. No rule +bypass was used. The retired AppVeyor failures were historical, non-required +contexts; their GitHub integration was already removed. + +All six repairs are now on their respective module development branches. See +[merge and maintained-source identities](ci-component-merges.json). Fresh +[aggregate checks on PR #31](https://github.com/stadub/PowershellScripts/pull/31/checks) +resolve these maintained tips to immutable SHAs. No module behavior fixes were +added to automation PR #31, and no passing feature branch substitutes for a +maintained baseline. Master and release branches were not merged or edited. + +Specifically, [the maintained-baseline run at automation commit 06ee2de](https://github.com/stadub/PowershellScripts/actions/runs/43120912939) +passed planning, Base64String and Uninstall (six module/OS jobs). Its historical +16 module/OS failures correspond to the six component repairs, which were then +unmerged. That failed run is preserved; it does not describe the newly integrated +development tips. The successful preview remains evidence for the proposed files, +while the fresh aggregate run tests the maintained branches after integration. + +The already approved AppVeyor removal from master was synced into the automation +branch; this task did not edit master. Legacy external AppVeyor/Azure service +statuses are distinct from GitHub Actions. The owner subsequently authorized +[repository-side service removal](ci/legacy-ci-removal/README.md): both single-repo +GitHub app installations are removed, with YAML/badge cleanup in this branch. +Historical results remain because GitHub has no supported deletion operation; +external definitions/history remain inaccessible. No results were masked as success. + +No release out/ package, Gallery routing, environment restriction, secret or issue +completion was changed by these source repairs. Base64String 1.3.0 release evidence +and the exact publish-gated #22 mapping remain unchanged. Nothing was published. + +See [machine-readable PR/source/job evidence](ci-build-repairs.json). diff --git a/docs/ci-component-merges.json b/docs/ci-component-merges.json new file mode 100644 index 0000000..51fa047 --- /dev/null +++ b/docs/ci-component-merges.json @@ -0,0 +1,118 @@ +{ + "date": "2026-11-12", + "authorization": "Owner explicitly selected: Merge PRs #40\u201345 and rerun CI", + "scope": "Six component development branches only; master/release/Gallery unchanged", + "merges": [ + { + "number": 40, + "base": "Bookmarks/develop", + "baseShaBefore": "a17e2b348807ec1688a713bebb2b973b211fa141", + "reviewedHeadSha": "8f122965e7fcc515ba6487901cc5860b6bc99a0a", + "mergeSha": "5d63a44e4135c5bc3f46f1b7e6cbd928476a2004", + "mergedAt": "2026-11-12T00:50:32Z", + "url": "https://github.com/stadub/PowershellScripts/pull/40", + "sourceCheckNames": [ + "source / test (macos-latest)", + "source / test (ubuntu-latest)", + "source / test (windows-latest)" + ], + "requiredContexts": [], + "method": "merge", + "adminBypass": false + }, + { + "number": 41, + "base": "Pipe/develop", + "baseShaBefore": "9567c81804cbe8fcd68913ea1b00c417152bb393", + "reviewedHeadSha": "ed386fb0c70539917fd90f629aee91d49c04ad37", + "mergeSha": "ed959361a5f0d08997a795967402bcd464b85410", + "mergedAt": "2026-11-12T00:50:39Z", + "url": "https://github.com/stadub/PowershellScripts/pull/41", + "sourceCheckNames": [ + "source / test (macos-latest)", + "source / test (ubuntu-latest)", + "source / test (windows-latest)" + ], + "requiredContexts": [], + "method": "merge", + "adminBypass": false + }, + { + "number": 42, + "base": "Currency-Conv/develop", + "baseShaBefore": "35cde0c1d50087e52324fde65831aeaef137ea8c", + "reviewedHeadSha": "91ec76d0dd2a2d1c74c3c2613cef9c9b12c2e0b6", + "mergeSha": "7306a3b9c3deb1de7257fb51f9b0becdaf7acd4a", + "mergedAt": "2026-11-12T00:50:45Z", + "url": "https://github.com/stadub/PowershellScripts/pull/42", + "sourceCheckNames": [ + "source / test (macos-latest)", + "source / test (ubuntu-latest)", + "source / test (windows-latest)" + ], + "requiredContexts": [], + "method": "merge", + "adminBypass": false + }, + { + "number": 43, + "base": "7Zip/develop", + "baseShaBefore": "93ac7b94cbb11b548bb7373de6eb088d9a242ff5", + "reviewedHeadSha": "06cabf8d6296cfe5ac5c806e66b0b81d8bf87339", + "mergeSha": "b846f1b01fad8e193cb9e92abdc75a0338c6c823", + "mergedAt": "2026-11-12T00:50:52Z", + "url": "https://github.com/stadub/PowershellScripts/pull/43", + "sourceCheckNames": [ + "source / test (windows-latest)" + ], + "requiredContexts": [], + "method": "merge", + "adminBypass": false + }, + { + "number": 44, + "base": "FolderEncoder/develop", + "baseShaBefore": "0515de02b0394e8818505aff1f9a1962492c380e", + "reviewedHeadSha": "f3175178e7a4ce19ab368cfa05e5ef0e6e78c002", + "mergeSha": "9b339c1d02e67e601b253da97d770c43242953ca", + "mergedAt": "2026-11-12T00:50:58Z", + "url": "https://github.com/stadub/PowershellScripts/pull/44", + "sourceCheckNames": [ + "source / test (macos-latest)", + "source / test (ubuntu-latest)", + "source / test (windows-latest)" + ], + "requiredContexts": [], + "method": "merge", + "adminBypass": false + }, + { + "number": 45, + "base": "Shell-Functions/develop", + "baseShaBefore": "0515de02b0394e8818505aff1f9a1962492c380e", + "reviewedHeadSha": "b31f26740aba6ed9d74a478de992a3f2f50b6dca", + "mergeSha": "5cd269b6602e973af70387ce04eaf26b82e04b89", + "mergedAt": "2026-11-12T00:51:05Z", + "url": "https://github.com/stadub/PowershellScripts/pull/45", + "sourceCheckNames": [ + "source / test (macos-latest)", + "source / test (ubuntu-latest)", + "source / test (windows-latest)" + ], + "requiredContexts": [], + "method": "merge", + "adminBypass": false + } + ], + "maintainedSourcesAfterIntegration": { + "Bookmarks/develop": "5d63a44e4135c5bc3f46f1b7e6cbd928476a2004", + "Pipe/develop": "ed959361a5f0d08997a795967402bcd464b85410", + "Currency-Conv/develop": "7306a3b9c3deb1de7257fb51f9b0becdaf7acd4a", + "7Zip/develop": "b846f1b01fad8e193cb9e92abdc75a0338c6c823", + "FolderEncoder/develop": "9b339c1d02e67e601b253da97d770c43242953ca", + "Shell-Functions/develop": "5cd269b6602e973af70387ce04eaf26b82e04b89", + "base64tring/develop": "7eab2ac96dc04bbbfc78a54aeb817fe3cc9f25bd", + "Uninstall/develop": "cb191cc44ec85174187958b994065f6452ae046f" + }, + "aggregateCheck": "https://github.com/stadub/PowershellScripts/pull/31/checks" +} diff --git a/docs/ci-matrix-verified.json b/docs/ci-matrix-verified.json new file mode 100644 index 0000000..89ef656 --- /dev/null +++ b/docs/ci-matrix-verified.json @@ -0,0 +1,469 @@ +{ + "run": { + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43120956188", + "headSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "conclusion": "success" + }, + "automationImplementationSha": "06ee2deb2bc11affb7dfa18f7b7098013964f479", + "scope": "review-only combined module candidates; not a merge or release authorization", + "successfulJobs": 24, + "moduleOsJobs": 22, + "pesterAssertions": 295, + "structureAssertions": 24, + "failures": 0, + "skipped": 0, + "identities": [ + { + "artifact": "tests-7zip-Archive-windows-latest", + "sourceRef": "workflow snapshot", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceMode": "snapshot", + "module": "7zip-Archive", + "sha256": "4c1fc9f5ddca8bd9c41ba98651991278abb74f8741df9cb3d7a04db0122223a3" + }, + { + "artifact": "tests-Base64String-macos-latest", + "module": "Base64String", + "sourceRef": "workflow snapshot", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceMode": "snapshot", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sha256": "9544b17ca8d342c06eaede46152f5ee7b760f3514222e513898adcbdb41bc7ad" + }, + { + "artifact": "tests-Base64String-ubuntu-latest", + "module": "Base64String", + "sourceMode": "snapshot", + "sourceRef": "workflow snapshot", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sha256": "4232afa6e0d0975982efbdcd192eb09b1fb41dceec228c5769e7b8d462d4c974" + }, + { + "artifact": "tests-Base64String-windows-latest", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceRef": "workflow snapshot", + "module": "Base64String", + "sourceMode": "snapshot", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sha256": "1dfc06b8e307ed3b488e929bd41d3033208936167e5fa5d811ff707e12fec5a2" + }, + { + "artifact": "tests-Bookmarks-macos-latest", + "sourceRef": "workflow snapshot", + "module": "Bookmarks", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceMode": "snapshot", + "sha256": "5a7a265a7f58c8d9f241d46ed6aee6100daac2d012839fd8ea070c91e07e67cb" + }, + { + "artifact": "tests-Bookmarks-ubuntu-latest", + "sourceMode": "snapshot", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "module": "Bookmarks", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceRef": "workflow snapshot", + "sha256": "f11f0b900b3ba4c7408ff7de740e7326d13c76f5078a27661ee848debc274535" + }, + { + "artifact": "tests-Bookmarks-windows-latest", + "sourceMode": "snapshot", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceRef": "workflow snapshot", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "module": "Bookmarks", + "sha256": "ede21c53a14668721148b09c04e08b2c2bf5872bf04e0d336f1c2b736e2d22db" + }, + { + "artifact": "tests-Currency-Conv-macos-latest", + "module": "Currency-Conv", + "sourceRef": "workflow snapshot", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceMode": "snapshot", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sha256": "91338cc2dc75a834e19733784e804f82ec5c56663236bc5cfa4c841e2761c4db" + }, + { + "artifact": "tests-Currency-Conv-ubuntu-latest", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceRef": "workflow snapshot", + "module": "Currency-Conv", + "sourceMode": "snapshot", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sha256": "72cd60ce4a08507cfe885f8f61ddbe640611eadd823e4c9277328f8a907669a2" + }, + { + "artifact": "tests-Currency-Conv-windows-latest", + "module": "Currency-Conv", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceRef": "workflow snapshot", + "sourceMode": "snapshot", + "sha256": "b4296adbf7bb1414e69eb4682edcde08b0490b300b3f1105011dc825df35192a" + }, + { + "artifact": "tests-FolderEncoder-macos-latest", + "sourceMode": "snapshot", + "module": "FolderEncoder", + "sourceRef": "workflow snapshot", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sha256": "82eaccff2a65a334c66432fd5371b38f20d742d4dbf2336bdb05c7140bcb7631" + }, + { + "artifact": "tests-FolderEncoder-ubuntu-latest", + "sourceMode": "snapshot", + "sourceRef": "workflow snapshot", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "module": "FolderEncoder", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sha256": "c40945e10201d4ab0cded37a69c659e4939110cf38499b98cf559cc21eefb657" + }, + { + "artifact": "tests-FolderEncoder-windows-latest", + "sourceRef": "workflow snapshot", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "module": "FolderEncoder", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceMode": "snapshot", + "sha256": "2f7e7c7ffc5e0bc1014f25cf7f1b8002bf8bcec3fcd31abac0dac836ed88b649" + }, + { + "artifact": "tests-Pipe-macos-latest", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceMode": "snapshot", + "module": "Pipe", + "sourceRef": "workflow snapshot", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sha256": "14845cfd380b5db63b17c998c579737cba976777a40fd8088ad3b67836e4da62" + }, + { + "artifact": "tests-Pipe-ubuntu-latest", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceRef": "workflow snapshot", + "module": "Pipe", + "sourceMode": "snapshot", + "sha256": "e0fc5dc2397dd16a25a24322d1978ac6c894b9b130b4176450eac0ee55d68296" + }, + { + "artifact": "tests-Pipe-windows-latest", + "sourceMode": "snapshot", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceRef": "workflow snapshot", + "module": "Pipe", + "sha256": "3d0d61715a199df01271576dd9ba4406b5cc9f6f646fb7f4ba0f07212073f30f" + }, + { + "artifact": "tests-Shell-Functions-macos-latest", + "sourceMode": "snapshot", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "module": "Shell-Functions", + "sourceRef": "workflow snapshot", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sha256": "35b5e9f200e1c619a215c5115c7024a31005a999d9d50c29ac1bb8264f1d152f" + }, + { + "artifact": "tests-Shell-Functions-ubuntu-latest", + "sourceMode": "snapshot", + "module": "Shell-Functions", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceRef": "workflow snapshot", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sha256": "ed31e92f8e038fa30e3f12dc015b7400e6524668a0394d4f65e4e4f9a36a95d6" + }, + { + "artifact": "tests-Shell-Functions-windows-latest", + "sourceMode": "snapshot", + "module": "Shell-Functions", + "sourceSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceRef": "workflow snapshot", + "sha256": "f77fef3f5e78cafe4459785bccc97915d7ebb443b1a192244d3ae308bc638787" + }, + { + "artifact": "tests-Uninstall-macos-latest", + "module": "Uninstall", + "sourceRef": "Uninstall/develop", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceMode": "development", + "sourceSha": "cb191cc44ec85174187958b994065f6452ae046f", + "sha256": "8012eeca4038ac883d631df4a05fff00aa912acf896896e59ad24e95ad7d3d34" + }, + { + "artifact": "tests-Uninstall-ubuntu-latest", + "sourceSha": "cb191cc44ec85174187958b994065f6452ae046f", + "module": "Uninstall", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceRef": "Uninstall/develop", + "sourceMode": "development", + "sha256": "abb21d584241118d5d3a576546efde0fe32a92fc5c5c90984ae87b8716ca9ee2" + }, + { + "artifact": "tests-Uninstall-windows-latest", + "sourceRef": "Uninstall/develop", + "sourceSha": "cb191cc44ec85174187958b994065f6452ae046f", + "automationSha": "9f6273bf9198dec336f56fe565665a37f7c84758", + "sourceMode": "development", + "module": "Uninstall", + "sha256": "29bd2983f9c617244290b187a80d657ab778bbc9a82632a663cb47ee1fae6409" + } + ], + "reports": [ + { + "artifact": "tests-7zip-Archive-windows-latest", + "file": "7zip-Archive.xml", + "kind": "pester", + "total": 19, + "failures": 0, + "skipped": 0, + "sha256": "c7fa8a8c515cad994219d3641e97d41013b66c76be3e70bcfc9c4361befaf3cf" + }, + { + "artifact": "tests-Base64String-macos-latest", + "file": "Base64String.xml", + "kind": "pester", + "total": 34, + "failures": 0, + "skipped": 0, + "sha256": "60f5fc7e3380f734da94a1144892ff6f09f28b1067e403a9ca3458ccc7babed0" + }, + { + "artifact": "tests-Base64String-ubuntu-latest", + "file": "Base64String.xml", + "kind": "pester", + "total": 34, + "failures": 0, + "skipped": 0, + "sha256": "0e754548333fb971959a28e7c2af185a8791b1fd037dafbee1ec84028eaae096" + }, + { + "artifact": "tests-Base64String-windows-latest", + "file": "Base64String.xml", + "kind": "pester", + "total": 34, + "failures": 0, + "skipped": 0, + "sha256": "ed2f5cc7b836b2ea2c8c0fde7db9ec6ee2f53bde1f40f9e4b453c69ab41a8cec" + }, + { + "artifact": "tests-Bookmarks-macos-latest", + "file": "Bookmarks.xml", + "kind": "pester", + "total": 26, + "failures": 0, + "skipped": 0, + "sha256": "050218cbbf4704907e6349d2120092b34271e384bfcf80acd3a214d6f7e0ce2d" + }, + { + "artifact": "tests-Bookmarks-ubuntu-latest", + "file": "Bookmarks.xml", + "kind": "pester", + "total": 26, + "failures": 0, + "skipped": 0, + "sha256": "5afd5e87c77baa463d98b9d55553883c5d5c25e9e6ae257ec80e2c47f354aeb2" + }, + { + "artifact": "tests-Bookmarks-windows-latest", + "file": "Bookmarks.xml", + "kind": "pester", + "total": 26, + "failures": 0, + "skipped": 0, + "sha256": "08382a655401e637b0fd0b9b2b995b7c6d5ad6dfbc59f71f346786fc847020e4" + }, + { + "artifact": "tests-Currency-Conv-macos-latest", + "file": "Currency-Conv.xml", + "kind": "pester", + "total": 15, + "failures": 0, + "skipped": 0, + "sha256": "c99e3615998ed92191549e512d22174e2d2a769689e2e66a0241556b73e36b85" + }, + { + "artifact": "tests-Currency-Conv-ubuntu-latest", + "file": "Currency-Conv.xml", + "kind": "pester", + "total": 15, + "failures": 0, + "skipped": 0, + "sha256": "401b0d2be51e4f6f088bc816b5a9ac10ecbda4d4859e44b769818e10e3bb034a" + }, + { + "artifact": "tests-Currency-Conv-windows-latest", + "file": "Currency-Conv.xml", + "kind": "pester", + "total": 15, + "failures": 0, + "skipped": 0, + "sha256": "a21b584feda61ba8c3c4eadf4fc5f09cd6d849129c29ae475b73ba1697579844" + }, + { + "artifact": "tests-FolderEncoder-macos-latest", + "file": "FolderEncoder-structure.xml", + "kind": "structure", + "total": 3, + "failures": 0, + "skipped": 0, + "sha256": "f249ded7a9a16e7ef7d8955810fa0d2a58f0eba7b24fd34426195dfbf56bba65" + }, + { + "artifact": "tests-FolderEncoder-macos-latest", + "file": "FolderEncoder.xml", + "kind": "pester", + "total": 3, + "failures": 0, + "skipped": 0, + "sha256": "9a0d0c9ef0e7316061a8bde4e9472a72fae2c74d6a38b4def6e64f79e34cd0b1" + }, + { + "artifact": "tests-FolderEncoder-ubuntu-latest", + "file": "FolderEncoder-structure.xml", + "kind": "structure", + "total": 3, + "failures": 0, + "skipped": 0, + "sha256": "f249ded7a9a16e7ef7d8955810fa0d2a58f0eba7b24fd34426195dfbf56bba65" + }, + { + "artifact": "tests-FolderEncoder-ubuntu-latest", + "file": "FolderEncoder.xml", + "kind": "pester", + "total": 3, + "failures": 0, + "skipped": 0, + "sha256": "079f6bb81c2833f1e04366a73e19bc234618b4303a7278b9ef63ac2650dfe27e" + }, + { + "artifact": "tests-FolderEncoder-windows-latest", + "file": "FolderEncoder-structure.xml", + "kind": "structure", + "total": 3, + "failures": 0, + "skipped": 0, + "sha256": "d54894b092cb478e3dcecee14e244b9e341bfeaf57d26c783cf6d1760a26ee48" + }, + { + "artifact": "tests-FolderEncoder-windows-latest", + "file": "FolderEncoder.xml", + "kind": "pester", + "total": 3, + "failures": 0, + "skipped": 0, + "sha256": "d4cc999f82fb88792762d40ba3b83305512d78309d1ba690bfb7d6c029f1e4a2" + }, + { + "artifact": "tests-Pipe-macos-latest", + "file": "Pipe.xml", + "kind": "pester", + "total": 8, + "failures": 0, + "skipped": 0, + "sha256": "999ca41cf251aa57c3464232444c47f8d3f78c2ed229b3b4bf6160aa72b0ee95" + }, + { + "artifact": "tests-Pipe-ubuntu-latest", + "file": "Pipe.xml", + "kind": "pester", + "total": 8, + "failures": 0, + "skipped": 0, + "sha256": "93c211c58903fb2f577de31e9ab4aaae4dfea6560abd642b445890686177dbeb" + }, + { + "artifact": "tests-Pipe-windows-latest", + "file": "Pipe.xml", + "kind": "pester", + "total": 8, + "failures": 0, + "skipped": 0, + "sha256": "31566f8877e37b67ba7e23295921f9a2e21a09443d9da810da34a2b9621b9346" + }, + { + "artifact": "tests-Shell-Functions-macos-latest", + "file": "Shell-Functions-structure.xml", + "kind": "structure", + "total": 3, + "failures": 0, + "skipped": 0, + "sha256": "3d6ea12311108ad6f01b15b6c89c3d07c5c6f9b30f4fa09d3533679e53881d24" + }, + { + "artifact": "tests-Shell-Functions-macos-latest", + "file": "Shell-Functions.xml", + "kind": "pester", + "total": 6, + "failures": 0, + "skipped": 0, + "sha256": "f784bc76449c4518974f1bf95eca44735c2d7dbc2332b7dbee75c5f1ffe83eaa" + }, + { + "artifact": "tests-Shell-Functions-ubuntu-latest", + "file": "Shell-Functions-structure.xml", + "kind": "structure", + "total": 3, + "failures": 0, + "skipped": 0, + "sha256": "3d6ea12311108ad6f01b15b6c89c3d07c5c6f9b30f4fa09d3533679e53881d24" + }, + { + "artifact": "tests-Shell-Functions-ubuntu-latest", + "file": "Shell-Functions.xml", + "kind": "pester", + "total": 6, + "failures": 0, + "skipped": 0, + "sha256": "08856ac8091877a7a01fb7fd7606c7eecf52905edecbaff90da18d2519c925b6" + }, + { + "artifact": "tests-Shell-Functions-windows-latest", + "file": "Shell-Functions-structure.xml", + "kind": "structure", + "total": 3, + "failures": 0, + "skipped": 0, + "sha256": "014dd294378e6875b711e5106417a505ed51653fe914d0af9566c8a5100440e4" + }, + { + "artifact": "tests-Shell-Functions-windows-latest", + "file": "Shell-Functions.xml", + "kind": "pester", + "total": 6, + "failures": 0, + "skipped": 0, + "sha256": "a44184910fe2f9275df923fd400e43a3396f1b17c903db6ae9b9a3aba8ac8600" + }, + { + "artifact": "tests-Uninstall-macos-latest", + "file": "Uninstall-structure.xml", + "kind": "structure", + "total": 2, + "failures": 0, + "skipped": 0, + "sha256": "ca6e36d821755dc8dc0902853dec1014e5b40b43d3dee46e2c255c021d5a90a2" + }, + { + "artifact": "tests-Uninstall-ubuntu-latest", + "file": "Uninstall-structure.xml", + "kind": "structure", + "total": 2, + "failures": 0, + "skipped": 0, + "sha256": "ca6e36d821755dc8dc0902853dec1014e5b40b43d3dee46e2c255c021d5a90a2" + }, + { + "artifact": "tests-Uninstall-windows-latest", + "file": "Uninstall-structure.xml", + "kind": "structure", + "total": 2, + "failures": 0, + "skipped": 0, + "sha256": "40464f0b933998d1b275ae92dd9263949dcc787a5b37b2ed67df54cf949f9c64" + } + ] +} diff --git a/docs/ci/appveyor-cutover/README.md b/docs/ci/appveyor-cutover/README.md index 46fbb6a..0ae5a06 100644 --- a/docs/ci/appveyor-cutover/README.md +++ b/docs/ci/appveyor-cutover/README.md @@ -1,5 +1,10 @@ # AppVeyor integration cutover +**Historical audit:** the owner subsequently authorized live removal on 2026-11-12. +The single-repository AppVeyor and Azure Pipelines GitHub installations are now +removed. See [current outcome and remaining access limits](../legacy-ci-removal/README.md). +The original findings and snapshots below are preserved as before-state evidence. + Scope: `stadub/PowershellScripts`, branch `ci/remove-appveyor-checks`, intended PR target **master**. Audit date: 2026-11-11. Repository infrastructure only. Instructions were read from `/Users/dimastadub/orca/PowershellScripts/AGENTS.md` diff --git a/docs/ci/legacy-ci-removal/README.md b/docs/ci/legacy-ci-removal/README.md new file mode 100644 index 0000000..a05edd4 --- /dev/null +++ b/docs/ci/legacy-ci-removal/README.md @@ -0,0 +1,95 @@ +# Azure Pipelines and AppVeyor removal + +On 2026-11-12 the owner explicitly requested removal of Azure DevOps and AppVeyor +from `stadub/PowershellScripts`, including their stale test results. Scope is this +repository only. The owner has no Azure DevOps or AppVeyor account access. + +## Live GitHub changes + +The owner completed GitHub's required authentication directly. The Azure Pipelines +installation **1179244** and AppVeyor installation **1178482** each used **Only +select repositories**, with exactly one selected repository: +`stadub/PowershellScripts`. GitHub requires at least one selected repository, so +removing the final selection could not be saved. Each single-repository installation +was therefore uninstalled. Both confirmation dialogs explicitly identified **1 +repository**. No installation covering other repositories was removed or modified. + +Afterward, the repository's Installed GitHub Apps page no longer listed either +Azure Pipelines/Microsoft or AppVeyor. Codecov, GitHub Learning Lab and Vercel +remained. The two remaining repository webhooks (Read the Docs and CodeFactor) +were unchanged. No Azure/AppVeyor required contexts existed to remove. GitHub +Actions, component PR states and Gallery environment/secret settings were unchanged. + +GitHub documents repository selection and uninstall behavior in +[reviewing and modifying installed GitHub Apps](https://docs.github.com/en/apps/using-github-apps/reviewing-and-modifying-installed-github-apps). + +## Repository files + +Removed these four Azure pipeline definitions: + +- `azure-pipelines.yml` +- `7Zip/azure-pipelines.yml` +- `Bookmarks/azure-pipelines.yml` +- `Currency-Conv/azure-pipelines.yml` + +Removed Azure status badges from the source READMEs for 7Zip, Bookmarks, +Currency-Conv, FolderEncoder, Base64String and Pipe. Removed both Azure and AppVeyor +badges from `Bookmarks/out/README.md`; no packaged executable/module bytes changed. +AppVeyor YAML had already been removed by the separately approved PR #33. + +Historical audit files and terminal demo recordings retain service names as +historical evidence. Packaging tests retain dummy Azure YAML fixtures to verify +that CI files cannot enter a Gallery package. These are not active integrations. +No fake replacement success badge was added. File changes are on the automation +branch in PR #31, pending integration; master and other worktrees were not edited. + +## External definitions remain inaccessible + +Public reads verified that Azure definition IDs **3 Bookmarks**, **4 7Zip**, +**5 Currency-Conv** and **6 SharedFunctions** belong exactly to this repository. +All four reported `queueStatus: enabled` with CI/PR triggers before disconnection. +The Azure browser was signed out; the owner confirmed no access. Their definitions, +service connections and build histories could not be disabled or deleted inside +Azure DevOps. The GitHub installation/access used by that integration is removed. +Microsoft documents that [disabled processing prevents new runs and triggers](https://learn.microsoft.com/en-us/azure/devops/pipelines/customize-pipeline#pipeline-settings), +which is distinct from the GitHub disconnection performed here. + +AppVeyor public metadata still lists four projects for this repository: + +| ID | Name | Slug | +| --- | --- | --- | +| 584025 | Bookmarks | powershellscripts | +| 607276 | 7Zip | powershellscripts-yvvt0 | +| 607412 | Currency-Conv | powershellscripts-7m2fk | +| 610315 | SharedFunctions | powershellscripts-v9ncj | + +AppVeyor was signed out; its GitHub login requested an OAuth grant, which was +cancelled. No new grant was approved and no integration was reinstalled. Public +metadata cannot prove that internal schedules/manual builds are disabled. Those +projects remain inaccessible to this task. No external project history was deleted. + +## Historical result removal limitation + +GitHub's supported [Checks API](https://docs.github.com/en/rest/checks) and +[commit status API](https://docs.github.com/en/rest/commits/statuses) provide no +repository operation to delete individual external check runs/suites or commit +statuses. Uninstalling an app revokes its access but does not delete the results +already attached to older commits. Therefore those historical Azure/AppVeyor +results were **not deleted**. No statuses were rewritten to success, and no +GitHub Actions runs, logs, artifacts or reports were deleted. There were no tracked +NUnit/TRX/test-result files in this checkout to remove. + +A normal cleanup commit provides a new PR head. The post-push read of cleanup SHA +`ffbb518d50f0aa8668000db25bcf5085d0d09993` found only GitHub Actions check runs, +zero Azure/AppVeyor check runs and zero commit statuses. This is a point-in-time +observation; inaccessible vendor-side schedules cannot be verified. Other PRs +with unchanged old head SHAs can still +show their historical external results. Do not rewrite those branches solely to +hide history. Check the actual replacement Actions results independently: six +component repairs were subsequently merged into their development branches with +explicit owner approval; see [integration evidence](../../ci-component-merges.json). +Removal of obsolete services alone did not resolve those source defects. + +See [sanitized scope and settings evidence](audit.json). The earlier +[AppVeyor audit](../appveyor-cutover/README.md) predates this explicitly authorized +live GitHub removal; its historical snapshots are preserved. diff --git a/docs/ci/legacy-ci-removal/audit.json b/docs/ci/legacy-ci-removal/audit.json new file mode 100644 index 0000000..4ff9cf2 --- /dev/null +++ b/docs/ci/legacy-ci-removal/audit.json @@ -0,0 +1,178 @@ +{ + "date": "2026-11-12", + "repository": "stadub/PowershellScripts", + "pipelinesBefore": [ + { + "id": 3, + "name": "Bookmarks", + "queueStatus": "enabled", + "repository": "stadub/PowershellScripts", + "repositoryType": "GitHub", + "yamlPath": "/Bookmarks/azure-pipelines.yml", + "triggerTypes": [ + "continuousIntegration", + "pullRequest" + ] + }, + { + "id": 4, + "name": "7Zip", + "queueStatus": "enabled", + "repository": "stadub/PowershellScripts", + "repositoryType": "GitHub", + "yamlPath": "/7Zip/azure-pipelines.yml", + "triggerTypes": [ + "continuousIntegration", + "pullRequest" + ] + }, + { + "id": 5, + "name": "Currency-Conv", + "queueStatus": "enabled", + "repository": "stadub/PowershellScripts", + "repositoryType": "GitHub", + "yamlPath": "/Currency-Conv/azure-pipelines.yml", + "triggerTypes": [ + "continuousIntegration", + "pullRequest" + ] + }, + { + "id": 6, + "name": "SharedFunctions", + "queueStatus": "enabled", + "repository": "stadub/PowershellScripts", + "repositoryType": "GitHub", + "yamlPath": "azure-pipelines.yml", + "triggerTypes": [ + "continuousIntegration", + "pullRequest" + ] + } + ], + "removedYaml": [ + "azure-pipelines.yml", + "7Zip/azure-pipelines.yml", + "Bookmarks/azure-pipelines.yml", + "Currency-Conv/azure-pipelines.yml" + ], + "removedBadgeFrom": [ + "7Zip/README.md", + "Bookmarks/README.md", + "Currency-Conv/README.md", + "FolderEncoder/README.md", + "Shared-Functions/Base64String/README.md", + "Shared-Functions/Pipe/README.md", + "Bookmarks/out/README.md" + ], + "hooksBefore": [ + { + "id": 104335530, + "name": "web", + "active": true, + "host": "readthedocs.org" + }, + { + "id": 128539623, + "name": "web", + "active": true, + "host": "www.codefactor.io" + } + ], + "externalChange": "Azure Pipelines installation1179244 and AppVeyor installation1178482 uninstalled after verifying each selected only stadub/PowershellScripts", + "historicalChecks": "Preserved; no synthetic status success or result deletion", + "githubAppsBefore": [ + "AppVeyor", + "Azure Pipelines", + "Codecov", + "GitHub Learning Lab", + "Vercel" + ], + "githubAppsAfter": [ + "Codecov", + "GitHub Learning Lab", + "Vercel" + ], + "singleRepositoryConfirmation": "Each uninstall confirmation explicitly identified 1 repository", + "removedAppveyorBadgeFrom": [ + "Bookmarks/out/README.md" + ], + "remainingExternalAccess": "Owner reports no Azure DevOps or AppVeyor access; internal definitions, service connections and build history not changed", + "appveyorProjectsAfterDisconnect": [ + { + "projectId": 584025, + "accountName": "stadub", + "name": "Bookmarks", + "slug": "powershellscripts", + "repositoryName": "stadub/PowershellScripts", + "repositoryType": "gitHub", + "skipBranchesWithoutAppveyorYml": false, + "isDisabled": null + }, + { + "projectId": 610315, + "accountName": "stadub", + "name": "SharedFunctions", + "slug": "powershellscripts-v9ncj", + "repositoryName": "stadub/PowershellScripts", + "repositoryType": "gitHub", + "skipBranchesWithoutAppveyorYml": false, + "isDisabled": null + }, + { + "projectId": 607412, + "accountName": "stadub", + "name": "Currency-Conv", + "slug": "powershellscripts-7m2fk", + "repositoryName": "stadub/PowershellScripts", + "repositoryType": "gitHub", + "skipBranchesWithoutAppveyorYml": false, + "isDisabled": null + }, + { + "projectId": 607276, + "accountName": "stadub", + "name": "7Zip", + "slug": "powershellscripts-yvvt0", + "repositoryName": "stadub/PowershellScripts", + "repositoryType": "gitHub", + "skipBranchesWithoutAppveyorYml": false, + "isDisabled": null + } + ], + "hooksAfter": [ + { + "id": 104335530, + "name": "web", + "active": true, + "host": "readthedocs.org" + }, + { + "id": 128539623, + "name": "web", + "active": true, + "host": "www.codefactor.io" + } + ], + "resultRemoval": { + "supportedDeleteEndpoint": false, + "externalHistoricalChecksDeleted": false, + "actionsRunsOrArtifactsDeleted": false, + "syntheticStatusesPosted": false, + "docs": [ + "https://docs.github.com/en/rest/checks", + "https://docs.github.com/en/rest/commits/statuses" + ] + }, + "postRemovalCommitObservation": { + "sha": "ffbb518d50f0aa8668000db25bcf5085d0d09993", + "observedCheckApps": [ + "github-actions" + ], + "observedExternalCheckRuns": 0, + "observedExternalStatuses": 0, + "masterShaUnchanged": "ff8210dad4b29e6d3e2ff66e3374d3a6acd272df", + "observation": "Point-in-time read after first push following both GitHub app removals; future external schedules cannot be verified without vendor access" + } +} diff --git a/docs/release-pipeline.md b/docs/release-pipeline.md new file mode 100644 index 0000000..22c733b --- /dev/null +++ b/docs/release-pipeline.md @@ -0,0 +1,411 @@ +# Tested releases and protected PowerShell Gallery publication + +This is automation for issue #29, not a deployment of the #22 fix. #22 stays open. +No live Gallery upload, GitHub release creation, issue mutation, secret edit, master +edit, or existing sibling worktree edit was performed by this task. The separately +authorized Base64String release preparation is recorded in +[the 1.3.0 snapshot report](releases/base64string-1.3.0.md). + +## Ownership and integration + +`ci/release-pipeline` selectively reuses the routing/runner from the read-only +`github-actions-ci` worktree and configuration/staging/preflight checks from the +read-only `psgallery-deploy` worktree. The sibling files were uncommitted and have +continued owner activity: merge this integrated implementation deliberately, not +both its workflow and the sibling `publish-gallery.yml`. Preserve the five publication +routes and Gallery account ownership. Public usernames and the module-to-account +mapping live in `scripts/gallery/Get-ReleaseConfig.ps1`; API keys live in separate +protected environment secrets. The selected key alone is passed to the upload +process as `PSGALLERY_API_KEY`. Do not merge a duplicate sibling publishing workflow. + + +The owner subsequently explicitly authorized removing Azure DevOps and AppVeyor. +Both GitHub app installations were removed after verifying each selected only this +repository. This branch removes the four remaining Azure YAML definitions and +obsolete Azure/AppVeyor badges; the approved AppVeyor YAML deletion is preserved. +The owner lacks external service access, so internal definitions/history remain. +GitHub provides no supported individual deletion for their historical check/status +results. See [exact removal and limitations](ci/legacy-ci-removal/README.md). +Only require `CI status` after a real hosted run succeeds on each maintained branch. + +## Inputs and behavior + +Run `release-gallery.yml` manually. Select a module from the dropdown and enter +its prepared stable version number, such as `1.3.0`. No commit SHA is required in +the form. The workflow resolves the configured reviewed release branch once to a +full immutable SHA, records it in the run summary, and passes that exact SHA to +every checkout, test, release, publication, verification and issue-completion job. +The entered version must match both reviewed source and out/ manifests; entering a +new number does not silently rewrite an unreviewed package. Development is never +a publication fallback. The configured sources are: + +| Module | Release branch | Package directory | +| --- | --- | --- | +| Bookmarks | Bookmarks/release/latest | Bookmarks/out | +| 7zip-Archive | 7-Zip/release/1.1 | 7Zip/out | +| Currency-Conv | Currency-Conv/release/1.5 | Currency-Conv/out | +| Base64String | base64String/release/latest | Shared-Functions/Base64String/out | +| Pipe | Pipe/release/latest | Shared-Functions/Pipe/out | + +These are literal Git branch names. The owner clarified that GitHub's +`/releases/latest` is a release URL alias, not a requirement to create branches +ending in latest. The 7Zip/Currency routes therefore use their verified reviewed +numbered refs. The existing Bookmarks/Pipe/Base64 branches named latest are real +branches and remain valid preparation sources. The GitHub URL alias is repository-wide; +the versioned release tag and recorded SHA identify the individual module package. + +`PackagePath` follows one rule for every configured module: +**/out** within the reviewed release snapshot. The nested +Shared-Functions prefix remains part of Base64String's and Pipe's source layout. +Staging never falls back to source files beside out/ when a package is missing. + +The historical numbered 7Zip and Currency-Conv snapshots used their module +directories directly. Their configured snapshots must instead contain reviewed +`7Zip/out` and `Currency-Conv/out` packages with matching source/manifest bytes. +Preparing those release snapshots remains a rollout prerequisite; this automation +change does not generate or commit release artifacts into development source. +No new latest branch is required solely because of GitHub's release URL alias. + +### Gallery accounts and credential setup + +Live public package pages checked on 2026-11-11 list these **Owners**, rather than +relying on the module manifest's Author field: + +| Module | Gallery owner / configured deployment account | Environment secret | +| --- | --- | --- | +| [Bookmarks](https://www.powershellgallery.com/packages/Bookmarks/3.0.1) | Stadub | PSGALLERY_API_KEY_STADUB | +| [7zip-Archive](https://www.powershellgallery.com/packages/7zip-Archive/1.1.0) | Stadub | PSGALLERY_API_KEY_STADUB | +| [Currency-Conv](https://www.powershellgallery.com/packages/Currency-Conv/1.0.2) | Stadub | PSGALLERY_API_KEY_STADUB | +| [Base64String](https://www.powershellgallery.com/packages/Base64String/1.2.0) | MiniModules | PSGALLERY_API_KEY_MINIMODULES | +| [Pipe](https://www.powershellgallery.com/packages/Pipe/1.0.0) | MiniModules | PSGALLERY_API_KEY_MINIMODULES | + +Usernames are public configuration, not secrets. Each module names its +`GalleryAccount`; the account-to-secret-name table in the same script supplies +`GallerySecret`. Neither account nor secret name is a dispatch input. A trusted, +credential-free step resolves the module's account and secret name, and the upload +step uses `secrets[steps.account.outputs.secret]`. It receives only that key as +`PSGALLERY_API_KEY` and the configured username as `PSGALLERY_ACCOUNT`. The helper +rejects an absent/mismatched username or absent key; there is no generic-key or +other-account fallback. Reviewable job summaries record account/secret **names**, +never values. Dry-runs and non-upload steps never receive either API key. + +The owner opens repository Settings -> Environments -> powershell-gallery -> +Environment secrets -> Add environment secret and creates both named secrets, +using a Gallery key generated while signed into the corresponding account. Scope +the Stadub key to its three packages and the MiniModules key to its two packages, +with suitable push/update permissions and expiry. Do not replace one account's key +when deploying another module. The previous generic `PSGALLERY_API_KEY` environment +secret is not read by this workflow and need not be configured. + +Preserve master-only deployment restrictions and configure independent reviewers +as described below. Metadata inspection on 2026-11-12 found both named secrets +present (updated 2026-11-11); no secret value was accessed or changed by this task. +Presence does not verify a key's validity. Public owner lookup confirms the +mapping, not the identity or permissions of a secret's opaque API key. Gallery +itself authenticates that key at upload. Publish-Module authenticates through the +API key; a username or manifest Author field cannot switch accounts. +See [Microsoft's ownership rules](https://learn.microsoft.com/en-us/powershell/gallery/how-to/publishing-packages/managing-package-owners?view=powershellget-3.x) +and [scoped API key setup](https://learn.microsoft.com/en-us/powershell/gallery/how-to/managing-profile/creating-apikeys?view=powershellget-3.x). + +### Set or rotate the keys from your terminal + +`scripts/gallery/Set-GalleryApiKey.ps1` creates or updates the correct environment +secret for a selected module, using the same trusted account mapping as deployment. +Authenticate GitHub CLI to github.com with an account allowed to manage this +repository's environment secrets, then run: + +```powershell +gh auth login --hostname github.com +# Preview the exact target: no GitHub request, prompt or secret update. +./scripts/gallery/Set-GalleryApiKey.ps1 -Module Base64String -WhatIf +# gh prompts for the MiniModules Gallery API key with input hidden. +./scripts/gallery/Set-GalleryApiKey.ps1 -Module Base64String +# gh prompts for the Stadub Gallery API key with input hidden. +./scripts/gallery/Set-GalleryApiKey.ps1 -Module Bookmarks +``` + +The MiniModules key is shared by Base64String/Pipe; the Stadub key is shared by +Bookmarks/7zip-Archive/Currency-Conv. Rotating one updates that account's credential +for all its mapped modules. The GitHub login and Gallery account are separate +identities: enter the Gallery account's publishing key, not a GitHub token. +`-Repository owner/repo` can explicitly select another repository; the default is +`stadub/PowershellScripts`. Secret names and the environment cannot be overridden. + +The helper checks that the environment already exists and permits only master, +then invokes `gh secret set` with `--env powershell-gallery` and the mapped name. +It does not create environments or alter reviewer/branch protection. GitHub CLI +owns the hidden prompt (or stdin) and local encryption; the key is never a script +parameter, command argument, environment variable, file or printed output. +Afterward the helper reads only secret metadata (name/update time). GitHub does +not return secret values, so this cannot verify Gallery key identity/permissions. +A failed metadata check after a successful update is reported distinctly. +No workflow is dispatched, release created, package published or issue completed. + +See [the official gh secret set manual](https://cli.github.com/manual/gh_secret_set). +No real secret was set while implementing or testing this helper; its tests use a +fixture command and the real helper was invoked only with `-WhatIf`. + +After integration into master and preparation of a tested release snapshot, open +Actions -> Tested release and protected Gallery deployment -> Run workflow. Select +master, module and prepared version number. Start with dry_run=true and +create_release=false. Inspect the resulting package/tests, optionally create the +GitHub release with create_release=true while retaining dry_run=true, and only +when actual deployment is authorized choose dry_run=false and approve its protected +environment. Configuring a secret does not itself trigger a deployment. + +The manual form appears only after the workflow is integrated into the default +branch (`master`). A branch-only workflow does not expose the Run workflow form. +See [GitHub's manual workflow documentation](https://docs.github.com/en/actions/how-tos/manage-workflow-runs/manually-run-a-workflow). +The form contains: + +- **Module to release**: Bookmarks, 7zip-Archive, Currency-Conv, Base64String or Pipe. +- **Prepared version number**: for example, `1.3.0`. +- **Also create the GitHub release during a dry-run**: unchecked by default. +- **Validate only; uncheck to publish to PowerShell Gallery**: checked by default. + +`dry_run=true` (default) prevents Gallery publication and issue completion. +`create_release=false` (default) also prevents GitHub release creation. A release-only +run explicitly sets `create_release=true`, retaining `dry_run=true`. Any mutation +requires dispatch from master. Setting `dry_run=false` creates/verifies the tested +GitHub release first, then requests the protected environment before upload. +Concurrency serializes each module, and never cancels an active publish. + +Staging copies only allowed flat package files plus LICENSE from the immutable +snapshot. The workflow independently regenerates output with New-ReleaseOutput.ps1 +and checks its staged hashes against the committed package. It does not recover +historical PSM-Release.ps1 or silently replace stale committed output. Every staged script, +module and manifest must match the corresponding source bytes (flattened names +must be unique). Source/package divergence blocks release. Reconcile known Pipe +and Bookmarks helper/manifest differences in their component release reviews. + +The same staged artifact is tested on Windows PowerShell 5.1 and pwsh on Windows, +Linux and macOS (7zip-Archive runtime suites remain Windows-only). Tests use pinned +Pester 4.10.1. Source suites run separately against an installed copy, imported by +absolute manifest path; suite files never enter the publish payload. Pipe runs its source Pester suites when present, with manifest checks on older +snapshots without suites. CI now covers all eight formal modules; this expansion +does not add publication routes. See the coverage table below. + +Release tags are `-v` at the tested SHA, with `package.tar.gz` and +`evidence.json` assets. No automatic closing keywords appear in release notes. +An existing tag must resolve to the same SHA; existing release evidence and archive +bytes must match. Missing/changed assets fail rather than being overwritten. +Do not retarget tags or edit release assets after approval. Repository admins can +still alter GitHub tags/assets unless repository release immutability/rules are +configured separately; hash checks detect mismatches on rerun. + +Only the actual upload step receives the environment secret. CI, staging, tests, +release creation, Gallery verification and issue completion receive no API key. +Upload preflight rejects existing/superseded versions and fails closed on lookup +errors. It calls Publish-Module, not an unofficial Gallery upload endpoint. + +After actual upload success a fresh job queries and downloads the **exact** version +from PSGallery, retries visibility up to six times, checks all payload hashes, and +runs manifest/import/export and installed regression checks. Only Gallery-generated +PSGetModuleInfo.xml is excluded from the comparison. A different visible package, +missing version, download error, hash change, or failed regression blocks completion. +The `gallery-verification` artifact and run log contain verification evidence. + +## Populate a missing or stale out/ package + +`New-ReleaseOutput.ps1` builds the five configured packages from source; it does +not publish, change versions, recover release-only fixes or overwrite old output. +Prepare the module's reviewed release branch first. For Base64String, selectively +port the already-reviewed #22 fix and regression suite from development, choose an +unused version and update source manifest/release notes. For 7Zip/Currency-Conv, +prepare their configured reviewed numbered release sources first. +Do not generate a package from old master source and call it the fixed release. + +Run the helper from this automation checkout with a separate reviewed release +checkout as input. This example uses Base64String; version 1.3.0 is illustrative +and must be checked against Gallery before choosing it: + +```powershell +$releaseRoot = '/path/to/reviewed-release-checkout' +$version = '1.3.0' # Must match that checkout's updated source manifest. +$candidate = Join-Path ([IO.Path]::GetTempPath()) "base64-candidate-$([guid]::NewGuid())" +$stage = Join-Path ([IO.Path]::GetTempPath()) "base64-stage-$([guid]::NewGuid())" +./scripts/gallery/New-ReleaseOutput.ps1 -Module Base64String -SourceRoot $releaseRoot -OutputRoot $candidate -ExpectedVersion $version +./scripts/gallery/Build-GalleryPackage.ps1 -Module Base64String -SourceRoot $candidate -OutputRoot $stage -ExpectedVersion $version +./scripts/gallery/Assert-SourcePackage.ps1 -Module Base64String -SourceRoot $releaseRoot -PackageRoot $stage +./scripts/gallery/Test-ReleasePackage.ps1 -Module Base64String -SourceRoot $releaseRoot -PackageRoot $stage -ExpectedVersion $version +``` + +The generated folder is `$candidate/Shared-Functions/Base64String/out`. Compare it +with the release checkout's existing out/ folder. Review every source/manifest, +README, icon and license change; replace that checkout's entire old out/ with the +generated folder after review (do not overlay and retain obsolete files). Stage +and commit the reviewed source/version/tests and out/ changes on the configured +release branch. Push the reviewed commit, then select its module and version in a +manual dry-run. Confirm the automatically resolved SHA in the run summary matches +the reviewed commit; later jobs reuse that immutable value. +Windows tests remain hosted workflow gates, even when local checks succeed. + +The helper flattens runtime scripts into the established flat package layout, +requires unique filenames, preserves source/manifest bytes, includes README, +primary icon and explicit module LICENSE (repository LICENSE only as a fallback), +and excludes tests, CI files, old out/ and +source assets other than the primary icon. Missing dependencies and ambiguous +filenames fail validation before a destination package is created. If the source +requires a different runtime layout, reconcile that layout in a separate reviewed +source/packaging change; the generator does not rewrite manifests or script paths. + +The release workflow still requires a committed, reviewable out/ package. It also +regenerates output independently from the same immutable source and verifies that +the staged files match the committed package's hashes. This catches stale or extra +package files and produces reproducible file contents, without making development +source a fallback deployment input. Use a new output root for each generation; +existing directories are never deleted or overwritten by the helper. + +## CI coverage for all modules + +The user subsequently requested CI for all modules. Master, automation branches +and unknown feature branches now select all eight modules (22 OS/module jobs). +Module development branches and PR targets select their own module; changed source +in another component adds its coverage. Repository-wide runs pin maintained +development commits for unchanged modules and test changed modules at the proposal +SHA. Every job records its source identity; see [build repairs and source selection](ci-build-repairs.md). Existing +7zip-Archive runtime suites remain Windows-only; all other entries run pwsh on +Windows, Linux and macOS. The release workflow's publication choices remain five. + +| Module | CI checks | +| --- | --- | +| Bookmarks | Existing source Pester suites | +| 7zip-Archive | Existing source Pester suites, Windows | +| Currency-Conv | Existing source Pester suites | +| Base64String | Existing source Pester suites | +| Pipe | Manifest validation and source Pester suites when available | +| FolderEncoder | Parse source scripts/manifests, validate manifest, import, require exported commands; run source Pester suites when added | +| Shell-Functions | Parse source scripts/manifests, validate manifest, import, require exported commands; run source Pester suites when added | +| Uninstall | Parse/import standalone Uninstall.psm1, verify exported Uninstall-Application command and SoftwareName/Application parameter contract; run Uninstall*.Tests.ps1 when added | + +The three new modules currently have no functional Pester suites. Their checks +produce NUnit-compatible structure reports on success and failure. Uninstall's +smoke checks never invoke its command, access HKLM, start msiexec, or uninstall +software. This checks its loadable public API, not Windows uninstall behavior. + +Local real-source checks: Uninstall passes on macOS pwsh 7.7.0; FolderEncoder fails +because Functions.ps1 is missing; Shell-Functions fails because its manifest imports +an empty module with no exported commands. These are pre-existing module defects, +not successful test runs or allow-failure exceptions. They will block aggregate CI +until repaired through the module development branches. No module implementation +or manifest was modified as part of this expansion. The three development branch +source trees still match this worktree's source at inspection. + +EXportGithub, Git-Functions and shared infrastructure are the other three inventory +components, not formal modules. They do not get invented module entries. All-module +CI still runs on their branches through the default routing. Gallery automation +and issue-completion mappings are unchanged. + +## Trusted issue completion + +`complete-issues` alone has `issues: write`. It requires successful actual upload +and successful verification outputs in this same workflow. No merge, PR event, +release event, dry-run, failure, cancellation or skipped job closes issues. It runs +trusted master automation only and executes no package code. Its JSON mapping is +`scripts/gallery/issue-map.json`. The prepared Base64String 1.3.0 entry maps only +its exact tested release SHA to #22; #29 remains outside automatic completion. +No dispatch input accepts issue numbers. Example **schema only**, not active data: + +```json +[ + { + "repository": "stadub/PowershellScripts", + "module": "Base64String", + "version": "REVIEWED_NEW_VERSION", + "sourceSha": "REVIEWED_FULL_RELEASE_SHA", + "issues": [22] + } +] +``` + +Review the committed exact mapping on master **before** publishing. Do not map #29 unless +its broader rollout work is also complete. The issue comment records the versioned +Gallery URL, immutable source SHA, GitHub release link and verification workflow +run/artifact. A stable per-package marker prevents duplicate bot comments; closing +an already closed issue is a no-op. If interrupted between comment and close, +retry completes the close without duplicating evidence. PR numbers are rejected. + +If upload succeeded but verification/closure failed, use GitHub's **re-run failed +jobs** to retry downstream work without uploading again. Re-running all jobs will +reject an existing Gallery version and cannot falsely report another actual upload. +Do not bypass that guard or close manually without verifying deployment evidence. + +## Owner rollout and remaining blockers + +1. Integrate automation into master and port read-only CI automation to maintained + module branches. Run hosted CI and a full production dry-run before enabling required status + checks. The prepared Base64String snapshot now has passing hosted validation; + the production manual workflow still needs default-branch integration. +2. For #22, the reviewed fix is commit + `5fe9e2344afacccd4cebe02f178d6eb8cd162d2f`, merged by PR #28 into + `base64tring/develop` at `4d2e1c86e8083202f74b9b31c48447c0cd82808e`. + Do not redo it. Selectively port reviewed files/tests to + `base64String/release/latest`, choose an unused version, update release notes, + and regenerate/review out/ with matching implementation and manifest bytes. + This preparation is now complete for 1.3.0: PR #30 integrated the reviewed source, + version, owner-confirmed WTFPL license and regenerated out/; PR #32 added the + Windows/.NET Framework padding follow-up through development; PR #34 fixed + checkout line endings. The prepared release tip is + `6d30dbc22de8bfb8bccda5cd3880ffb9a6655f5f`. + See [exact snapshot evidence](releases/base64string-1.3.0.md). +3. Review and integrate the exact issue mapping from PR #31 into master. Run a + Base64String 1.3.0 dry-run and verify the resolved SHA matches the prepared + snapshot above. Review source and installed NUnit artifacts, + including both Windows runtimes. Then optionally create the GitHub release with + `create_release=true,dry_run=true` and review its snapshot/assets. +4. Preserve `powershell-gallery` environment's custom deployment branch policy: + **master only**, branch type, no tag wildcard. Live inspection on 2026-11-12 found + one such policy, no reviewer rule and admin bypass enabled. + Do not treat master-only as independent reviewer approval. The owner should add + required reviewers, prevent self-review and restrict admin bypass as available. + This repository is public, so GitHub documents required-reviewer support here. + On private repos, plan restrictions can make reviewers/wait timers unavailable + (Free/Pro/Team support them only on public repos). A sole owner cannot provide + an independent approval with self-review disabled; arrange a second trusted + reviewer or document that organizational limitation before deployment. +5. Both **environment** secret names `PSGALLERY_API_KEY_STADUB` and + `PSGALLERY_API_KEY_MINIMODULES` are present as of 2026-11-12. The owner must verify + their account, package scope and expiry; rotate through settings or the helper if needed. + Never print/paste their values into code, logs, chat, issue comments or command + arguments. Use each account's scoped Gallery key with appropriate package rights + and expiry. Nothing here creates or changes secrets. +6. Only an explicitly authorized deployment run should set `dry_run=false` on + master. Approve its environment after reviewing run SHA, version and hashes. + Confirm Gallery verification and mapped issue evidence afterward. This task + authorizes implementation, not that live upload. + +## Local validation + +Tools: `/tmp/ps-actions-tools/powershell/pwsh` 7.7.0, Pester 4.10.1 from +`/tmp/ps-actions-tools/modules`, actionlint 1.7.12 at +`/tmp/ps-actions-tools/actionlint/actionlint`. + +```sh +/tmp/ps-actions-tools/actionlint/actionlint .github/workflows/*.yml +# Run each test in a fresh PowerShell process (the tests mock commands offline). +pwsh -NoProfile -NonInteractive -File tests/Test-CiSelection.ps1 +pwsh -NoProfile -NonInteractive -File tests/Test-CiSources.ps1 +pwsh -NoProfile -NonInteractive -File tests/Test-CiRunner.ps1 +pwsh -NoProfile -NonInteractive -File tests/Test-CiStructure.ps1 +pwsh -NoProfile -NonInteractive -File tests/Test-GalleryAutomation.ps1 +pwsh -NoProfile -NonInteractive -File tests/Test-ReleaseSelection.ps1 +pwsh -NoProfile -NonInteractive -File tests/Test-GalleryKeySetup.ps1 +pwsh -NoProfile -NonInteractive -File tests/Test-ReleaseOutput.ps1 +pwsh -NoProfile -NonInteractive -File tests/Test-ReleaseEvidence.ps1 +pwsh -NoProfile -NonInteractive -File tests/Test-GalleryVerification.ps1 +node tests/Test-IssueCompletion.cjs +node tests/Test-WorkflowSafety.cjs +node tests/Test-ReleaseCreation.cjs +``` + +All these automation contract checks passed locally. A temporary fixture extracted from the already +committed fix, packaged by New-ReleaseOutput.ps1 and staged by Build-GalleryPackage.ps1, +also passed source and installed regressions separately: **31 + 31**, macOS pwsh 7.7.0/Pester 4.10.1. This validates +runner behavior, not an actual release branch, Gallery download, or Windows run. +Windows 5.1/pwsh and hosted cross-platform tests remain deployment gates. + +Official references consulted: +- [GitHub environment protection and plan limitations](https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments) +- [PowerShell Gallery publishing](https://learn.microsoft.com/en-us/powershell/scripting/gallery/how-to/publishing-packages/publishing-a-package) +- [Publish-Module](https://learn.microsoft.com/en-us/powershell/module/powershellget/publish-module?view=powershellget-2.x) +- [Save-Module exact-version downloads](https://learn.microsoft.com/en-us/powershell/module/powershellget/save-module?view=powershellget-2.x) diff --git a/docs/releases/base64string-1.3.0-evidence.json b/docs/releases/base64string-1.3.0-evidence.json new file mode 100644 index 0000000..091d85a --- /dev/null +++ b/docs/releases/base64string-1.3.0-evidence.json @@ -0,0 +1,31 @@ +{ + "module": "Base64String", + "version": "1.3.0", + "sourceSha": "6d30dbc22de8bfb8bccda5cd3880ffb9a6655f5f", + "files": [ + { + "path": "Aliases.ps1", + "sha256": "9130AD1904843CEF13C309A83B9AF27C343A49F4A5332F208F49D3F48D7352AF" + }, + { + "path": "Base64String.ps1", + "sha256": "CC92D77B62190E1973C1CDCFC6794A0602656DA2FB4562539056B0E8F28AEB50" + }, + { + "path": "Base64String.psd1", + "sha256": "6A1B603AF12314129B129D871995825E2CD725EBBE21A9266FD4E6E6530150B2" + }, + { + "path": "Icon.ico", + "sha256": "B3046898594275A1E8FA3729E6105F6571DB0BB40E5340CBB6FFA9D9DA0678AB" + }, + { + "path": "LICENSE", + "sha256": "6FCB3400CC6126E54B9C5BE59BB396FD2CE4CD6D075EC559F0AA4171372307BE" + }, + { + "path": "README.md", + "sha256": "CCC70F20C04316407651BC6258F41D561737F52ACDA6E404F40B4AC2B5F9A4DD" + } + ] +} diff --git a/docs/releases/base64string-1.3.0-validation.json b/docs/releases/base64string-1.3.0-validation.json new file mode 100644 index 0000000..0097227 --- /dev/null +++ b/docs/releases/base64string-1.3.0-validation.json @@ -0,0 +1,76 @@ +{ + "module": "Base64String", + "version": "1.3.0", + "sourceSha": "6d30dbc22de8bfb8bccda5cd3880ffb9a6655f5f", + "artifacts": [ + { + "artifact": "candidate-macos-latest-pwsh", + "reports": [ + { + "report": "Base64String.xml", + "total": 34, + "failures": 0 + }, + { + "report": "installed-Base64String.xml", + "total": 34, + "failures": 0 + } + ], + "package_hashes_match": true, + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43086442317/artifacts/13886117879" + }, + { + "artifact": "candidate-ubuntu-latest-pwsh", + "reports": [ + { + "report": "Base64String.xml", + "total": 34, + "failures": 0 + }, + { + "report": "installed-Base64String.xml", + "total": 34, + "failures": 0 + } + ], + "package_hashes_match": true, + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43086442317/artifacts/13885953800" + }, + { + "artifact": "candidate-windows-latest-powershell", + "reports": [ + { + "report": "Base64String.xml", + "total": 34, + "failures": 0 + }, + { + "report": "installed-Base64String.xml", + "total": 34, + "failures": 0 + } + ], + "package_hashes_match": true, + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43086442317/artifacts/13887505451" + }, + { + "artifact": "candidate-windows-latest-pwsh", + "reports": [ + { + "report": "Base64String.xml", + "total": 34, + "failures": 0 + }, + { + "report": "installed-Base64String.xml", + "total": 34, + "failures": 0 + } + ], + "package_hashes_match": true, + "url": "https://github.com/stadub/PowershellScripts/actions/runs/43086442317/artifacts/13886971654" + } + ], + "workflowRun": "https://github.com/stadub/PowershellScripts/actions/runs/43086442317" +} diff --git a/docs/releases/base64string-1.3.0.md b/docs/releases/base64string-1.3.0.md new file mode 100644 index 0000000..2dd5de1 --- /dev/null +++ b/docs/releases/base64string-1.3.0.md @@ -0,0 +1,89 @@ +# Base64String 1.3.0 prepared release snapshot + +Prepared on 2026-11-11. This is a tested Git release snapshot, **not a Gallery +deployment**. Issues #22 and #29 remain open. No versioned GitHub release was created. + +- Release branch: `base64String/release/latest` +- Exact tested release commit: `6d30dbc22de8bfb8bccda5cd3880ffb9a6655f5f` +- Package path: `Shared-Functions/Base64String/out` +- Gallery account: `MiniModules`; required environment secret: `PSGALLERY_API_KEY_MINIMODULES` +- [Payload SHA256 evidence](base64string-1.3.0-evidence.json) +- [Downloaded-artifact verification](base64string-1.3.0-validation.json) +- [Successful exact-commit hosted run](https://github.com/stadub/PowershellScripts/actions/runs/43086442317) + +## Review and integration + +[PR #30](https://github.com/stadub/PowershellScripts/pull/30) selectively ported the +reviewed encoding/pipeline fix from PR #28, bumped the source/package version and +release notes, and populated out/. Its initial tests exposed a .NET Framework +padding difference: Windows PowerShell 5.1 accepted malformed `Zm8==`. + +[PR #32](https://github.com/stadub/PowershellScripts/pull/32) added an explicit +padding-shape guard through `base64tring/develop` (merge +`51b283c5da01fd5a962bbd9194a07a8bf24b5ce4`). It preserves all 31 original regressions +and adds three malformed-padding cases. The source-only validation passed all +four runtimes before the guard/tests were selectively ported into the release. + +The owner explicitly confirmed WTFPL. Source LICENSE, packaged LICENSE and both +manifest URLs now agree; the repository-wide BSD-2-Clause license is unchanged. +Existing license edits were preserved. Commit a3b8551 has an inaccurate padding-port +message: it recorded those license edits; 564a30c contains the actual guard port +and regenerated package. The history was not rewritten. Generation prefers the +module-local license, and staging never overwrites a package license with the root +fallback. Source/generated/staged WTFPL SHA256: +`6fcb3400cc6126e54b9c5be59bb396fd2ce4cd6d075ec559f0aa4171372307be`. + +Comparing the first passing release artifacts caught Windows CRLF conversion. +[PR #34](https://github.com/stadub/PowershellScripts/pull/34) added a Base64String-local +.gitattributes policy for LF text and binary images. The final exact release tip +was tested again after integration; all four artifacts now contain identical +payload bytes, not merely equivalent normalized text. + +## Final verification + +Pester is pinned to 4.10.1. Every job passed 34 source and 34 installed-package +regressions, manifest/import/export checks and independent regeneration/hash +comparison. Downloaded artifacts were checked against the payload hashes computed +from a fresh Git archive of the exact release commit. All six payload files agree +across platforms; all eight NUnit reports have 34 tests and zero failures. + +| Runtime | Source / installed tests | Package and test artifact | +| --- | --- | --- | +| Windows PowerShell 5.1 | 34 / 34 | [artifact](https://github.com/stadub/PowershellScripts/actions/runs/43086442317/artifacts/13887505451) | +| Windows pwsh | 34 / 34 | [artifact](https://github.com/stadub/PowershellScripts/actions/runs/43086442317/artifacts/13886971654) | +| Linux pwsh | 34 / 34 | [artifact](https://github.com/stadub/PowershellScripts/actions/runs/43086442317/artifacts/13885953800) | +| macOS pwsh | 34 / 34 | [artifact](https://github.com/stadub/PowershellScripts/actions/runs/43086442317/artifacts/13886117879) | + +## Remaining rollout gates + +The production manual workflow is not on master yet (contents lookup returned 404). +Automation [PR #31](https://github.com/stadub/PowershellScripts/pull/31) remains a draft; +its offline automation checks pass. The six component baseline repairs were merged +into their module development branches after explicit owner approval; see +[integration evidence](../ci-component-merges.json). Verify fresh maintained-source +CI before choosing required contexts. Integrate reviewed automation separately. +The owner's concurrent AppVeyor removal was +merged into master through PR #33; this task did not change master or sibling worktrees. + +After production workflow integration, run `release-gallery.yml` from master with: + +- module: `Base64String` +- version: `1.3.0` +- create_release: `false` +- dry_run: `true` + +No SHA entry is needed. Verify that the run summary automatically resolves +`base64String/release/latest` to the prepared +`6d30dbc22de8bfb8bccda5cd3880ffb9a6655f5f` snapshot. A different resolved tip +requires its own source/package validation and exact issue-map review. + +This full production dry-run is still pending; the successful runs above are its +credential-free source/package validation, not a simulated successful upload. +Both Gallery account secret names were present at the 2026-11-12 metadata check; +their opaque values, account rights and expiry remain unverified. Preserve the +environment's master-only branch policy and establish independent reviewer protection. +Any actual publish remains +separately authorized and must verify exact Gallery package/version/content before +issue completion. The trusted mapping in PR #31 targets only #22 for this version +and SHA; #29 is deliberately excluded. A GitHub release, dry-run or merge never +completes either issue. diff --git a/scripts/ci/Get-CiModuleConfig.ps1 b/scripts/ci/Get-CiModuleConfig.ps1 new file mode 100644 index 0000000..2844d46 --- /dev/null +++ b/scripts/ci/Get-CiModuleConfig.ps1 @@ -0,0 +1,17 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)] + [ValidateSet('Bookmarks','7zip-Archive','Currency-Conv','Base64String','Pipe','FolderEncoder','Shell-Functions','Uninstall')] + [string]$Module +) +$configs = @{ + Bookmarks = @{ SourcePath='Bookmarks'; DevelopmentBranch='Bookmarks/develop' } + '7zip-Archive' = @{ SourcePath='7Zip'; DevelopmentBranch='7Zip/develop' } + 'Currency-Conv' = @{ SourcePath='Currency-Conv'; DevelopmentBranch='Currency-Conv/develop' } + Base64String = @{ SourcePath='Shared-Functions/Base64String'; DevelopmentBranch='base64tring/develop' } + Pipe = @{ SourcePath='Shared-Functions/Pipe'; DevelopmentBranch='Pipe/develop' } + FolderEncoder = @{ SourcePath='FolderEncoder'; DevelopmentBranch='FolderEncoder/develop' } + 'Shell-Functions' = @{ SourcePath='Shell-Functions'; DevelopmentBranch='Shell-Functions/develop' } + Uninstall = @{ SourcePath='.'; DevelopmentBranch='Uninstall/develop' } +} +[pscustomobject]$configs[$Module] diff --git a/scripts/ci/Invoke-ModuleTests.ps1 b/scripts/ci/Invoke-ModuleTests.ps1 new file mode 100644 index 0000000..fb40514 --- /dev/null +++ b/scripts/ci/Invoke-ModuleTests.ps1 @@ -0,0 +1,54 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)] + [ValidateSet('Bookmarks', '7zip-Archive', 'Currency-Conv', 'Base64String', 'Pipe', 'FolderEncoder', 'Shell-Functions', 'Uninstall')] + [string]$Module, + [string]$SourceRoot +) + +$ErrorActionPreference = 'Stop' +$root = if ($SourceRoot) { (Resolve-Path $SourceRoot).Path } else { (Resolve-Path (Join-Path $PSScriptRoot '../..')).Path } +$config = & (Join-Path $PSScriptRoot 'Get-CiModuleConfig.ps1') -Module $Module +$modulePath = Join-Path $root $config.SourcePath + +if (-not (Test-Path $modulePath -PathType Container)) { + throw "Module directory missing on this branch: $modulePath" +} + +if ($Module -in 'FolderEncoder', 'Shell-Functions', 'Uninstall') { + & (Join-Path $PSScriptRoot 'Test-ModuleStructure.ps1') -Module $Module -SourceRoot $root + $suiteFilter = if ($Module -eq 'Uninstall') { 'Uninstall*.Tests.ps1' } else { '*.Tests.ps1' } + if (-not (Get-ChildItem -LiteralPath $modulePath -Filter $suiteFilter -File)) { + Write-Host "$Module structure/import checks passed; no functional Pester suite exists yet." + return + } +} + +if ($Module -eq 'Pipe') { + # Validate Pipe imports even on older branches without a Pester suite. + Test-ModuleManifest (Join-Path $modulePath 'Pipe.psd1') -ErrorAction Stop | Out-Null + if (-not (Get-ChildItem -LiteralPath $modulePath -Filter '*.Tests.ps1' -File)) { return } +} + +# Discover source suites beside the manifest, excluding packaged out/ copies. +$suiteFilter = if ($Module -eq 'Uninstall') { 'Uninstall*.Tests.ps1' } else { '*.Tests.ps1' } +$testPaths = @(Get-ChildItem -LiteralPath $modulePath -Filter $suiteFilter -File | + Sort-Object Name | Select-Object -ExpandProperty FullName) +if ($testPaths.Count -eq 0) { throw "No test files found for $Module" } + +# Existing suites use Pester 4 mocks and assertions; do not implicitly upgrade them. +if (-not (Get-Module -ListAvailable Pester | Where-Object Version -eq '4.10.1')) { + Install-Module Pester -RequiredVersion 4.10.1 -Scope CurrentUser -Force -SkipPublisherCheck +} +Import-Module Pester -RequiredVersion 4.10.1 -Force +$results = Join-Path $root 'TestResults' +New-Item $results -ItemType Directory -Force | Out-Null +$report = Join-Path $results "$Module.xml" +Push-Location $modulePath +try { + $result = Invoke-Pester -Script $testPaths -PassThru -OutputFile $report -OutputFormat NUnitXml + if ($result.TotalCount -eq 0) { throw "No tests discovered for $Module" } + if ($result.FailedCount -gt 0) { throw "$($result.FailedCount) tests failed for $Module" } +} finally { + Pop-Location +} diff --git a/scripts/ci/Resolve-CiSources.ps1 b/scripts/ci/Resolve-CiSources.ps1 new file mode 100644 index 0000000..8536d12 --- /dev/null +++ b/scripts/ci/Resolve-CiSources.ps1 @@ -0,0 +1,54 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)][string]$Branch, + [Parameter(Mandatory)][ValidatePattern('^[0-9a-f]{40}$')][string]$CurrentSha, + [Parameter(Mandatory)][AllowEmptyCollection()][hashtable]$RemoteRefs, + [string[]]$ChangedPaths = @() +) +$ErrorActionPreference = 'Stop' +$selected = (& "$PSScriptRoot/Select-CiModules.ps1" -Branch $Branch -NoGitHubOutput) | ConvertFrom-Json +$all = (& "$PSScriptRoot/Select-CiModules.ps1" -Branch master -NoGitHubOutput) | ConvertFrom-Json +$routed = @($selected.include.module | Select-Object -Unique) +$componentRun = $routed.Count -eq 1 +$changedModules = @() +foreach ($name in @($all.include.module | Select-Object -Unique)) { + $config = & "$PSScriptRoot/Get-CiModuleConfig.ps1" -Module $name + foreach ($item in $ChangedPaths) { + $path = $item.Replace('\','/') + if ($name -eq 'Uninstall') { + $matchesSource = $path -eq 'Uninstall.psm1' -or ($path -notlike '*/*' -and $path -like 'Uninstall*.Tests.ps1') + } else { + $prefix = "$($config.SourcePath)/" + $matchesSource = $path.StartsWith($prefix, [StringComparison]::OrdinalIgnoreCase) -and + -not $path.StartsWith("${prefix}out/", [StringComparison]::OrdinalIgnoreCase) -and + ([IO.Path]::GetExtension($path) -in '.ps1','.psm1','.psd1','.dll','.ps1xml','.xml' -or + [IO.Path]::GetFileName($path) -eq '.gitattributes') + } + if ($matchesSource) { $changedModules += $name; break } + } +} +# A source change outside a branch's usual component must not escape testing. +$entries = @($selected.include) +foreach ($name in $changedModules) { + if ($name -notin $routed) { $entries += @($all.include | Where-Object module -eq $name) } +} +$matrix = @( + foreach ($entry in $entries) { + $config = & "$PSScriptRoot/Get-CiModuleConfig.ps1" -Module $entry.module + $useSnapshot = ($componentRun -and $entry.module -in $routed) -or $entry.module -in $changedModules + $sha = if ($useSnapshot) { $CurrentSha } else { $RemoteRefs[$config.DevelopmentBranch] } + if ($sha -cnotmatch '^[0-9a-f]{40}$') { + throw "Missing or invalid immutable source ref for $($entry.module): $($config.DevelopmentBranch)" + } + [ordered]@{ + module=$entry.module + os=$entry.os + source_sha=$sha + source_ref=$(if ($useSnapshot) { 'workflow snapshot' } else { $config.DevelopmentBranch }) + source_mode=$(if ($useSnapshot) { 'snapshot' } else { 'development' }) + } + } +) +$json = @{include=$matrix} | ConvertTo-Json -Depth 5 -Compress +if ($env:GITHUB_OUTPUT) { "matrix=$json" >> $env:GITHUB_OUTPUT } +$json diff --git a/scripts/ci/Select-CiModules.ps1 b/scripts/ci/Select-CiModules.ps1 new file mode 100644 index 0000000..a651a68 --- /dev/null +++ b/scripts/ci/Select-CiModules.ps1 @@ -0,0 +1,31 @@ +[CmdletBinding()] +param([Parameter(Mandatory)][string]$Branch, [switch]$NoGitHubOutput) + +$ErrorActionPreference = 'Stop' +$modules = switch -Regex ($Branch) { + '^Bookmarks/|^fix/update-check-startup$' { 'Bookmarks'; break } + '^(7Zip|7-Zip)/|^fix/7zip-runtime-help$' { '7zip-Archive'; break } + '^Currency-Conv/|^fix/currency-cache-expiry$' { 'Currency-Conv'; break } + '^base64(tring|String)/|^fix/base64-encoding$' { 'Base64String'; break } + '^Pipe/' { 'Pipe'; break } + '^FolderEncoder/' { 'FolderEncoder'; break } + '^Shell-Functions/' { 'Shell-Functions'; break } + '^Uninstall/' { 'Uninstall'; break } + default { 'Bookmarks', '7zip-Archive', 'Currency-Conv', 'Base64String', 'Pipe', 'FolderEncoder', 'Shell-Functions', 'Uninstall' } +} +$entries = @( + foreach ($module in $modules) { + # The legacy 7Zip suite exercises Windows-specific runtime installation. + $platforms = if ($module -eq '7zip-Archive') { + @('windows-latest') + } else { + @('windows-latest', 'ubuntu-latest', 'macos-latest') + } + foreach ($platform in $platforms) { + @{ module = $module; os = $platform } + } + } +) +$matrix = @{ include = $entries } | ConvertTo-Json -Depth 4 -Compress +if ($env:GITHUB_OUTPUT -and -not $NoGitHubOutput) { "matrix=$matrix" >> $env:GITHUB_OUTPUT } +$matrix diff --git a/scripts/ci/Test-ModuleStructure.ps1 b/scripts/ci/Test-ModuleStructure.ps1 new file mode 100644 index 0000000..22c37a6 --- /dev/null +++ b/scripts/ci/Test-ModuleStructure.ps1 @@ -0,0 +1,71 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)][ValidateSet('FolderEncoder', 'Shell-Functions', 'Uninstall')][string]$Module, + [Parameter(Mandatory)][string]$SourceRoot +) +$ErrorActionPreference = 'Stop' +$root = (Resolve-Path $SourceRoot).Path +$entry = switch ($Module) { + FolderEncoder { Join-Path $root 'FolderEncoder/FolderEncoder.psd1' } + Shell-Functions { Join-Path $root 'Shell-Functions/Shell-Function.psd1' } + Uninstall { Join-Path $root 'Uninstall.psm1' } +} +$results = Join-Path $root 'TestResults' +New-Item $results -ItemType Directory -Force | Out-Null +$cases = [System.Collections.Generic.List[string]]::new() +$loaded = $null +function Add-Check([string]$Name, [scriptblock]$Action) { + $safeName = [Security.SecurityElement]::Escape("$Module.$Name") + try { + & $Action + $cases.Add("") + } catch { + $message = [Security.SecurityElement]::Escape($_.Exception.Message) + $cases.Add("$message") + throw + } +} +try { + Add-Check 'syntax' { + if (-not (Test-Path $entry -PathType Leaf)) { throw "Module entry missing: $entry" } + $files = if ($Module -eq 'Uninstall') { @(Get-Item $entry) } else { + @(Get-ChildItem (Split-Path $entry) -File -Recurse | Where-Object { + $_.Extension -in '.ps1', '.psm1', '.psd1' -and $_.FullName -notmatch '[/\\]out[/\\]' + }) + } + foreach ($file in $files) { + $tokens = $null; $parseErrors = $null + [System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref]$tokens, [ref]$parseErrors) | Out-Null + if ($parseErrors.Count) { throw "Syntax errors in $($file.Name): $($parseErrors.Message -join '; ')" } + } + } + if ($Module -ne 'Uninstall') { + Add-Check 'manifest' { Test-ModuleManifest $entry -ErrorAction Stop | Out-Null } + } + # Import into this script's local scope, then remove by module object in finally. + $loaded = Import-Module $entry -Force -PassThru -ErrorAction Stop + Add-Check 'exports' { + if ($loaded.ExportedCommands.Count -eq 0) { throw "$Module imports but exports no commands" } + if ($Module -eq 'Uninstall') { + $command = $loaded.ExportedFunctions['Uninstall-Application'] + if (-not $command -or -not $command.Parameters.ContainsKey('SoftwareName') -or + 'Application' -notin $command.Parameters['SoftwareName'].Aliases) { + throw 'Uninstall-Application command/parameter contract is missing' + } + # Never call this command: it accesses HKLM and starts msiexec. + } + } + Write-Host "$Module syntax, import and export checks passed." +} catch { + # Import failures must be represented in the uploaded report too. + if (-not ($cases | Where-Object { $_ -like '*success="False"*' })) { + $message = [Security.SecurityElement]::Escape($_.Exception.Message) + $cases.Add("$message") + } + throw +} finally { + if ($loaded) { Remove-Module $loaded -Force -ErrorAction SilentlyContinue } + $failures = @($cases | Where-Object { $_ -like '*success="False"*' }).Count + $xml = "$($cases -join '')" + $xml | Set-Content (Join-Path $results "$Module-structure.xml") -Encoding UTF8 +} diff --git a/scripts/gallery/Assert-SourcePackage.ps1 b/scripts/gallery/Assert-SourcePackage.ps1 new file mode 100644 index 0000000..76bae2d --- /dev/null +++ b/scripts/gallery/Assert-SourcePackage.ps1 @@ -0,0 +1,10 @@ +param([string]$Module, [string]$SourceRoot, [string]$PackageRoot) +$ErrorActionPreference = 'Stop' +$config = & "$PSScriptRoot/Get-ReleaseConfig.ps1" -Module $Module +$source = Join-Path $SourceRoot ($config.PackagePath -replace '/out$', '') +foreach ($file in Get-ChildItem (Join-Path $PackageRoot $Module) -File | Where-Object Extension -in '.ps1','.psm1','.psd1') { + $matches = @(Get-ChildItem $source -File -Recurse | Where-Object { $_.Name -eq $file.Name -and $_.FullName -notmatch '[/\\]out[/\\]' }) + if ($matches.Count -ne 1 -or (Get-FileHash $matches[0].FullName).Hash -ne (Get-FileHash $file.FullName).Hash) { + throw "Source/package divergence: $($file.Name). Reconcile and review before releasing." + } +} diff --git a/scripts/gallery/Build-GalleryPackage.ps1 b/scripts/gallery/Build-GalleryPackage.ps1 new file mode 100644 index 0000000..f5059f0 --- /dev/null +++ b/scripts/gallery/Build-GalleryPackage.ps1 @@ -0,0 +1,40 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)][string]$Module, + [Parameter(Mandatory)][string]$SourceRoot, + [Parameter(Mandatory)][string]$OutputRoot, + [Parameter(Mandatory)][version]$ExpectedVersion +) + +$ErrorActionPreference = 'Stop' +$config = & (Join-Path $PSScriptRoot 'Get-ReleaseConfig.ps1') -Module $Module +$source = Join-Path (Resolve-Path $SourceRoot).Path $config.PackagePath +$manifestPath = Join-Path $source $config.Manifest +if (-not (Test-Path $manifestPath -PathType Leaf)) { + throw "Release package is missing: $manifestPath. Run New-ReleaseOutput.ps1 against reviewed release source, test and commit its out/ output first." +} +$metadata = Import-PowerShellDataFile $manifestPath +if ([version]$metadata.ModuleVersion -ne $ExpectedVersion) { + throw "Expected $ExpectedVersion, but release manifest declares $($metadata.ModuleVersion)." +} +if ($metadata.PrivateData.PSData.Prerelease) { + throw 'This workflow currently supports stable manifest versions only.' +} + +$destination = Join-Path $OutputRoot $Module +if (Test-Path $destination) { throw "Output already exists: $destination. Use a fresh staging directory." } +New-Item $destination -ItemType Directory -Force | Out-Null +# These five release packages are flat. Never publish the monorepo, tests, CI, +# secrets, or nested build output by passing a module source tree wholesale. +$allowed = '.ps1', '.psm1', '.psd1', '.dll', '.xml', '.ps1xml', '.md', '.txt', '.ico', '.png' +Get-ChildItem $source -File | Where-Object { + ($_.Extension -in $allowed -or $_.Name -eq 'LICENSE') -and $_.Name -notmatch '\.(Tests?|SmokeTests)\.ps1$' +} | Copy-Item -Destination $destination +$license = Join-Path $SourceRoot 'LICENSE' +if (-not (Test-Path (Join-Path $destination 'LICENSE') -PathType Leaf) -and + (Test-Path $license -PathType Leaf)) { Copy-Item $license (Join-Path $destination 'LICENSE') } +Test-ModuleManifest (Join-Path $destination $config.Manifest) -ErrorAction Stop | Out-Null +Write-Host "Validated $Module $ExpectedVersion in $destination" +if ($env:GITHUB_STEP_SUMMARY) { + "Package: $Module $ExpectedVersion. Review gallery-package before publishing." >> $env:GITHUB_STEP_SUMMARY +} diff --git a/scripts/gallery/Complete-Issues.cjs b/scripts/gallery/Complete-Issues.cjs new file mode 100644 index 0000000..c7fd3ae --- /dev/null +++ b/scripts/gallery/Complete-Issues.cjs @@ -0,0 +1,28 @@ +// No package/source code executes in the issues:write job. +const fs = require('node:fs'); +function mappedIssues(mapping, identity) { + return mapping.filter(m => m.repository === identity.repository && + m.module === identity.module && m.version === identity.version && + m.sourceSha === identity.sourceSha).flatMap(m => m.issues).filter((n, i, a) => { + if (!Number.isSafeInteger(n) || n <= 0) throw Error('Invalid mapped issue'); + return a.indexOf(n) === i; + }); +} +async function complete({github, context, identity, mapping}) { + const issues = mappedIssues(mapping, identity); + const run = `https://github.com/${identity.repository}/actions/runs/${context.runId}`; + const gallery = `https://www.powershellgallery.com/packages/${identity.module}/${identity.version}`; + const release = `https://github.com/${identity.repository}/releases/tag/${identity.module}-v${identity.version}`; + const marker = ``; + for (const issue_number of issues) { + const args = {...context.repo, issue_number}; + const issue = (await github.rest.issues.get(args)).data; + if (issue.pull_request) throw Error('Mapping must name an issue, not a PR'); + const comments = await github.paginate(github.rest.issues.listComments, {...args, per_page:100}); + if (!comments.some(c => c.user?.type === 'Bot' && c.body.includes(marker))) { + await github.rest.issues.createComment({...args, body: `${marker}\nActual Gallery publish succeeded and the exact downloaded package passed content-hash, manifest, import and installed regression checks.\n\nPackage: ${gallery}\nRelease: ${release}\nSnapshot: ${identity.sourceSha}\nWorkflow and verification artifact: ${run}`}); + } + if (issue.state !== 'closed') await github.rest.issues.update({...args, state:'closed', state_reason:'completed'}); + } +} +module.exports = {mappedIssues, complete}; diff --git a/scripts/gallery/Create-Release.cjs b/scripts/gallery/Create-Release.cjs new file mode 100644 index 0000000..6f35725 --- /dev/null +++ b/scripts/gallery/Create-Release.cjs @@ -0,0 +1,34 @@ +const {execFileSync} = require('node:child_process'); +const fs = require('node:fs'); +const {MODULE:moduleName, VERSION:version, SHA:sha, GITHUB_REPOSITORY:repo, GITHUB_RUN_ID:run} = process.env; +const tag = `${moduleName}-v${version}`; +const gh = (...args) => execFileSync('gh', args, {encoding:'utf8'}).trim(); +const evidence = JSON.parse(fs.readFileSync('stage/evidence.json')); +if(evidence.module !== moduleName || evidence.version !== version || evidence.sourceSha !== sha) throw Error('Release identity mismatch'); +// Tag must either be absent or resolve exactly to the tested commit; never retarget it. +const tags = JSON.parse(gh('api', `repos/${repo}/git/matching-refs/tags/${tag}`)); +const existing = tags.find(r => r.ref === `refs/tags/${tag}`); +if (existing) { + if(existing.object.type !== 'commit' || existing.object.sha !== sha) throw Error('Existing tag is not the tested commit'); + fs.mkdirSync('existing-release', {recursive:true}); + gh('release','download',tag,'--pattern','evidence.json','--dir','existing-release'); + if(fs.readFileSync('stage/evidence.json','utf8') !== fs.readFileSync('existing-release/evidence.json','utf8')) throw Error('Existing release evidence differs'); + gh('release','download',tag,'--pattern','package.tar.gz','--dir','existing-release'); + const entries = execFileSync('tar',['-tzf','existing-release/package.tar.gz'],{encoding:'utf8'}).trim().split('\n'); + if(entries.some(p => !p.startsWith(moduleName + '/') || p.split('/').includes('..'))) throw Error('Unsafe archive entries'); + const crypto = require('node:crypto'); + const expectedPaths = evidence.files.map(f => moduleName+'/'+f.path).sort(); + const archivePaths = entries.filter(p => !p.endsWith('/')).sort(); + if(JSON.stringify(expectedPaths) !== JSON.stringify(archivePaths)) throw Error('Existing archive file list differs'); + // Read members to stdout; never extract a release archive on a write-token runner. + for(const file of evidence.files) { + const bytes = execFileSync('tar',['-xOzf','existing-release/package.tar.gz',moduleName+'/'+file.path]); + if(crypto.createHash('sha256').update(bytes).digest('hex').toUpperCase() !== file.sha256) throw Error('Existing release archive differs from tested package'); + } + console.log(`Verified existing release ${tag}`); +} else { + // Archive is a convenience asset; evidence contains the canonical per-file hashes. + execFileSync('tar',['-czf','package.tar.gz','-C','stage',moduleName]); + gh('release','create',tag,'package.tar.gz','stage/evidence.json','--target',sha,'--title',tag, + '--notes',`Tested immutable release snapshot ${sha}. Source and installed package tests: https://github.com/${repo}/actions/runs/${run}. Gallery publication is a separate protected job; this release does not imply deployment.`); +} diff --git a/scripts/gallery/Get-ReleaseConfig.ps1 b/scripts/gallery/Get-ReleaseConfig.ps1 new file mode 100644 index 0000000..677a5c1 --- /dev/null +++ b/scripts/gallery/Get-ReleaseConfig.ps1 @@ -0,0 +1,58 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)] + [ValidateSet('Bookmarks', '7zip-Archive', 'Currency-Conv', 'Base64String', 'Pipe')] + [string]$Module +) + +# Package branches are deliberately distinct from feature/PR development bases. +# Do not substitute master or dynamically accept arbitrary branch names here. +# These are literal reviewed Git branch names, separate from GitHub Releases +# /releases/latest URL alias. Never resolve a package from development as fallback. +# All configured packages use /out within the snapshot. +# PackagePath is relative to that immutable snapshot, not the runner or branch name. +# GallerySecret is a GitHub environment SECRET NAME, never the API key value. +$configs = @{ + Bookmarks = @{ + ReleaseBranch = 'Bookmarks/release/latest' + PackagePath = 'Bookmarks/out' + Manifest = 'Bookmarks.psd1' + GalleryAccount = 'Stadub' + } + '7zip-Archive' = @{ + ReleaseBranch = '7-Zip/release/1.1' + PackagePath = '7Zip/out' + Manifest = '7zip-Archive.psd1' + GalleryAccount = 'Stadub' + } + 'Currency-Conv' = @{ + ReleaseBranch = 'Currency-Conv/release/1.5' + PackagePath = 'Currency-Conv/out' + Manifest = 'Currency-Conv.psd1' + GalleryAccount = 'Stadub' + } + Base64String = @{ + ReleaseBranch = 'base64String/release/latest' + PackagePath = 'Shared-Functions/Base64String/out' + Manifest = 'Base64String.psd1' + GalleryAccount = 'MiniModules' + } + Pipe = @{ + ReleaseBranch = 'Pipe/release/latest' + PackagePath = 'Shared-Functions/Pipe/out' + Manifest = 'Pipe.psd1' + GalleryAccount = 'MiniModules' + } +} +# Gallery usernames are public configuration. API key values live only in the +# protected environment; module selection never accepts an account/secret input. +$accountSecrets = @{ + Stadub = 'PSGALLERY_API_KEY_STADUB' + MiniModules = 'PSGALLERY_API_KEY_MINIMODULES' +} +$config = $configs[$Module] +if (-not $accountSecrets.ContainsKey($config.GalleryAccount)) { + throw 'No credential route for the configured Gallery account' +} +$config.GallerySecret = $accountSecrets[$config.GalleryAccount] +[pscustomobject]$config diff --git a/scripts/gallery/New-ReleaseOutput.ps1 b/scripts/gallery/New-ReleaseOutput.ps1 new file mode 100644 index 0000000..c5a0c34 --- /dev/null +++ b/scripts/gallery/New-ReleaseOutput.ps1 @@ -0,0 +1,59 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)][string]$Module, + [Parameter(Mandatory)][string]$SourceRoot, + [Parameter(Mandatory)][string]$OutputRoot, + [Parameter(Mandatory)][version]$ExpectedVersion +) +$ErrorActionPreference = 'Stop' +$config = & "$PSScriptRoot/Get-ReleaseConfig.ps1" -Module $Module +$sourceRootPath = (Resolve-Path $SourceRoot).Path +$source = Join-Path $sourceRootPath ($config.PackagePath -replace '/out$', '') +$manifest = Join-Path $source $config.Manifest +if (-not (Test-Path $manifest -PathType Leaf)) { throw "Source manifest missing: $manifest" } +$metadata = Import-PowerShellDataFile $manifest +if ([version]$metadata.ModuleVersion -ne $ExpectedVersion) { + throw "Expected $ExpectedVersion, but source manifest declares $($metadata.ModuleVersion)." +} +if ($metadata.PrivateData.PSData.Prerelease) { throw 'Only stable manifest versions are supported.' } +$destination = Join-Path $OutputRoot $config.PackagePath +if (Test-Path $destination) { throw "Output already exists: $destination. Use a fresh output root and review replacement separately." } + +# Generate in isolation. No source changes, version rewrites, stale out/ reuse, +# import-time module execution, or Gallery calls belong in package generation. +$temporary = Join-Path ([IO.Path]::GetTempPath()) "release-output-$([guid]::NewGuid())" +try { + $package = New-Item (Join-Path $temporary $Module) -ItemType Directory -Force + $files = @(Get-Item $manifest) + $files += @(Get-ChildItem $source -Recurse -File | Where-Object { + $relative = $_.FullName.Substring($source.Length + 1) + $_.Extension -in '.ps1', '.psm1', '.dll', '.ps1xml' -and + $relative -notmatch '(^|[/\\])(out|tests?|TestResults|Assets|\.git|\.github)([/\\]|$)' -and + $_.Name -notmatch '\.(Tests?|SmokeTests)\.ps1$' + }) + foreach ($name in 'README.md', 'LICENSE') { + $file = Join-Path $source $name + if (Test-Path $file -PathType Leaf) { $files += Get-Item $file } + } + $icon = Join-Path $source 'Assets/Icon.ico' + if (Test-Path $icon -PathType Leaf) { $files += Get-Item $icon } + # An explicit module license takes precedence; the repository license is a fallback. + $license = Join-Path $sourceRootPath 'LICENSE' + if (-not (Test-Path (Join-Path $source 'LICENSE') -PathType Leaf) -and + (Test-Path $license -PathType Leaf)) { $files += Get-Item $license } + $duplicates = @($files | Group-Object Name | Where-Object Count -gt 1) + if ($duplicates.Count) { throw "Ambiguous flat package filenames: $($duplicates.Name -join ', ')" } + foreach ($file in $files | Sort-Object Name) { + if ($file.Attributes -band [IO.FileAttributes]::ReparsePoint) { throw "Linked package file is not supported: $($file.Name)" } + Copy-Item $file.FullName (Join-Path $package $file.Name) + } + Test-ModuleManifest (Join-Path $package $config.Manifest) -ErrorAction Stop | Out-Null + & "$PSScriptRoot/Assert-SourcePackage.ps1" -Module $Module -SourceRoot $sourceRootPath -PackageRoot $temporary + # The destination appears only after validation succeeds. Existing output is + # never deleted or replaced; copying into a release checkout remains explicit. + New-Item (Split-Path $destination -Parent) -ItemType Directory -Force | Out-Null + Copy-Item $package.FullName $destination -Recurse + Write-Host "Generated $Module $ExpectedVersion at $destination. Review and run source/installed tests before committing the release snapshot." +} finally { + if (Test-Path $temporary) { Remove-Item $temporary -Recurse -Force } +} diff --git a/scripts/gallery/Package-Evidence.ps1 b/scripts/gallery/Package-Evidence.ps1 new file mode 100644 index 0000000..5664ac0 --- /dev/null +++ b/scripts/gallery/Package-Evidence.ps1 @@ -0,0 +1,29 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)][string]$PackageRoot, + [Parameter(Mandatory)][string]$EvidencePath, + [string]$Module, [string]$Version, [string]$SourceSha, + [switch]$Verify +) +$ErrorActionPreference = 'Stop' +if ($Verify) { + $evidence = Get-Content $EvidencePath -Raw | ConvertFrom-Json + if ($evidence.module -cne $Module -or $evidence.version -cne $Version -or $evidence.sourceSha -cne $SourceSha) { + throw 'Evidence identity mismatch' + } +} else { + if ($SourceSha -cnotmatch '^[0-9a-f]{40}$') { throw 'Full immutable SHA required' } + $evidence = [ordered]@{ module=$Module; version=$Version; sourceSha=$SourceSha; files=@() } +} +$root = (Resolve-Path (Join-Path $PackageRoot $Module)).Path +$files = @(Get-ChildItem $root -Recurse -File | Where-Object Name -ne 'PSGetModuleInfo.xml' | Sort-Object FullName | ForEach-Object { + [ordered]@{ path=$_.FullName.Substring($root.Length + 1).Replace('\','/'); sha256=(Get-FileHash $_.FullName -Algorithm SHA256).Hash } +}) +if ($Verify) { + if (($files | ConvertTo-Json -Depth 5 -Compress) -cne ($evidence.files | ConvertTo-Json -Depth 5 -Compress)) { + throw 'Package content hash mismatch' + } +} else { + $evidence.files = $files + $evidence | ConvertTo-Json -Depth 5 | Set-Content $EvidencePath -Encoding utf8 +} diff --git a/scripts/gallery/Publish-GalleryPackage.ps1 b/scripts/gallery/Publish-GalleryPackage.ps1 new file mode 100644 index 0000000..bf3a438 --- /dev/null +++ b/scripts/gallery/Publish-GalleryPackage.ps1 @@ -0,0 +1,41 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)][string]$Module, + [Parameter(Mandatory)][string]$PackageRoot, + [Parameter(Mandatory)][version]$ExpectedVersion +) + +$ErrorActionPreference = 'Stop' +$config = & (Join-Path $PSScriptRoot 'Get-ReleaseConfig.ps1') -Module $Module +if ($env:PSGALLERY_ACCOUNT -cne $config.GalleryAccount) { + throw "Gallery account mismatch: $Module requires $($config.GalleryAccount). Select its configured credential route." +} +$package = Join-Path (Resolve-Path $PackageRoot).Path $Module +$metadata = Import-PowerShellDataFile (Join-Path $package $config.Manifest) +if ([version]$metadata.ModuleVersion -ne $ExpectedVersion) { + throw 'Artifact version does not match the requested release.' +} +if ($metadata.PrivateData.PSData.Prerelease) { + throw 'This workflow currently supports stable manifest versions only.' +} +Test-ModuleManifest (Join-Path $package $config.Manifest) -ErrorAction Stop | Out-Null +if ([string]::IsNullOrWhiteSpace($env:PSGALLERY_API_KEY)) { + throw "Configure the $($config.GallerySecret) secret for $($config.GalleryAccount) in the powershell-gallery GitHub environment." +} + +try { + $published = Find-Module -Name $Module -Repository PSGallery -ErrorAction Stop + if ($null -eq $published) { + throw 'Gallery lookup returned no result without an explicit package-not-found error.' + } + if ([version]$published.Version -ge $ExpectedVersion) { + throw "Gallery already has $Module $($published.Version). Bump the release manifest version before publishing." + } +} catch { + # A genuinely new package is allowed. Network/authentication errors must fail. + if ($_.FullyQualifiedErrorId -notlike 'NoMatchFoundForCriteria*') { throw } +} +Publish-Module -Path $package -Repository PSGallery -NuGetApiKey $env:PSGALLERY_API_KEY -ErrorAction Stop +if ($env:GITHUB_STEP_SUMMARY) { + "Published $Module $ExpectedVersion using the configured $($config.GalleryAccount) account from source commit $env:SOURCE_SHA." >> $env:GITHUB_STEP_SUMMARY +} diff --git a/scripts/gallery/Resolve-ReleaseSnapshot.ps1 b/scripts/gallery/Resolve-ReleaseSnapshot.ps1 new file mode 100644 index 0000000..04ad1cf --- /dev/null +++ b/scripts/gallery/Resolve-ReleaseSnapshot.ps1 @@ -0,0 +1,36 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)] + [ValidateSet('Bookmarks', '7zip-Archive', 'Currency-Conv', 'Base64String', 'Pipe')] + [string]$Module, + [Parameter(Mandatory)] + [ValidatePattern('^\d+\.\d+\.\d+(\.\d+)?$')] + [string]$Version, + [Parameter(Mandatory)] + [string]$RepositoryRoot +) +$ErrorActionPreference = 'Stop' +$PSNativeCommandUseErrorActionPreference = $false +$root = (Resolve-Path -LiteralPath $RepositoryRoot).Path +$config = & "$PSScriptRoot/Get-ReleaseConfig.ps1" -Module $Module +$ref = "refs/heads/$($config.ReleaseBranch)" +# Resolve exactly once. Every checkout, evidence record and mutation in the run +# must consume this SHA, never the moving branch name or /releases/latest alias. +$remote = @(& git -C $root ls-remote --exit-code origin $ref) +if ($LASTEXITCODE -ne 0 -or $remote.Count -ne 1 -or + $remote[0] -cnotmatch ('^([0-9a-f]{40})\s+' + [regex]::Escape($ref) + '$')) { + throw "Cannot resolve the reviewed release branch for ${Module}: $($config.ReleaseBranch). No development or other-ref fallback is allowed." +} +$sha = $Matches[1] +if ($env:GITHUB_OUTPUT) { + "sha=$sha" >> $env:GITHUB_OUTPUT +} +if ($env:GITHUB_STEP_SUMMARY) { + "Reviewed release snapshot: $Module $Version | $($config.ReleaseBranch) | $sha" >> $env:GITHUB_STEP_SUMMARY +} +[pscustomobject]@{ + Module = $Module + Version = $Version + ReleaseBranch = $config.ReleaseBranch + SourceSha = $sha +} diff --git a/scripts/gallery/Set-GalleryApiKey.ps1 b/scripts/gallery/Set-GalleryApiKey.ps1 new file mode 100644 index 0000000..18db9cf --- /dev/null +++ b/scripts/gallery/Set-GalleryApiKey.ps1 @@ -0,0 +1,61 @@ +<# +.SYNOPSIS +Create or rotate the selected module owner's GitHub environment secret. +.DESCRIPTION +Resolves the account and secret name from Get-ReleaseConfig.ps1. GitHub CLI +prompts for the Gallery key and encrypts it locally. This script never receives +the key as a parameter, command argument, environment variable or file. +.EXAMPLE +./scripts/gallery/Set-GalleryApiKey.ps1 -Module Base64String -WhatIf +.EXAMPLE +./scripts/gallery/Set-GalleryApiKey.ps1 -Module Base64String +#> +[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] +param( + [Parameter(Mandatory)] + [ValidateSet('Bookmarks', '7zip-Archive', 'Currency-Conv', 'Base64String', 'Pipe')] + [string]$Module, + [ValidatePattern('^[A-Za-z0-9-]+/[A-Za-z0-9_.-]+$')] + [string]$Repository = 'stadub/PowershellScripts' +) +$ErrorActionPreference = 'Stop' +$PSNativeCommandUseErrorActionPreference = $false +$config = & "$PSScriptRoot/Get-ReleaseConfig.ps1" -Module $Module +$environmentName = 'powershell-gallery' +$target = "$Repository / $environmentName / $($config.GallerySecret) (Gallery account $($config.GalleryAccount))" +if (-not $PSCmdlet.ShouldProcess($target, 'Create or update environment secret')) { return } +try { $ghCommand = Get-Command gh -CommandType Application -ErrorAction Stop } catch { + throw 'Install GitHub CLI (gh) and authenticate to github.com before updating the environment secret.' +} +$environmentEndpoint = "repos/$Repository/environments/$environmentName" +$metadata = & $ghCommand.Source api --hostname github.com $environmentEndpoint +if ($LASTEXITCODE -ne 0) { throw 'Cannot read the existing powershell-gallery environment. Check gh authentication and environment-secret permissions.' } +$environment = $metadata | ConvertFrom-Json +if ($environment.name -cne $environmentName -or + -not $environment.deployment_branch_policy.custom_branch_policies -or + $environment.deployment_branch_policy.protected_branches) { + throw 'The existing environment must use the configured master-only deployment branch policy. No settings were changed.' +} +$metadata = & $ghCommand.Source api --hostname github.com "$environmentEndpoint/deployment-branch-policies?per_page=100" +if ($LASTEXITCODE -ne 0) { throw 'Cannot verify environment deployment restrictions. No secret was updated.' } +$policies = $metadata | ConvertFrom-Json +if ($policies.total_count -ne 1 -or @($policies.branch_policies).Count -ne 1 -or + $policies.branch_policies[0].name -cne 'master' -or $policies.branch_policies[0].type -cne 'branch') { + throw 'The environment must allow only the master branch. No settings were changed.' +} +Write-Host "Enter the PowerShell Gallery API key for $($config.GalleryAccount) when gh prompts. Target: $target" +# No --body / --env-file / key-valued arguments: gh owns the hidden interactive +# prompt (or its standard input), local encryption and upload. Never print a key. +& $ghCommand.Source secret set $config.GallerySecret --env $environmentName --repo "github.com/$Repository" --app actions +if ($LASTEXITCODE -ne 0) { throw "GitHub CLI could not update $($config.GallerySecret). No deployment was started." } +$metadata = & $ghCommand.Source api --hostname github.com "$environmentEndpoint/secrets/$($config.GallerySecret)" +if ($LASTEXITCODE -ne 0) { throw 'The update command succeeded, but secret metadata verification failed. Check environment settings before retrying.' } +$secret = $metadata | ConvertFrom-Json +if ($secret.name -cne $config.GallerySecret -or -not $secret.updated_at) { throw 'The update command succeeded, but returned secret metadata was unexpected.' } +[pscustomobject]@{ + Repository = $Repository + Environment = $environmentName + GalleryAccount = $config.GalleryAccount + SecretName = $secret.name + UpdatedAt = $secret.updated_at +} diff --git a/scripts/gallery/Test-ReleasePackage.ps1 b/scripts/gallery/Test-ReleasePackage.ps1 new file mode 100644 index 0000000..df00f06 --- /dev/null +++ b/scripts/gallery/Test-ReleasePackage.ps1 @@ -0,0 +1,41 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)][string]$Module, + [Parameter(Mandatory)][string]$SourceRoot, + [Parameter(Mandatory)][string]$PackageRoot, + [Parameter(Mandatory)][version]$ExpectedVersion, + [switch]$InstalledOnly +) +$ErrorActionPreference = 'Stop' +$config = & "$PSScriptRoot/Get-ReleaseConfig.ps1" -Module $Module +$sourcePath = $config.PackagePath -replace '/out$', '' +$source = Join-Path $SourceRoot $sourcePath +$package = Join-Path $PackageRoot $Module +$manifest = Join-Path $package $config.Manifest +$data = Import-PowerShellDataFile $manifest +if ([version]$data.ModuleVersion -ne $ExpectedVersion) { throw 'Installed version mismatch' } +Test-ModuleManifest $manifest -ErrorAction Stop | Out-Null +# Test a copy under the normal module layout, never inject tests into publish payload. +$testRoot = Join-Path ([IO.Path]::GetTempPath()) "release-test-$([guid]::NewGuid())" +try { + $installed = Join-Path $testRoot $sourcePath + New-Item $installed -ItemType Directory -Force | Out-Null + Copy-Item "$package/*" $installed -Recurse + Copy-Item "$source/*.Tests.ps1" $installed -ErrorAction SilentlyContinue + $loaded = Import-Module (Join-Path $installed $config.Manifest) -Force -PassThru -ErrorAction Stop + if ($loaded.Version -ne $ExpectedVersion -or $loaded.ExportedCommands.Count -eq 0) { + throw 'Installed module version/exports smoke check failed' + } + Remove-Module $loaded -Force + if (-not $InstalledOnly) { + & "$PSScriptRoot/../ci/Invoke-ModuleTests.ps1" -Module $Module -SourceRoot $SourceRoot + } + & "$PSScriptRoot/../ci/Invoke-ModuleTests.ps1" -Module $Module -SourceRoot $testRoot +} finally { + $reports = Join-Path $SourceRoot 'TestResults' + New-Item $reports -ItemType Directory -Force | Out-Null + Get-ChildItem (Join-Path $testRoot 'TestResults') -Filter '*.xml' -ErrorAction SilentlyContinue | ForEach-Object { + Copy-Item $_.FullName (Join-Path $reports ("installed-" + $_.Name)) + } + if (Test-Path $testRoot) { Remove-Item $testRoot -Recurse -Force } +} diff --git a/scripts/gallery/Verify-GalleryPackage.ps1 b/scripts/gallery/Verify-GalleryPackage.ps1 new file mode 100644 index 0000000..5aefbbf --- /dev/null +++ b/scripts/gallery/Verify-GalleryPackage.ps1 @@ -0,0 +1,30 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)][string]$Module, + [Parameter(Mandatory)][string]$Version, + [Parameter(Mandatory)][string]$SourceSha, + [Parameter(Mandatory)][string]$EvidencePath, + [Parameter(Mandatory)][string]$SourceRoot, + [Parameter(Mandatory)][string]$OutputRoot +) +$ErrorActionPreference = 'Stop' +# A successful upload is insufficient: wait for exact-version visibility, bounded. +$found = $null +for ($attempt=0; $attempt -lt 6; $attempt++) { + try { + $found = Find-Module -Name $Module -RequiredVersion $Version -Repository PSGallery -ErrorAction Stop + if ($found.Name -cne $Module -or [version]$found.Version -ne [version]$Version) { throw 'Gallery identity mismatch' } + break + } catch { + if ($attempt -eq 5) { throw } + Start-Sleep -Seconds 20 + } +} +Save-Module -Name $Module -RequiredVersion $Version -Repository PSGallery -Path $OutputRoot -ErrorAction Stop +$download = Join-Path $OutputRoot "$Module/$Version" +$flat = Join-Path $OutputRoot 'verify' +New-Item $flat -ItemType Directory -Force | Out-Null +Copy-Item $download (Join-Path $flat $Module) -Recurse +& "$PSScriptRoot/Package-Evidence.ps1" -PackageRoot $flat -EvidencePath $EvidencePath -Module $Module -Version $Version -SourceSha $SourceSha -Verify +& "$PSScriptRoot/Test-ReleasePackage.ps1" -Module $Module -SourceRoot $SourceRoot -PackageRoot $flat -ExpectedVersion $Version -InstalledOnly +"Verified https://www.powershellgallery.com/packages/$Module/$Version from $SourceSha" | Write-Host diff --git a/scripts/gallery/issue-map.json b/scripts/gallery/issue-map.json new file mode 100644 index 0000000..b342f55 --- /dev/null +++ b/scripts/gallery/issue-map.json @@ -0,0 +1,11 @@ +[ + { + "repository": "stadub/PowershellScripts", + "module": "Base64String", + "version": "1.3.0", + "sourceSha": "6d30dbc22de8bfb8bccda5cd3880ffb9a6655f5f", + "issues": [ + 22 + ] + } +] diff --git a/tests/Test-CiRunner.ps1 b/tests/Test-CiRunner.ps1 new file mode 100644 index 0000000..556b39d --- /dev/null +++ b/tests/Test-CiRunner.ps1 @@ -0,0 +1,70 @@ +# Offline contract tests: a fixture Pester module checks runner orchestration only. +# Real module assertions still run under Pester 4.10.1 in the matrix jobs. +$ErrorActionPreference = 'Stop' +$fixture = Join-Path ([IO.Path]::GetTempPath()) "ci-runner-$([guid]::NewGuid())" +$savedModulePath = $env:PSModulePath +$originalLocation = Get-Location +$savedPester = @(Get-Module Pester | Select-Object -ExpandProperty Path) +function Assert-RunnerFailure { + param([string]$Module, [string]$Message) + $caught = $null + try { & $runner -Module $Module } catch { $caught = $_ } + if (-not $caught -or $caught.ToString() -notlike "*$Message*") { + throw "Expected '$Message', got '$caught'" + } + if ((Get-Location).Path -ne $originalLocation.Path) { throw 'Runner did not restore location' } +} +try { + $ci = New-Item (Join-Path $fixture 'scripts/ci') -ItemType Directory -Force + Copy-Item (Join-Path $PSScriptRoot '../scripts/ci/Invoke-ModuleTests.ps1') $ci + Copy-Item (Join-Path $PSScriptRoot '../scripts/ci/Get-CiModuleConfig.ps1') $ci + $runner = Join-Path $ci 'Invoke-ModuleTests.ps1' + $pester = New-Item (Join-Path $fixture 'modules/Pester/4.10.1') -ItemType Directory -Force + @' +@{ RootModule = 'Pester.psm1'; ModuleVersion = '4.10.1'; GUID = '2b264083-fd6b-4897-a827-2d99b548ff29'; FunctionsToExport = @('Invoke-Pester') } +'@ | Set-Content (Join-Path $pester 'Pester.psd1') + @' +function Invoke-Pester { + param([string[]]$Script, [switch]$PassThru, [string]$OutputFile, [string]$OutputFormat) + if (-not $PassThru -or $OutputFormat -ne 'NUnitXml') { throw 'Wrong Pester arguments' } + foreach ($path in $Script) { + if ((Split-Path $path) -ne (Get-Location).Path) { throw 'Wrong suite location' } + } + if ($Script.Count -ne 2) { throw 'Runner must discover both source suites and exclude out/' } + '' | Set-Content -LiteralPath $OutputFile + $counts = Get-Content -LiteralPath $Script[0] | ConvertFrom-Json + [pscustomobject]@{ TotalCount = $counts.TotalCount; FailedCount = $counts.FailedCount } +} +Export-ModuleMember -Function Invoke-Pester +'@ | Set-Content (Join-Path $pester 'Pester.psm1') + Remove-Module Pester -Force -ErrorAction SilentlyContinue + $env:PSModulePath = "$(Join-Path $fixture 'modules')$([IO.Path]::PathSeparator)$savedModulePath" + Assert-RunnerFailure Bookmarks 'Module directory missing' + $moduleDir = New-Item (Join-Path $fixture 'Bookmarks') -ItemType Directory + Assert-RunnerFailure Bookmarks 'No test files found' + $suite = Join-Path $moduleDir 'A.Tests.ps1' + '{"TotalCount":2,"FailedCount":0}' | Set-Content $suite + '{}' | Set-Content (Join-Path $moduleDir 'B.Tests.ps1') + $out = New-Item (Join-Path $moduleDir 'out') -ItemType Directory + '{}' | Set-Content (Join-Path $out 'Ignored.Tests.ps1') + & $runner -Module Bookmarks + if (-not (Test-Path (Join-Path $fixture 'TestResults/Bookmarks.xml'))) { throw 'Missing report' } + if ((Get-Location).Path -ne $originalLocation.Path) { throw 'Runner did not restore location' } + '{"TotalCount":0,"FailedCount":0}' | Set-Content $suite + Assert-RunnerFailure Bookmarks 'No tests discovered' + '{"TotalCount":2,"FailedCount":1}' | Set-Content $suite + Assert-RunnerFailure Bookmarks '1 tests failed' + $pipe = New-Item (Join-Path $fixture 'Shared-Functions/Pipe') -ItemType Directory -Force + "@{ ModuleVersion = '1.0.0'; NestedModules = @('Missing.ps1') }" | + Set-Content (Join-Path $pipe 'Pipe.psd1') + Assert-RunnerFailure Pipe 'Missing.ps1' + "@{ ModuleVersion = '1.0.0' }" | Set-Content (Join-Path $pipe 'Pipe.psd1') + & $runner -Module Pipe +} finally { + Set-Location $originalLocation + Remove-Module Pester -Force -ErrorAction SilentlyContinue + $env:PSModulePath = $savedModulePath + foreach ($path in $savedPester) { Import-Module $path -Force } + Remove-Item -LiteralPath $fixture -Recurse -Force -ErrorAction SilentlyContinue +} +Write-Host 'CI runner contract checks passed (success, failures, discovery, reports, location, manifest).' diff --git a/tests/Test-CiSelection.ps1 b/tests/Test-CiSelection.ps1 new file mode 100644 index 0000000..2a7af2a --- /dev/null +++ b/tests/Test-CiSelection.ps1 @@ -0,0 +1,62 @@ +$ErrorActionPreference = 'Stop' +$selector = Join-Path $PSScriptRoot '../scripts/ci/Select-CiModules.ps1' +$cases = @{ + 'Bookmarks/develop' = 'Bookmarks' + 'Bookmarks/release/latest' = 'Bookmarks' + 'base64tring/develop' = 'Base64String' + 'base64String/release/latest' = 'Base64String' + '7Zip/develop' = '7zip-Archive' + '7-Zip/release/1.1' = '7zip-Archive' + '7-Zip/release/latest' = '7zip-Archive' + 'Currency-Conv/develop' = 'Currency-Conv' + 'Currency-Conv/release/1.5' = 'Currency-Conv' + 'Currency-Conv/release/latest' = 'Currency-Conv' + 'FolderEncoder/develop' = 'FolderEncoder' + 'Shell-Functions/develop' = 'Shell-Functions' + 'Uninstall/develop' = 'Uninstall' + 'Pipe/develop' = 'Pipe' + 'Pipe/release/latest' = 'Pipe' + 'fix/base64-encoding' = 'Base64String' + 'fix/currency-cache-expiry' = 'Currency-Conv' + 'fix/update-check-startup' = 'Bookmarks' + 'fix/7zip-runtime-help' = '7zip-Archive' +} +$all = @('Bookmarks', '7zip-Archive', 'Currency-Conv', 'Base64String', 'Pipe', 'FolderEncoder', 'Shell-Functions', 'Uninstall') +foreach ($branch in @('master', 'ci/github-actions', 'fix/new-feature', 'feature/new-feature', + 'EXportGithub/develop', 'Git-Functions/develop', 'Shared-Functions/develop')) { + $cases[$branch] = $all +} + +# Keep tests from writing matrices into the calling Actions step's outputs. +$savedOutput = $env:GITHUB_OUTPUT +$outputPath = Join-Path ([IO.Path]::GetTempPath()) "ci-selection-$([guid]::NewGuid()).txt" +try { + $env:GITHUB_OUTPUT = $null + foreach ($branch in $cases.Keys) { + $matrix = (& $selector -Branch $branch) | ConvertFrom-Json + $expected = @( + foreach ($module in $cases[$branch]) { + "$module/windows-latest" + if ($module -ne '7zip-Archive') { + "$module/ubuntu-latest" + "$module/macos-latest" + } + } + ) + $actual = @($matrix.include | ForEach-Object { "$($_.module)/$($_.os)" }) + if ($actual.Count -ne $expected.Count -or + @(Compare-Object ($expected | Sort-Object) ($actual | Sort-Object)).Count -gt 0) { + throw "Wrong module/platform coverage for $branch" + } + } + $env:GITHUB_OUTPUT = $outputPath + $json = & $selector -Branch 'Pipe/develop' + $lines = @(Get-Content -LiteralPath $outputPath) + if ($lines.Count -ne 1 -or $lines[0] -cne "matrix=$json") { + throw 'Selector did not emit the matrix as a single GitHub output line' + } +} finally { + $env:GITHUB_OUTPUT = $savedOutput + Remove-Item -LiteralPath $outputPath -Force -ErrorAction SilentlyContinue +} +Write-Host "Module branch selection checks passed ($($cases.Count) branches and GitHub output)." diff --git a/tests/Test-CiSources.ps1 b/tests/Test-CiSources.ps1 new file mode 100644 index 0000000..a6e8675 --- /dev/null +++ b/tests/Test-CiSources.ps1 @@ -0,0 +1,51 @@ +$ErrorActionPreference='Stop' +$resolver=Join-Path $PSScriptRoot '../scripts/ci/Resolve-CiSources.ps1' +$current='a'*40 +$refs=@{} +$allModules=@('Bookmarks','7zip-Archive','Currency-Conv','Base64String','Pipe','FolderEncoder','Shell-Functions','Uninstall') +foreach($name in $allModules) { + $cfg=& "$PSScriptRoot/../scripts/ci/Get-CiModuleConfig.ps1" -Module $name + $refs[$cfg.DevelopmentBranch]='b'*40 +} +$savedOutput=$env:GITHUB_OUTPUT +$outputFile=Join-Path ([IO.Path]::GetTempPath()) "ci-sources-$([guid]::NewGuid()).txt" +function Get-Plan([string]$Branch,[string[]]$Paths=@(),[hashtable]$Refs=$refs) { + (& $resolver -Branch $Branch -CurrentSha $current -RemoteRefs $Refs -ChangedPaths $Paths) | ConvertFrom-Json +} +try { + $env:GITHUB_OUTPUT=$null + $plan=Get-Plan master + if($plan.include.Count -ne 22 -or @($plan.include|Where-Object source_mode -ne development).Count) {throw 'Aggregate baseline is not the eight maintained sources'} + foreach($entry in $plan.include) { + if($entry.source_sha -cne ('b'*40)) {throw 'Baseline SHA changed'} + $cfg=& "$PSScriptRoot/../scripts/ci/Get-CiModuleConfig.ps1" -Module $entry.module + if($entry.source_ref -cne $cfg.DevelopmentBranch) {throw 'Incorrect maintained ref'} + } + $plan=Get-Plan 'Bookmarks/develop' -Refs @{} + if($plan.include.Count -ne 3 -or @($plan.include|Where-Object source_sha -ne $current).Count) {throw 'Component PR is not testing its actual snapshot'} + $plan=Get-Plan 'base64String/release/latest' -Refs @{} + if(@($plan.include|Where-Object source_mode -ne snapshot).Count) {throw 'Release branch is not testing its snapshot'} + $plan=Get-Plan master @('Shared-Functions/Base64String/Base64String.ps1','Uninstall.psm1') + foreach($entry in $plan.include) { + $expected=if($entry.module -in 'Base64String','Uninstall') {$current} else {'b'*40} + if($entry.source_sha -cne $expected) {throw 'A changed module was ignored or unrelated baseline replaced'} + } + $plan=Get-Plan 'Bookmarks/develop' @('Currency-Conv/Functions.ps1') + if($plan.include.Count -ne 6 -or @($plan.include|Where-Object source_sha -ne $current).Count) {throw 'Cross-component source changes escaped checks'} + $plan=Get-Plan master @('Bookmarks/README.md','Shared-Functions/Base64String/out/Base64String.ps1') + if(@($plan.include|Where-Object source_mode -ne development).Count) {throw 'Docs or packaged output falsely replaced source baseline'} + $badRefs=$refs.Clone();$badRefs.Remove('Shell-Functions/develop');$caught=$false + try {Get-Plan master -Refs $badRefs | Out-Null} catch {$caught=$_.Exception.Message -like '*Missing or invalid immutable source ref*'} + if(-not $caught) {throw 'Missing source ref silently accepted'} + $caught=$false + try { & $resolver -Branch master -CurrentSha 'main' -RemoteRefs $refs | Out-Null } catch { $caught=$true } + if(-not $caught) {throw 'Mutable current ref accepted'} + $env:GITHUB_OUTPUT=$outputFile + $json=& $resolver -Branch master -CurrentSha $current -RemoteRefs $refs + $lines=@(Get-Content $outputFile) + if($lines.Count -ne 1 -or $lines[0] -cne "matrix=$json") {throw 'Source plan emitted duplicate/malformed Actions output'} + Write-Host 'CI source planning passed: eight pinned baselines, real component/release snapshots, changed-source coverage, no silent ref fallback and single output.' +} finally { + $env:GITHUB_OUTPUT=$savedOutput + Remove-Item $outputFile -ErrorAction SilentlyContinue +} diff --git a/tests/Test-CiStructure.ps1 b/tests/Test-CiStructure.ps1 new file mode 100644 index 0000000..d25170e --- /dev/null +++ b/tests/Test-CiStructure.ps1 @@ -0,0 +1,39 @@ +# Offline contracts for the three modules added to CI. No registry/process operations. +$ErrorActionPreference = 'Stop' +$fixture = Join-Path ([IO.Path]::GetTempPath()) "ci-structure-$([guid]::NewGuid())" +$runner = Join-Path $PSScriptRoot '../scripts/ci/Invoke-ModuleTests.ps1' +function Assert-StructureFailure([string]$Module, [string]$Pattern) { + $caught = $null + try { & $runner -Module $Module -SourceRoot $fixture } catch { $caught = $_ } + if (-not $caught -or $caught.Exception.Message -notlike $Pattern) { throw "Expected '$Pattern', got '$caught'" } + $report = [xml](Get-Content "$fixture/TestResults/$Module-structure.xml" -Raw) + if ([int]$report.'test-results'.failures -lt 1) { throw 'Failed check has no failed report' } +} +try { + New-Item "$fixture/FolderEncoder", "$fixture/Shell-Functions" -ItemType Directory -Force | Out-Null + $folder = "$fixture/FolderEncoder/FolderEncoder.psd1" + "@{ ModuleVersion='1.0.0'; NestedModules=@('Functions.ps1'); FunctionsToExport=@('EncodeFolder') }" | Set-Content $folder + Assert-StructureFailure FolderEncoder '*Functions.ps1*' + 'function EncodeFolder { throw "must not execute during import checks" }' | Set-Content "$fixture/FolderEncoder/Functions.ps1" + & $runner -Module FolderEncoder -SourceRoot $fixture + $shellManifest = "$fixture/Shell-Functions/Shell-Function.psd1" + "@{ ModuleVersion='1.0.0'; FunctionsToExport=@() }" | Set-Content $shellManifest + Assert-StructureFailure Shell-Functions '*exports no commands*' + "@{ ModuleVersion='1.0.0'; RootModule='Shell-Function.psm1'; FunctionsToExport=@('Get-Fixture') }" | Set-Content $shellManifest + 'function Get-Fixture { "fixture" }; Export-ModuleMember -Function Get-Fixture' | Set-Content "$fixture/Shell-Functions/Shell-Function.psm1" + & $runner -Module Shell-Functions -SourceRoot $fixture + 'function Broken {' | Set-Content "$fixture/Shell-Functions/Shell-Function.psm1" + Assert-StructureFailure Shell-Functions '*Syntax errors*' + 'throw "import fixture failure"' | Set-Content "$fixture/Shell-Functions/Shell-Function.psm1" + Assert-StructureFailure Shell-Functions '*import fixture failure*' + 'function Wrong-Command {}; Export-ModuleMember -Function Wrong-Command' | Set-Content "$fixture/Uninstall.psm1" + Assert-StructureFailure Uninstall '*command/parameter contract*' + # Destructive body would fail if the checker invoked the exported command. + 'function Uninstall-Application { param([Alias("Application")][string]$SoftwareName); throw "must never uninstall" }; Export-ModuleMember -Function Uninstall-Application' | Set-Content "$fixture/Uninstall.psm1" + & $runner -Module Uninstall -SourceRoot $fixture + foreach ($name in 'FolderEncoder', 'Uninstall') { + $report = [xml](Get-Content "$fixture/TestResults/$name-structure.xml" -Raw) + if ([int]$report.'test-results'.failures -ne 0) { throw 'Successful check has failed report' } + } + Write-Host 'Extended CI contracts passed: missing dependency, empty exports, syntax/import failure, safe standalone import and reports.' +} finally { Remove-Item $fixture -Recurse -Force -ErrorAction SilentlyContinue } diff --git a/tests/Test-GalleryAutomation.ps1 b/tests/Test-GalleryAutomation.ps1 new file mode 100644 index 0000000..b95a310 --- /dev/null +++ b/tests/Test-GalleryAutomation.ps1 @@ -0,0 +1,154 @@ +# Offline checks: fixtures and command mocks; never contacts or publishes to Gallery. +$ErrorActionPreference = 'Stop' +$scripts = Join-Path $PSScriptRoot '../scripts/gallery' +$fixture = Join-Path ([IO.Path]::GetTempPath()) ([guid]::NewGuid().ToString()) +$oldKey = $env:PSGALLERY_API_KEY +$oldAccount = $env:PSGALLERY_ACCOUNT +$oldMarker = $env:GALLERY_TEST_MARKER +$oldMode = $env:GALLERY_TEST_MODE +$oldSummary = $env:GITHUB_STEP_SUMMARY +function Assert-Throws([scriptblock]$Action, [string]$Pattern) { + $caught = $false + try { & $Action } catch { + $caught = $true + if ($_.Exception.Message -notlike $Pattern) { throw } + } + if (-not $caught) { throw "Expected failure matching $Pattern" } +} +try { + # Keep offline fixture runs out of any enclosing Actions job summary. + $env:GITHUB_STEP_SUMMARY = '' + $expectedConfigs = @{ + Bookmarks = @('Bookmarks/release/latest', 'Bookmarks/out', 'Bookmarks.psd1', 'Stadub', 'PSGALLERY_API_KEY_STADUB') + '7zip-Archive' = @('7-Zip/release/1.1', '7Zip/out', '7zip-Archive.psd1', 'Stadub', 'PSGALLERY_API_KEY_STADUB') + 'Currency-Conv' = @('Currency-Conv/release/1.5', 'Currency-Conv/out', 'Currency-Conv.psd1', 'Stadub', 'PSGALLERY_API_KEY_STADUB') + Base64String = @('base64String/release/latest', 'Shared-Functions/Base64String/out', 'Base64String.psd1', 'MiniModules', 'PSGALLERY_API_KEY_MINIMODULES') + Pipe = @('Pipe/release/latest', 'Shared-Functions/Pipe/out', 'Pipe.psd1', 'MiniModules', 'PSGALLERY_API_KEY_MINIMODULES') + } + foreach ($name in $expectedConfigs.Keys) { + $config = & "$scripts/Get-ReleaseConfig.ps1" -Module $name + if ((@($config.ReleaseBranch, $config.PackagePath, $config.Manifest, $config.GalleryAccount, $config.GallerySecret) -join '|') -cne ($expectedConfigs[$name] -join '|')) { + throw "Unexpected release configuration for $name" + } + } + # Every module must stage out/, even when a source manifest exists beside it. + foreach ($name in $expectedConfigs.Keys) { + $config = & "$scripts/Get-ReleaseConfig.ps1" -Module $name + $layoutRoot = Join-Path $fixture "layout-$name" + $moduleSource = Join-Path $layoutRoot ($config.PackagePath -replace '/out$', '') + New-Item $moduleSource -ItemType Directory -Force | Out-Null + $fixtureManifest = "@{ ModuleVersion = '1.2.0'; GUID = 'fb5ca217-8826-4570-8241-10a37250331d'; Author = 'Test'; Description = 'Offline layout fixture' }" + $fixtureManifest | Set-Content (Join-Path $moduleSource $config.Manifest) + Assert-Throws { & "$scripts/Build-GalleryPackage.ps1" -Module $name -SourceRoot $layoutRoot -OutputRoot "$fixture/layout-stage-$name" -ExpectedVersion 1.2.0 } '*Release package is missing*' + $releaseOut = New-Item (Join-Path $layoutRoot $config.PackagePath) -ItemType Directory -Force + $fixtureManifest | Set-Content (Join-Path $releaseOut $config.Manifest) + & "$scripts/Build-GalleryPackage.ps1" -Module $name -SourceRoot $layoutRoot -OutputRoot "$fixture/layout-stage-$name" -ExpectedVersion 1.2.0 + & "$scripts/Assert-SourcePackage.ps1" -Module $name -SourceRoot $layoutRoot -PackageRoot "$fixture/layout-stage-$name" + } + $source = Join-Path $fixture 'source' + $package = Join-Path $source 'Shared-Functions/Base64String/out' + New-Item $package -ItemType Directory -Force | Out-Null + @" +@{ + ModuleVersion = '1.2.0' + GUID = 'fb5ca217-8826-4570-8241-10a37250331d' + Author = 'Test' + Description = 'Offline fixture' + NestedModules = @('Base64String.ps1') +} +"@ | Set-Content (Join-Path $package 'Base64String.psd1') + 'function ConvertTo-Fixture { param($Value) $Value }' | Set-Content (Join-Path $package 'Base64String.ps1') + 'excluded' | Set-Content (Join-Path $package 'Base64String.Tests.ps1') + 'excluded' | Set-Content (Join-Path $package 'Base64String.SmokeTests.ps1') + 'excluded' | Set-Content (Join-Path $package 'azure-pipelines.yml') + $stage = Join-Path $fixture 'stage' + & "$scripts/Build-GalleryPackage.ps1" -Module Base64String -SourceRoot $source -OutputRoot $stage -ExpectedVersion 1.2.0 + $built = Join-Path $stage 'Base64String' + if (@(Get-ChildItem $built -File).Count -ne 2) { throw 'Package includes unexpected files' } + Assert-Throws { & "$scripts/Build-GalleryPackage.ps1" -Module Base64String -SourceRoot $source -OutputRoot "$fixture/wrong" -ExpectedVersion 1.3.0 } '*Expected 1.3.0*' + Assert-Throws { & "$scripts/Build-GalleryPackage.ps1" -Module Base64String -SourceRoot $source -OutputRoot $stage -ExpectedVersion 1.2.0 } '*Output already exists*' + Assert-Throws { & "$scripts/Get-ReleaseConfig.ps1" -Module '../invalid' } '*ValidateSet*' + Assert-Throws { & "$scripts/Get-ReleaseConfig.ps1" -Module 'FolderEncoder' } '*ValidateSet*' + $manifest = Join-Path $built 'Base64String.psd1' + $originalManifest = Get-Content $manifest -Raw + $prereleaseManifest = $originalManifest.Replace("ModuleVersion = '1.2.0'", "ModuleVersion = '1.2.0'; PrivateData = @{ PSData = @{ Prerelease = 'beta1' } }") + $prereleaseManifest | Set-Content (Join-Path $package 'Base64String.psd1') + Assert-Throws { & "$scripts/Build-GalleryPackage.ps1" -Module Base64String -SourceRoot $source -OutputRoot "$fixture/prerelease" -ExpectedVersion 1.2.0 } '*stable manifest versions only*' + $originalManifest | Set-Content (Join-Path $package 'Base64String.psd1') + Remove-Item (Join-Path $package 'Base64String.ps1') + Assert-Throws { & "$scripts/Build-GalleryPackage.ps1" -Module Base64String -SourceRoot $source -OutputRoot "$fixture/missing-dependency" -ExpectedVersion 1.2.0 } '*' + + function global:Find-Module { + param($Name, $Repository, $ErrorAction) + switch ($env:GALLERY_TEST_MODE) { + 'duplicate' { [pscustomobject]@{ Version = [version]'1.2.0' } } + 'newer' { [pscustomobject]@{ Version = [version]'2.0.0' } } + 'empty' { return } + 'network' { throw 'Simulated network failure' } + 'new' { Write-Error 'No package found' -ErrorId NoMatchFoundForCriteria -ErrorAction Stop } + default { [pscustomobject]@{ Version = [version]'1.1.0' } } + } + } + function global:Publish-Module { + param($Path, $Repository, $NuGetApiKey, $ErrorAction) + if ($NuGetApiKey -cne "offline-key-$env:PSGALLERY_ACCOUNT") { throw 'Unexpected test key' } + $Path | Set-Content $env:GALLERY_TEST_MARKER + } + $env:GALLERY_TEST_MARKER = Join-Path $fixture 'published.txt' + $env:PSGALLERY_ACCOUNT = 'MiniModules' + Assert-Throws { & "$scripts/Publish-GalleryPackage.ps1" -Module Base64String -PackageRoot $stage -ExpectedVersion 1.3.0 } '*Artifact version*' + $prereleaseManifest | Set-Content $manifest + Assert-Throws { & "$scripts/Publish-GalleryPackage.ps1" -Module Base64String -PackageRoot $stage -ExpectedVersion 1.2.0 } '*stable manifest versions only*' + $originalManifest | Set-Content $manifest + $env:PSGALLERY_API_KEY = '' + # Validate missing selected credentials for every configured module. These + # fixtures contain no module code and the Gallery commands remain mocked. + foreach ($name in $expectedConfigs.Keys) { + $config = & "$scripts/Get-ReleaseConfig.ps1" -Module $name + $env:PSGALLERY_ACCOUNT = $config.GalleryAccount + $accountPackage = Join-Path "$fixture/accounts" $name + New-Item $accountPackage -ItemType Directory -Force | Out-Null + "@{ ModuleVersion = '1.2.0'; GUID = 'fb5ca217-8826-4570-8241-10a37250331d'; Author = 'Test'; Description = 'Offline fixture' }" | Set-Content (Join-Path $accountPackage $config.Manifest) + Assert-Throws { & "$scripts/Publish-GalleryPackage.ps1" -Module $name -PackageRoot "$fixture/accounts" -ExpectedVersion 1.2.0 } "*Configure the $($config.GallerySecret) secret for $($config.GalleryAccount)*" + } + $env:PSGALLERY_ACCOUNT = 'MiniModules' + $env:PSGALLERY_API_KEY = 'offline-key-MiniModules' + $env:GALLERY_TEST_MODE = 'duplicate' + Assert-Throws { & "$scripts/Publish-GalleryPackage.ps1" -Module Base64String -PackageRoot $stage -ExpectedVersion 1.2.0 } '*Gallery already has*' + $env:GALLERY_TEST_MODE = 'newer' + Assert-Throws { & "$scripts/Publish-GalleryPackage.ps1" -Module Base64String -PackageRoot $stage -ExpectedVersion 1.2.0 } '*Gallery already has*' + $env:GALLERY_TEST_MODE = 'empty' + Assert-Throws { & "$scripts/Publish-GalleryPackage.ps1" -Module Base64String -PackageRoot $stage -ExpectedVersion 1.2.0 } '*Gallery lookup returned no result*' + $env:GALLERY_TEST_MODE = 'network' + Assert-Throws { & "$scripts/Publish-GalleryPackage.ps1" -Module Base64String -PackageRoot $stage -ExpectedVersion 1.2.0 } '*Simulated network failure*' + if (Test-Path $env:GALLERY_TEST_MARKER) { throw 'Published despite a failed preflight' } + foreach ($mode in @('upgrade', 'new')) { + $env:GALLERY_TEST_MODE = $mode + & "$scripts/Publish-GalleryPackage.ps1" -Module Base64String -PackageRoot $stage -ExpectedVersion 1.2.0 + if (-not (Test-Path $env:GALLERY_TEST_MARKER)) { throw 'Expected mocked publish call' } + Remove-Item $env:GALLERY_TEST_MARKER + } + # Both accounts and all five modules: verify selected-key use and reject + # mismatched/missing account routes even if a nonempty key is supplied. + $env:GALLERY_TEST_MODE = 'upgrade' + foreach ($name in $expectedConfigs.Keys) { + $config = & "$scripts/Get-ReleaseConfig.ps1" -Module $name + $env:PSGALLERY_API_KEY = "offline-key-$($config.GalleryAccount)" + $env:PSGALLERY_ACCOUNT = 'wrong-account' + Assert-Throws { & "$scripts/Publish-GalleryPackage.ps1" -Module $name -PackageRoot "$fixture/accounts" -ExpectedVersion 1.2.0 } '*Gallery account mismatch*' + if (Test-Path $env:GALLERY_TEST_MARKER) { throw 'Published despite incorrect account routing' } + $env:PSGALLERY_ACCOUNT = $config.GalleryAccount + & "$scripts/Publish-GalleryPackage.ps1" -Module $name -PackageRoot "$fixture/accounts" -ExpectedVersion 1.2.0 + if ((Get-Content $env:GALLERY_TEST_MARKER) -notlike "*$name") { throw 'Wrong package selected for account' } + Remove-Item $env:GALLERY_TEST_MARKER + } + Write-Host 'Offline packaging and publishing checks passed.' +} finally { + Remove-Item function:global:Find-Module, function:global:Publish-Module -ErrorAction SilentlyContinue + $env:PSGALLERY_API_KEY = $oldKey + $env:PSGALLERY_ACCOUNT = $oldAccount + $env:GALLERY_TEST_MARKER = $oldMarker + $env:GALLERY_TEST_MODE = $oldMode + $env:GITHUB_STEP_SUMMARY = $oldSummary + if (Test-Path $fixture) { Remove-Item $fixture -Recurse -Force } +} diff --git a/tests/Test-GalleryKeySetup.ps1 b/tests/Test-GalleryKeySetup.ps1 new file mode 100644 index 0000000..da4748b --- /dev/null +++ b/tests/Test-GalleryKeySetup.ps1 @@ -0,0 +1,69 @@ +# Offline command contracts: no real gh process, key prompt, network or secret update. +$ErrorActionPreference = 'Stop' +$scriptPath = Join-Path $PSScriptRoot '../scripts/gallery/Set-GalleryApiKey.ps1' +$fixtureState = [pscustomobject]@{ Mode='success'; Calls=[System.Collections.Generic.List[object]]::new(); Secret=''; MissingGh=$false } +function Get-Command { + param($Name, $CommandType, $ErrorAction) + if ($Name -ne 'gh' -or $CommandType -ne 'Application') { throw 'Unexpected command lookup' } + if ($fixtureState.MissingGh) { throw 'Fixture gh missing' } + [pscustomobject]@{ Source='Invoke-KeySetupGhFixture' } +} +function Invoke-KeySetupGhFixture { + param([Parameter(ValueFromRemainingArguments)][string[]]$GhArguments) + $fixtureState.Calls.Add([object]$GhArguments) + $global:LASTEXITCODE = 0 + if ($GhArguments[0] -eq 'secret') { + if ($GhArguments[1] -ne 'set') { throw 'Unexpected secret operation' } + $fixtureState.Secret = $GhArguments[2] + if ($fixtureState.Mode -eq 'set-failure') { $global:LASTEXITCODE=1 } + return + } + if ($GhArguments[0] -ne 'api' -or $GhArguments[2] -ne 'github.com') { throw 'Unexpected API command' } + $endpoint=$GhArguments[3] + if ($endpoint -like '*/secrets/*') { + if ($fixtureState.Mode -eq 'verify-failure') { $global:LASTEXITCODE=1; return } + return @{name=$fixtureState.Secret; updated_at='2026-11-11T20:00:00Z'} | ConvertTo-Json -Compress + } + if ($endpoint -like '*/deployment-branch-policies?*') { + if ($fixtureState.Mode -eq 'policy-failure') { $global:LASTEXITCODE=1; return } + $policies=@(@{name='master';type='branch'}) + if ($fixtureState.Mode -eq 'wrong-branch') { $policies=@(@{name='develop';type='branch'}) } + if ($fixtureState.Mode -eq 'tag-policy') { $policies=@(@{name='master';type='tag'}) } + if ($fixtureState.Mode -eq 'extra-policy') { $policies+=@{name='*';type='branch'} } + return @{total_count=$policies.Count;branch_policies=$policies} | ConvertTo-Json -Depth 4 -Compress + } + if ($fixtureState.Mode -eq 'missing-environment') { $global:LASTEXITCODE=1; return } + @{ name='powershell-gallery'; deployment_branch_policy=@{custom_branch_policies=($fixtureState.Mode -ne 'unrestricted');protected_branches=$false} } | ConvertTo-Json -Compress +} +function Expect-KeySetupFailure([string]$Mode, [string]$Pattern) { + $fixtureState.Mode=$Mode; $fixtureState.Calls.Clear(); $caught=$null + try { & $scriptPath -Module Base64String } catch { $caught=$_ } + if (-not $caught -or $caught.Exception.Message -notlike $Pattern) { throw "Expected '$Pattern', got '$caught'" } + if ($Mode -notin 'set-failure','verify-failure' -and @($fixtureState.Calls | Where-Object { $_[0] -eq 'secret' }).Count) { throw 'Secret write attempted despite failed preflight' } +} +$savedExitCode=$global:LASTEXITCODE +try { + & $scriptPath -Module Base64String -WhatIf + if ($fixtureState.Calls.Count) { throw 'WhatIf contacted gh' } + $expected=@{Bookmarks='PSGALLERY_API_KEY_STADUB';'7zip-Archive'='PSGALLERY_API_KEY_STADUB';'Currency-Conv'='PSGALLERY_API_KEY_STADUB';Base64String='PSGALLERY_API_KEY_MINIMODULES';Pipe='PSGALLERY_API_KEY_MINIMODULES'} + foreach ($name in $expected.Keys) { + $fixtureState.Mode='success';$fixtureState.Calls.Clear() + $result=& $scriptPath -Module $name + if ($result.SecretName -cne $expected[$name] -or $result.Environment -cne 'powershell-gallery' -or $fixtureState.Calls.Count -ne 4) { throw 'Wrong environment/account secret route' } + $set=@($fixtureState.Calls | Where-Object { $_[0] -eq 'secret' }) + if ($set.Count -ne 1) { throw 'Expected exactly one secret update' } + $expectedArguments=@('secret','set',$expected[$name],'--env','powershell-gallery','--repo','github.com/stadub/PowershellScripts','--app','actions') + if (($set[0] -join '|') -cne ($expectedArguments -join '|')) { throw 'Secret scope or stdin-only CLI arguments differ' } + } + Expect-KeySetupFailure missing-environment '*Cannot read the existing*' + Expect-KeySetupFailure unrestricted '*master-only*' + Expect-KeySetupFailure wrong-branch '*allow only the master*' + Expect-KeySetupFailure tag-policy '*allow only the master*' + Expect-KeySetupFailure extra-policy '*allow only the master*' + Expect-KeySetupFailure policy-failure '*Cannot verify*' + Expect-KeySetupFailure set-failure '*could not update*' + Expect-KeySetupFailure verify-failure '*update command succeeded*' + $fixtureState.MissingGh=$true + Expect-KeySetupFailure missing-gh '*Install GitHub CLI*' + Write-Host 'Key setup contracts passed: five account routes, hidden-prompt arguments, environment-only scope, WhatIf, protection/auth/update/verification failures.' +} finally { $global:LASTEXITCODE=$savedExitCode } diff --git a/tests/Test-GalleryVerification.ps1 b/tests/Test-GalleryVerification.ps1 new file mode 100644 index 0000000..0318ed4 --- /dev/null +++ b/tests/Test-GalleryVerification.ps1 @@ -0,0 +1,43 @@ +# Fully offline Gallery visibility/download failures; never uses credentials. +$ErrorActionPreference='Stop' +$root=Join-Path ([IO.Path]::GetTempPath()) "gallery-verify-$([guid]::NewGuid())" +$scripts=Join-Path $PSScriptRoot '../scripts/gallery' +function Expect-Failure([scriptblock]$Action) { + $caught=$false + try { & $Action } catch { $caught=$true } + if (-not $caught) { throw 'Expected verification failure' } +} +try { + New-Item "$root/scripts", "$root/expected/Base64String" -ItemType Directory -Force | Out-Null + Copy-Item "$scripts/Verify-GalleryPackage.ps1", "$scripts/Package-Evidence.ps1" "$root/scripts" + # Installed smoke invocation contract; real runtime is tested separately. + 'param($Module,$SourceRoot,$PackageRoot,$ExpectedVersion,[switch]$InstalledOnly); if (-not $InstalledOnly) { throw "Not installed" }; if ($global:verifyMode -eq "smoke-failure") { throw "Bad import" }; $global:smoked=$true' | Set-Content "$root/scripts/Test-ReleasePackage.ps1" + 'exact bytes' | Set-Content "$root/expected/Base64String/module.ps1" + & "$scripts/Package-Evidence.ps1" -Module Base64String -Version 1.3.0 -SourceSha ('a'*40) -PackageRoot "$root/expected" -EvidencePath "$root/evidence.json" + function global:Start-Sleep { param($Seconds) } + function global:Find-Module { + param($Name,$RequiredVersion,$Repository,$ErrorAction) + if ($Name -ne 'Base64String' -or $RequiredVersion -ne '1.3.0' -or $Repository -ne 'PSGallery') { throw 'Wrong query' } + if ($global:verifyMode -eq 'invisible') { throw 'Not visible' } + if ($global:verifyMode -eq 'wrong-version') { return [pscustomobject]@{Name=$Name;Version='1.2.0'} } + [pscustomobject]@{Name=$Name;Version=$RequiredVersion} + } + function global:Save-Module { + param($Name,$RequiredVersion,$Repository,$Path,$ErrorAction) + if ($RequiredVersion -ne '1.3.0') { throw 'Wrong download version' } + $dest=New-Item "$Path/$Name/$RequiredVersion" -ItemType Directory -Force + Copy-Item "$root/expected/Base64String/*" $dest + if ($global:verifyMode -eq 'wrong-bytes') { 'imposter' | Set-Content "$dest/module.ps1" } + } + foreach($mode in 'invisible','wrong-version','wrong-bytes','smoke-failure','success') { + $global:verifyMode=$mode;$global:smoked=$false + $invoke = { & "$root/scripts/Verify-GalleryPackage.ps1" -Module Base64String -Version 1.3.0 -SourceSha ('a'*40) -SourceRoot "$root/source" -EvidencePath "$root/evidence.json" -OutputRoot "$root/$mode" } + if($mode -eq 'success') { & $invoke; if(-not $global:smoked) {throw 'Smoke not invoked'} } + else { Expect-Failure $invoke; if($global:smoked) {throw 'Unexpected smoke success'} } + } + Write-Host 'Gallery verification: invisible, wrong version, wrong bytes, import failure and exact success passed.' +} finally { + Remove-Item function:global:Start-Sleep,function:global:Find-Module,function:global:Save-Module -ErrorAction SilentlyContinue + Remove-Variable verifyMode,smoked -Scope Global -ErrorAction SilentlyContinue + Remove-Item $root -Recurse -Force -ErrorAction SilentlyContinue +} diff --git a/tests/Test-IssueCompletion.cjs b/tests/Test-IssueCompletion.cjs new file mode 100644 index 0000000..6e380e1 --- /dev/null +++ b/tests/Test-IssueCompletion.cjs @@ -0,0 +1,42 @@ +const assert = require('node:assert/strict'); +const {mappedIssues, complete} = require('../scripts/gallery/Complete-Issues.cjs'); +const identity = {repository:'stadub/PowershellScripts',module:'Base64String',version:'1.3.0',sourceSha:'a'.repeat(40)}; +const mapping = [{...identity, issues:[22,22]}]; +assert.deepEqual(mappedIssues(mapping, identity),[22]); +for(const key of Object.keys(identity)) assert.deepEqual(mappedIssues(mapping, {...identity,[key]:'wrong'}),[]); +assert.deepEqual(mappedIssues([],identity),[]); +assert.throws(()=>mappedIssues([{...identity,issues:['22']}],identity)); +(async()=>{ + let comments=[],state='open',writes=[]; + const github={rest:{issues:{ + get:async()=>({data:{state}}), + listComments:()=>{}, + createComment:async({body})=>{comments.push({body,user:{type:'Bot'}});writes.push('comment')}, + update:async()=>{state='closed';writes.push('close')} + }},paginate:async()=>comments}; + const args={github,context:{repo:{owner:'stadub',repo:'PowershellScripts'},runId:123},identity,mapping}; + await complete(args); + assert.deepEqual(writes,['comment','close']); + assert.match(comments[0].body,/packages\/Base64String\/1.3.0/); + assert.match(comments[0].body,/actions\/runs\/123/); + assert.match(comments[0].body,/releases\/tag\/Base64String-v1.3.0/); + await complete(args); + assert.equal(writes.length,2); + state='open';await complete(args);assert.equal(writes.length,3); // recover comment-before-close interruption + await complete({...args,identity:{...identity,version:'wrong'}});assert.equal(writes.length,3); + github.rest.issues.get=async()=>({data:{state:'open',pull_request:{}}}); + await assert.rejects(complete(args),/not a PR/); + console.log('Issue completion: exact mapping, evidence, retry idempotency and PR rejection passed.'); +})().catch(e=>{console.error(e);process.exitCode=1}); +// The real trusted mapping must agree with the checked-in immutable package evidence. +const trusted = require('../scripts/gallery/issue-map.json'); +for (const entry of trusted) { + assert.equal(entry.repository, 'stadub/PowershellScripts'); + assert.match(entry.sourceSha, /^[0-9a-f]{40}$/); + const evidence = require(`../docs/releases/${entry.module.toLowerCase()}-${entry.version}-evidence.json`); + assert.equal(evidence.module, entry.module); + assert.equal(evidence.version, entry.version); + assert.equal(evidence.sourceSha, entry.sourceSha); + assert.deepEqual(mappedIssues([entry], entry), entry.issues); +} +console.log('Trusted issue mapping agrees with recorded immutable package evidence.'); diff --git a/tests/Test-ReleaseCreation.cjs b/tests/Test-ReleaseCreation.cjs new file mode 100644 index 0000000..edffe5a --- /dev/null +++ b/tests/Test-ReleaseCreation.cjs @@ -0,0 +1,38 @@ +// Exercise real archive/evidence logic with a local gh stub; no GitHub writes. +const fs=require('node:fs'),os=require('node:os'),path=require('node:path'),crypto=require('node:crypto'); +const {execFileSync,spawnSync}=require('node:child_process'); +const assert=require('node:assert/strict'); +const root=fs.mkdtempSync(path.join(os.tmpdir(),'release-create-')); +try { + fs.mkdirSync(path.join(root,'bin'));fs.mkdirSync(path.join(root,'stage/Base64String'),{recursive:true}); + fs.mkdirSync(path.join(root,'remote')); + const payload='reviewed package bytes'; + fs.writeFileSync(path.join(root,'stage/Base64String/module.ps1'),payload); + const evidence={module:'Base64String',version:'1.3.0',sourceSha:'a'.repeat(40),files:[{path:'module.ps1',sha256:crypto.createHash('sha256').update(payload).digest('hex').toUpperCase()}]}; + fs.writeFileSync(path.join(root,'stage/evidence.json'),JSON.stringify(evidence)); + fs.writeFileSync(path.join(root,'bin/gh'),`#!/usr/bin/env node +const fs=require('node:fs');const args=process.argv.slice(2); +const state=fs.existsSync('remote/tag.json')?JSON.parse(fs.readFileSync('remote/tag.json')):[]; +if(args[0]==='api') process.stdout.write(JSON.stringify(state)); +else if(args[1]==='create') { + fs.writeFileSync('remote/tag.json',JSON.stringify([{ref:'refs/tags/'+args[2],object:{type:'commit',sha:process.env.SHA}}])); + fs.copyFileSync('stage/evidence.json','remote/evidence.json');fs.copyFileSync('package.tar.gz','remote/package.tar.gz'); +} else if(args[1]==='download') { + const file=args[args.indexOf('--pattern')+1],dir=args[args.indexOf('--dir')+1]; + fs.copyFileSync('remote/'+file,dir+'/'+file); +} else process.exit(1); +`,{mode:0o755}); + const script=path.resolve('scripts/gallery/Create-Release.cjs'); + const env={...process.env,PATH:path.join(root,'bin')+path.delimiter+process.env.PATH,MODULE:'Base64String',VERSION:'1.3.0',SHA:evidence.sourceSha,GITHUB_REPOSITORY:'stadub/PowershellScripts',GITHUB_RUN_ID:'123'}; + const run=()=>spawnSync(process.execPath,[script],{cwd:root,env,encoding:'utf8'}); + let result=run();assert.equal(result.status,0,result.stderr); // create + result=run();assert.equal(result.status,0,result.stderr); // existing exact tag and archive + fs.rmSync(path.join(root,'existing-release'),{recursive:true}); + fs.writeFileSync(path.join(root,'stage/Base64String/module.ps1'),'tampered package'); + execFileSync('tar',['-czf','remote/package.tar.gz','-C','stage','Base64String'],{cwd:root}); + result=run();assert.notEqual(result.status,0);assert.match(result.stderr,/archive differs/); + fs.rmSync(path.join(root,'existing-release'),{recursive:true}); + fs.writeFileSync(path.join(root,'remote/tag.json'),JSON.stringify([{ref:'refs/tags/Base64String-v1.3.0',object:{type:'commit',sha:'b'.repeat(40)}}])); + result=run();assert.notEqual(result.status,0);assert.match(result.stderr,/not the tested commit/); + console.log('Release creation: create, idempotent retry, changed archive and moved tag checks passed.'); +} finally { fs.rmSync(root,{recursive:true,force:true}); } diff --git a/tests/Test-ReleaseEvidence.ps1 b/tests/Test-ReleaseEvidence.ps1 new file mode 100644 index 0000000..6a7d704 --- /dev/null +++ b/tests/Test-ReleaseEvidence.ps1 @@ -0,0 +1,34 @@ +$ErrorActionPreference = 'Stop' +$root = Join-Path ([IO.Path]::GetTempPath()) "evidence-$([guid]::NewGuid())" +$scripts = Join-Path $PSScriptRoot '../scripts/gallery' +function Expect-Failure([scriptblock]$Action) { + $failed=$false + try { & $Action } catch { $failed=$true } + if (-not $failed) { throw 'Expected fail-closed behavior' } +} +try { + $module = New-Item "$root/package/Base64String" -ItemType Directory -Force + 'reviewed bytes' | Set-Content "$module/module.ps1" + $evidenceArgs = @{PackageRoot="$root/package"; EvidencePath="$root/evidence.json";Module='Base64String';Version='1.3.0';SourceSha=('a'*40)} + & "$scripts/Package-Evidence.ps1" @evidenceArgs + & "$scripts/Package-Evidence.ps1" @evidenceArgs -Verify + $wrong=$evidenceArgs.Clone();$wrong.Version='1.2.0' + Expect-Failure { & "$scripts/Package-Evidence.ps1" @wrong -Verify } + 'generated metadata' | Set-Content "$module/PSGetModuleInfo.xml" + & "$scripts/Package-Evidence.ps1" @evidenceArgs -Verify + 'tampered bytes' | Set-Content "$module/module.ps1" + Expect-Failure { & "$scripts/Package-Evidence.ps1" @evidenceArgs -Verify } + 'reviewed bytes' | Set-Content "$module/module.ps1" + 'extra file' | Set-Content "$module/extra.ps1" + Expect-Failure { & "$scripts/Package-Evidence.ps1" @evidenceArgs -Verify } + Remove-Item "$module/extra.ps1", "$module/module.ps1" + Expect-Failure { & "$scripts/Package-Evidence.ps1" @evidenceArgs -Verify } + # Detect release source/out divergence before code can be tested or published. + $source=New-Item "$root/source/Shared-Functions/Base64String" -ItemType Directory -Force + 'source' | Set-Content "$source/Base64String.ps1" + 'stale' | Set-Content "$module/Base64String.ps1" + Expect-Failure { & "$scripts/Assert-SourcePackage.ps1" -Module Base64String -SourceRoot "$root/source" -PackageRoot "$root/package" } + Copy-Item "$source/Base64String.ps1" "$module/Base64String.ps1" -Force + & "$scripts/Assert-SourcePackage.ps1" -Module Base64String -SourceRoot "$root/source" -PackageRoot "$root/package" + Write-Host 'Release evidence: exact identity, tampering, extra/missing files and source/package drift passed.' +} finally { Remove-Item $root -Recurse -Force -ErrorAction SilentlyContinue } diff --git a/tests/Test-ReleaseOutput.ps1 b/tests/Test-ReleaseOutput.ps1 new file mode 100644 index 0000000..865a7da --- /dev/null +++ b/tests/Test-ReleaseOutput.ps1 @@ -0,0 +1,53 @@ +# Offline generation contracts. No imports of runtime module code, Gallery calls, +# modification of checked-out modules, or release-branch changes. +$ErrorActionPreference = 'Stop' +$scripts = Join-Path $PSScriptRoot '../scripts/gallery' +$fixture = Join-Path ([IO.Path]::GetTempPath()) "release-output-test-$([guid]::NewGuid())" +function Assert-OutputFailure([scriptblock]$Action, [string]$Pattern) { + $caught = $null + try { & $Action } catch { $caught = $_ } + if (-not $caught -or $caught.Exception.Message -notlike $Pattern) { throw "Expected '$Pattern', got '$caught'" } +} +try { + $source = New-Item "$fixture/source" -ItemType Directory -Force + 'canonical license bytes' | Set-Content "$source/LICENSE" + foreach ($name in 'Bookmarks', '7zip-Archive', 'Currency-Conv', 'Base64String', 'Pipe') { + $config = & "$scripts/Get-ReleaseConfig.ps1" -Module $name + $modulePath = Join-Path $source ($config.PackagePath -replace '/out$', '') + New-Item "$modulePath/Functions", "$modulePath/out", "$modulePath/tests", "$modulePath/Assets" -ItemType Directory -Force | Out-Null + $manifest = Join-Path $modulePath $config.Manifest + "@{ ModuleVersion='1.3.0'; GUID='fb5ca217-8826-4570-8241-10a37250331d'; Author='Fixture'; Description='Offline output fixture'; NestedModules=@('Commands.ps1') }" | Set-Content $manifest + 'function Get-Fixture { throw "Runtime code must not execute in generator" }' | Set-Content "$modulePath/Functions/Commands.ps1" + 'excluded stale artifact' | Set-Content "$modulePath/out/stale.ps1" + 'excluded fixture' | Set-Content "$modulePath/tests/Fixtures.ps1" + 'excluded tests' | Set-Content "$modulePath/Fixture.Tests.ps1" + 'excluded CI' | Set-Content "$modulePath/azure-pipelines.yml" + $expectedLicense = if ($name -eq 'Base64String') { 'explicit module license bytes' } else { 'canonical license bytes' } + if ($name -eq 'Base64String') { $expectedLicense | Set-Content "$modulePath/LICENSE" } + 'reviewed docs' | Set-Content "$modulePath/README.md" + 'icon bytes' | Set-Content "$modulePath/Assets/Icon.ico" + foreach ($attempt in 1,2) { + & "$scripts/New-ReleaseOutput.ps1" -Module $name -SourceRoot $source -OutputRoot "$fixture/build-$attempt" -ExpectedVersion 1.3.0 + } + $first = Join-Path "$fixture/build-1" $config.PackagePath + $second = Join-Path "$fixture/build-2" $config.PackagePath + if (@(Get-ChildItem $first -File).Count -ne 5) { throw 'Unexpected generated package contents' } + foreach ($file in Get-ChildItem $first -File) { + if ((Get-FileHash $file.FullName).Hash -ne (Get-FileHash (Join-Path $second $file.Name)).Hash) { throw 'Non-reproducible output bytes' } + } + Copy-Item "$source/LICENSE" "$fixture/build-1/LICENSE" -Force + & "$scripts/Build-GalleryPackage.ps1" -Module $name -SourceRoot "$fixture/build-1" -OutputRoot "$fixture/stage" -ExpectedVersion 1.3.0 + & "$scripts/Assert-SourcePackage.ps1" -Module $name -SourceRoot $source -PackageRoot "$fixture/stage" + if ((Get-Content "$fixture/stage/$name/LICENSE") -ne $expectedLicense) { throw 'Generation/staging lost selected package license' } + Assert-OutputFailure { & "$scripts/New-ReleaseOutput.ps1" -Module $name -SourceRoot $source -OutputRoot "$fixture/build-1" -ExpectedVersion 1.3.0 } '*Output already exists*' + if ((Get-Content "$modulePath/out/stale.ps1") -ne 'excluded stale artifact') { throw 'Generator modified existing source output' } + } + # Negative cases use the last fixture: no partial valid-looking output. + Assert-OutputFailure { & "$scripts/New-ReleaseOutput.ps1" -Module Pipe -SourceRoot $source -OutputRoot "$fixture/wrong-version" -ExpectedVersion 1.4.0 } '*Expected 1.4.0*' + 'different file' | Set-Content "$modulePath/Commands.ps1" + Assert-OutputFailure { & "$scripts/New-ReleaseOutput.ps1" -Module Pipe -SourceRoot $source -OutputRoot "$fixture/ambiguous" -ExpectedVersion 1.3.0 } '*Ambiguous flat package filenames*' + Remove-Item "$modulePath/Commands.ps1", "$modulePath/Functions/Commands.ps1" + Assert-OutputFailure { & "$scripts/New-ReleaseOutput.ps1" -Module Pipe -SourceRoot $source -OutputRoot "$fixture/missing" -ExpectedVersion 1.3.0 } '*Commands.ps1*' + if (Test-Path (Join-Path "$fixture/missing" $config.PackagePath)) { throw 'Invalid package left behind' } + Write-Host 'Release output checks passed: all five routes, deterministic bytes, flattening, exclusions, module-license precedence, no overwrite, version, ambiguity and missing dependencies.' +} finally { Remove-Item $fixture -Recurse -Force -ErrorAction SilentlyContinue } diff --git a/tests/Test-ReleaseSelection.ps1 b/tests/Test-ReleaseSelection.ps1 new file mode 100644 index 0000000..9122a0b --- /dev/null +++ b/tests/Test-ReleaseSelection.ps1 @@ -0,0 +1,81 @@ +# Real local Git fixtures: no network, credentials, releases or Gallery mutations. +$ErrorActionPreference = 'Stop' +$PSNativeCommandUseErrorActionPreference = $false +$resolver = Join-Path $PSScriptRoot '../scripts/gallery/Resolve-ReleaseSnapshot.ps1' +$gitExe = (Get-Command git -CommandType Application -ErrorAction Stop | Select-Object -First 1).Source +$fixture = Join-Path ([IO.Path]::GetTempPath()) "release-selection-$([guid]::NewGuid())" +$savedOutput = $env:GITHUB_OUTPUT +$savedSummary = $env:GITHUB_STEP_SUMMARY +$exitCodeVariable = Get-Variable LASTEXITCODE -Scope Global -ErrorAction SilentlyContinue +$savedExitCode = if ($null -ne $exitCodeVariable) { $exitCodeVariable.Value } else { 0 } +function Invoke-FixtureGit { + # A plain function preserves native flags such as -d; advanced functions + # would bind that flag to PowerShell's common Debug parameter. + & $gitExe @args + if ($LASTEXITCODE -ne 0) { throw "Fixture Git command failed: $($args[0])" } +} +function Assert-SelectionFailure([scriptblock]$Action, [string]$Pattern) { + $caught = $false + try { & $Action | Out-Null } catch { + $caught = $true + if ($_.Exception.Message -notlike $Pattern) { throw } + } + if (-not $caught) { throw "Expected selection failure: $Pattern" } +} +try { + $env:GITHUB_OUTPUT = '' + $env:GITHUB_STEP_SUMMARY = '' + $seed = Join-Path $fixture 'seed' + $remote = Join-Path $fixture 'remote.git' + $hooks = (New-Item (Join-Path $fixture 'empty-hooks') -ItemType Directory -Force).FullName + Invoke-FixtureGit init --bare --quiet $remote + Invoke-FixtureGit init --quiet -b fixture $seed + Invoke-FixtureGit -C $seed config user.name 'Offline fixture' + Invoke-FixtureGit -C $seed config user.email 'fixture@example.invalid' + 'reviewed A' | Set-Content (Join-Path $seed 'snapshot.txt') + Invoke-FixtureGit -C $seed add snapshot.txt + Invoke-FixtureGit -C $seed -c commit.gpgsign=false -c "core.hooksPath=$hooks" commit --quiet -m 'reviewed A' + $shaA = Invoke-FixtureGit -C $seed rev-parse HEAD + Invoke-FixtureGit -C $seed remote add origin $remote + Invoke-FixtureGit -C $seed -c "core.hooksPath=$hooks" push --quiet origin HEAD:refs/heads/fixture + $modules = @('Bookmarks','7zip-Archive','Currency-Conv','Base64String','Pipe') + foreach ($name in $modules) { + $config = & "$PSScriptRoot/../scripts/gallery/Get-ReleaseConfig.ps1" -Module $name + Invoke-FixtureGit --git-dir=$remote update-ref "refs/heads/$($config.ReleaseBranch)" $shaA + $selected = & $resolver -Module $name -Version 1.3.0 -RepositoryRoot $seed + if ($selected.SourceSha -cne $shaA -or $selected.ReleaseBranch -cne $config.ReleaseBranch -or $selected.Module -cne $name) { + throw "Incorrect reviewed source selection for $name" + } + } + $output = Join-Path $fixture 'output.txt' + $summary = Join-Path $fixture 'summary.txt' + $env:GITHUB_OUTPUT = $output + $env:GITHUB_STEP_SUMMARY = $summary + $pinned = & $resolver -Module Base64String -Version 1.3.0 -RepositoryRoot $seed + if (@(Get-Content $output).Count -ne 1 -or (Get-Content $output) -cne "sha=$shaA") { throw 'Malformed or duplicate SHA output' } + if ((Get-Content $summary -Raw) -notlike "*Base64String 1.3.0*base64String/release/latest*$shaA*") { throw 'Snapshot evidence missing from run summary' } + $env:GITHUB_OUTPUT = '' + $env:GITHUB_STEP_SUMMARY = '' + 'reviewed B' | Set-Content (Join-Path $seed 'snapshot.txt') + Invoke-FixtureGit -C $seed add snapshot.txt + Invoke-FixtureGit -C $seed -c commit.gpgsign=false -c "core.hooksPath=$hooks" commit --quiet -m 'reviewed B' + $shaB = Invoke-FixtureGit -C $seed rev-parse HEAD + Invoke-FixtureGit -C $seed -c "core.hooksPath=$hooks" push --quiet origin HEAD:refs/heads/base64String/release/latest + if ($pinned.SourceSha -cne $shaA) { throw 'Pinned snapshot changed when its branch advanced' } + $next = & $resolver -Module Base64String -Version 1.3.0 -RepositoryRoot $seed + if ($next.SourceSha -cne $shaB) { throw 'A new selection did not resolve the current reviewed tip' } + Invoke-FixtureGit --git-dir=$remote update-ref -d refs/heads/7-Zip/release/1.1 + Assert-SelectionFailure { & $resolver -Module 7zip-Archive -Version 1.3.0 -RepositoryRoot $seed } '*Cannot resolve the reviewed release branch*' + Assert-SelectionFailure { & $resolver -Module Base64String -Version '1.3.0; echo injected' -RepositoryRoot $seed } '*Version*' + Assert-SelectionFailure { & $resolver -Module Uninstall -Version 1.3.0 -RepositoryRoot $seed } '*ValidateSet*' + Invoke-FixtureGit -C $seed remote remove origin + Assert-SelectionFailure { & $resolver -Module Base64String -Version 1.3.0 -RepositoryRoot $seed } '*Cannot resolve the reviewed release branch*' + Write-Host 'Release selection passed: five configured sources, one immutable SHA, advancing branches, summary evidence, missing refs/origin and invalid inputs.' +} finally { + $env:GITHUB_OUTPUT = $savedOutput + $env:GITHUB_STEP_SUMMARY = $savedSummary + Remove-Item $fixture -Recurse -Force -ErrorAction SilentlyContinue + # Expected failing native-Git cases must not make Actions' shell wrapper + # report failure after all assertions passed. + $global:LASTEXITCODE = $savedExitCode +} diff --git a/tests/Test-WorkflowSafety.cjs b/tests/Test-WorkflowSafety.cjs new file mode 100644 index 0000000..c3fa014 --- /dev/null +++ b/tests/Test-WorkflowSafety.cjs @@ -0,0 +1,65 @@ +const fs = require('node:fs'); +const assert = require('node:assert/strict'); +const workflow = fs.readFileSync('.github/workflows/release-gallery.yml','utf8'); +const jobs = Object.fromEntries([...workflow.matchAll(/^ ([\w-]+):\n([\s\S]*?)(?=^ [\w-]+:\n|$(?![\s\S]))/gm)].map(m=>[m[1],m[2]])); +for(const name of ['publish','verify','complete-issues']) assert.ok(jobs[name],name); +assert.match(jobs.publish,/environment: powershell-gallery/); +assert.match(jobs.publish,/!inputs.dry_run && github.ref == 'refs\/heads\/master'/); +assert.match(jobs.publish,/needs: \[package, test, release\]/); +for(const [name,job] of Object.entries(jobs)) { + if(name !== 'publish') assert.ok(!job.includes('secrets.') && !job.includes('secrets['),`Secret in ${name}`); + if(name !== 'complete-issues') assert.ok(!job.includes('issues: write'),`Issue write in ${name}`); +} +for(const term of ['!inputs.dry_run',"github.ref == 'refs/heads/master'","needs.publish.result == 'success'","needs.publish.outputs.published == 'true'","needs.verify.result == 'success'","needs.verify.outputs.verified == 'true'"]) assert.ok(jobs['complete-issues'].includes(term),term); +assert.ok(!jobs['complete-issues'].includes('inputs.issue')); +assert.ok(!jobs['complete-issues'].includes('ref: ${{ inputs.source_sha }}')); +assert.match(workflow,/dry_run:[\s\S]*?default: true/); +assert.match(workflow,/cancel-in-progress: false/); +console.log('Workflow safety: trusted closure, secret/permission scope, dry-run and success gates passed.'); + +assert.match(jobs.publish,/PSGALLERY_API_KEY: \$\{\{ secrets\[steps\.account\.outputs\.secret\] \}\}/); +assert.match(jobs.publish,/PSGALLERY_ACCOUNT: \$\{\{ steps\.account\.outputs\.name \}\}/); +assert.ok(!workflow.includes('secrets.PSGALLERY_API_KEY')); +assert.ok(!workflow.includes('inputs.account') && !workflow.includes('inputs.secret')); +const selector = jobs.publish.split(' - name: Select configured Gallery account')[1].split(' - name: Publish tested package')[0]; +assert.ok(selector.includes('Get-ReleaseConfig.ps1')); +assert.ok(selector.includes('config.GallerySecret') && selector.includes('config.GalleryAccount')); +assert.ok(!selector.includes('secrets[') && !selector.includes('secrets.')); +console.log('Credential safety: only selected configured account key reaches upload, with no fallback or dispatch override.'); +const candidateValidation = fs.readFileSync('.github/workflows/validate-release-candidate.yml','utf8'); +assert.ok(candidateValidation.includes('workflow_call:')); +assert.match(candidateValidation,/permissions:\n contents: read/); +for (const forbidden of ['secrets.', 'secrets[', 'issues: write', 'contents: write', 'environment:', 'Publish-GalleryPackage.ps1', 'Complete-Issues']) { + assert.ok(!candidateValidation.includes(forbidden), `Candidate validation unexpectedly contains ${forbidden}`); +} +assert.ok(candidateValidation.includes('inputs.source_sha') && candidateValidation.includes('inputs.automation_sha')); +console.log('Candidate validation is read-only, immutable-input-only, and cannot publish or complete issues.'); +const moduleValidation = fs.readFileSync('.github/workflows/validate-module-source.yml','utf8'); +assert.match(moduleValidation,/permissions:\n contents: read/); +for (const forbidden of ['secrets.', 'secrets[', 'issues: write', 'contents: write', 'environment:', 'Publish-GalleryPackage.ps1']) assert.ok(!moduleValidation.includes(forbidden)); +assert.ok(moduleValidation.includes('inputs.source_sha') && moduleValidation.includes('inputs.automation_sha')); +assert.ok(moduleValidation.includes('Invoke-ModuleTests.ps1')); +console.log('Module source validation remains read-only and tests exact source commits.'); + +const ciWorkflow = fs.readFileSync('.github/workflows/ci.yml','utf8'); +assert.ok(ciWorkflow.includes('Resolve-CiSources.ps1')); +assert.ok(ciWorkflow.includes('ref: ${{ matrix.source_sha }}')); +assert.ok(ciWorkflow.includes('-SourceRoot ./module-source')); +assert.ok(ciWorkflow.includes('source-identity.json')); +assert.ok(!ciWorkflow.includes('continue-on-error: true')); +console.log('Aggregate CI tests and records exact selected source commits without allow-failure.'); + +const dispatchForm = workflow.slice(0, workflow.indexOf('permissions:')); +assert.match(dispatchForm, /module:[\s\S]*?type: choice/); +assert.match(dispatchForm, /version:[\s\S]*?type: string/); +assert.ok(!dispatchForm.includes('source_sha:')); +assert.equal((jobs.package.match(/Resolve-ReleaseSnapshot.ps1/g) || []).length, 1); +assert.ok(jobs.package.includes('source_sha: ${{ steps.snapshot.outputs.sha }}')); +assert.ok(jobs.package.includes('ref: ${{ steps.snapshot.outputs.sha }}')); +assert.ok(!workflow.includes('inputs.source_sha')); +for (const name of ['test','release','publish','verify','complete-issues']) { + assert.ok(jobs[name].includes('needs.package.outputs.source_sha'), `Unpinned release source in ${name}`); +} +assert.match(jobs.verify, /needs: \[package, publish\]/); +assert.match(jobs['complete-issues'], /needs: \[package, publish, verify\]/); +console.log('Release form selects a module/version and propagates one resolved immutable snapshot through every job.');