|
| 1 | +name: Validation Workflow |
| 2 | + |
| 3 | +# This is a reusable workflow called by other workflows |
| 4 | + |
| 5 | +on: |
| 6 | + # This is going to be referenced by other workflows |
| 7 | + workflow_call: |
| 8 | + |
| 9 | +jobs: |
| 10 | + validate: |
| 11 | + name: Validate Workflow |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + # Needed for test reporting |
| 15 | + permissions: |
| 16 | + checks: write |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout Code |
| 20 | + uses: actions/checkout@v3 |
| 21 | + |
| 22 | + - name: Extract Repo Name |
| 23 | + id: repo_name |
| 24 | + run: echo "repo_name=$(echo '${{ github.repository }}' | cut -d '/' -f 2)" >> $GITHUB_OUTPUT |
| 25 | + |
| 26 | + - name: Install Linting and Testing Deps |
| 27 | + shell: pwsh |
| 28 | + run: | |
| 29 | + Install-Module -Name Pester -MinimumVersion 5.5.0 |
| 30 | + Install-Module -Name PSScriptAnalyzer -MinimumVersion 1.21.0 |
| 31 | +
|
| 32 | + - name: PSScriptAnalyzer Linting |
| 33 | + shell: pwsh |
| 34 | + run: | |
| 35 | + Invoke-ScriptAnalyzer -Path ./src/ |
| 36 | +
|
| 37 | + - name: Pester Test Runs |
| 38 | + shell: pwsh |
| 39 | + run: | |
| 40 | + $results = Invoke-Pester -Path ./tests/ -CI -PassThru |
| 41 | + $results | ConvertTo-JUnitReport -AsString | Out-File -Path testResults.xml -Force |
| 42 | +
|
| 43 | + - name: Version Update Check |
| 44 | + #if: ${{ github.event.pull_request.state != 'closed' }} |
| 45 | + if: github.ref != 'refs/heads/main' |
| 46 | + shell: pwsh |
| 47 | + run: | |
| 48 | +
|
| 49 | + # Fetch the current psd1 as it sits in main |
| 50 | + git fetch origin main:main |
| 51 | + git show FETCH_HEAD:src/${{ steps.repo_name.outputs.repo_name }}.psd1 | Out-File -Path main-manifest.psd1 |
| 52 | +
|
| 53 | + # Get the current Git commit hash and main branch hash. |
| 54 | + $mainCommitId = & git rev-parse main |
| 55 | + $branchCommitId = & git rev-parse HEAD |
| 56 | + "`nGit Commit Hashes:" |
| 57 | + "`tMain Commit Hash ID: `e[38;2;56;136;255m $mainCommitId `e[0m" |
| 58 | + "`tBranch Commit Hash ID: `e[38;2;56;136;255m $branchCommitId `e[0m" |
| 59 | +
|
| 60 | + "`nFetching current Manifest ModuleVersion from main..." |
| 61 | + $prevManifest = Import-PowerShellDataFile -Path ./main-manifest.psd1 |
| 62 | + $prevVer = [System.Version]::Parse($prevManifest.ModuleVersion) |
| 63 | +
|
| 64 | + # Import the current manifest |
| 65 | + "Fetching new Manifest ModuleVersion from branch..." |
| 66 | + $branchManifest = Import-PowerShellDataFile -Path ./src/*psd1 |
| 67 | + $branchVer = [System.Version]::Parse($branchManifest.ModuleVersion) |
| 68 | +
|
| 69 | + "`nVersions:" |
| 70 | + "`tNew Version (branch $env:GITHUB_REF_NAME):`e[38;2;56;136;255m $branchVer `e[0m " |
| 71 | + "`tPrevious Version (branch main):`e[38;2;56;136;255m $prevVer `e[0m " |
| 72 | + "`n" |
| 73 | +
|
| 74 | + # Check if version hasnt been udpated |
| 75 | + if ($mainCommitId -eq $branchCommitId) { |
| 76 | + "ℹ️ No new Git commits have been pushed to this branch yet, branch ($branchCommitId) and main ($mainCommitId) Git commit hashes are equal." |
| 77 | + } elseif ($prevVer -eq $branchVer) { |
| 78 | + "`e[38;2;255;0;0m❌ Branch Module Manfiest version ($branchVer) matches the main branch version ($prevVer), please update!`e[0m" |
| 79 | + exit 1 |
| 80 | + } elseif ($branchVer -lt $prevVer) { |
| 81 | + "`e[38;2;255;0;0m❌ SemVer violation! ($branchVer) cannot be less than ($prevVer), please update!`e[0m" |
| 82 | + exit 1 |
| 83 | + } else { |
| 84 | + "`e[38;2;0;255;0m✅ Version check pass! Good job, you're a SemVer pro 😎!`e[0m" |
| 85 | + } |
| 86 | +
|
| 87 | + - name: Report Tests |
| 88 | + |
| 89 | + if: success() || failure() |
| 90 | + with: |
| 91 | + name: Pester Test Results |
| 92 | + path: testResults.xml |
| 93 | + reporter: jest-junit |
0 commit comments