-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (98 loc) · 4.39 KB
/
test.yml
File metadata and controls
118 lines (98 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: test
on:
push:
branches:
- main
pull_request:
branches:
- main
types:
- opened
- edited
- synchronize
workflow_dispatch:
jobs:
test:
name: Test ${{ matrix.style }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
style: [mustache, envsubst, make]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout repository for ${{ matrix.style }} test on ${{ matrix.os }}
uses: actions/checkout@main
- name: Setup ${{ matrix.style }} test on ${{ matrix.os }}
id: test-setup
shell: pwsh
run: |
$expected = (Join-Path $pwd test stubs expected replaced.tpl)
$subject = (Join-Path $pwd test subject-${{ matrix.style }}.tpl)
$pristine = (Join-Path $pwd test stubs pristine ${{ matrix.style }}.tpl)
$untouched = (Join-Path $pwd test stubs untouched no-matches.tpl)
$untouchedHash = (Get-FileHash -Path $untouched -Algorithm SHA256).Hash
Copy-Item -Path $pristine -Destination $subject
Write-Output "expected-path=$expected" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8NoBOM -Append
Write-Output "subject-path=$subject" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8NoBOM -Append
Write-Output "untouched-path=$untouched" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8NoBOM -Append
Write-Output "untouched-hash=$untouchedHash" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8NoBOM -Append
- name: Show ${{ matrix.style }} test subject before replacement on ${{ matrix.os }}
run: cat "${{ steps.test-setup.outputs.subject-path }}"
- name: Show expected output for ${{ matrix.style }} test on ${{ matrix.os }}
run: cat "${{ steps.test-setup.outputs.expected-path }}"
- name: Show untouched ${{ matrix.style }} test subject before replacement on ${{ matrix.os }}
run: cat "${{ steps.test-setup.outputs.untouched-path }}"
- name: Show expected hash for untouched ${{ matrix.style }} test on ${{ matrix.os }}
run: echo "${{ steps.test-setup.outputs.untouched-hash }}"
- name: Perform ${{ matrix.style }} test on ${{ matrix.os }}
uses: ./
with:
paths: |
${{ steps.test-setup.outputs.subject-path }}
${{ steps.test-setup.outputs.untouched-path }}
style: ${{ matrix.style }}
fail: true
no-newline: true
env:
NAME: jon
- name: Show actual result for ${{ matrix.style }} test on ${{ matrix.os }}
run: cat "${{ steps.test-setup.outputs.subject-path }}"
- name: Assert ${{ matrix.style }} replacement test on ${{ matrix.os }}
id: assert-replacement
shell: pwsh
run: |
$expected = "${{ steps.test-setup.outputs.expected-path }}"
$subject = "${{ steps.test-setup.outputs.subject-path }}"
$expectedContent = Get-Content -Path $expected -Raw
$actualContent = Get-Content -Path $subject -Raw
if ($expectedContent -ne $actualContent) {
echo "::error title=✘ Token replacement test failed::You probably want to fix this."
exit 1
} else {
echo "✓ Token replacement test passed"
}
- name: Show actual result of untouched ${{ matrix.style }} test on ${{ matrix.os }}
run: cat "${{ steps.test-setup.outputs.untouched-path }}"
- name: Assert ${{ matrix.style }} untouched test on ${{ matrix.os }}
id: assert-untouched
shell: pwsh
run: |
$expected = "${{ steps.test-setup.outputs.untouched-hash }}"
$actual = (Get-FileHash -Path "${{ steps.test-setup.outputs.untouched-path }}" -Algorithm SHA256).Hash
if ($expected -ne $actual) {
echo "::error title=✘ Token untouched test failed::You probably want to fix this."
exit 1
} else {
echo "✓ Token untouched test passed"
}
pester:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: Run Pester Tests
shell: pwsh
run: |
$testPath = (Join-Path -Path "$env:GITHUB_WORKSPACE" -ChildPath 'test')
Invoke-Pester -Path (Join-Path -Path $testPath -ChildPath 'ReplaceTokens.Tests.ps1') -Output Detailed