forked from microsoft/variable-substitution
-
-
Notifications
You must be signed in to change notification settings - Fork 5
113 lines (99 loc) · 3.28 KB
/
ci.yml
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
on:
pull_request:
branches:
- master
push:
jobs:
build_test_job:
name: 'Build and test job'
permissions:
issues: write
pull-requests: write
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- name: 'Checking out repo code'
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: cleanup node_modules
shell: pwsh
run: |
if (Test-Path -Path node_modules) {
Remove-Item -Path node_modules -Recurse -Force
}
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 16
- name: 'Validate build'
run: |
npm install
npm run build
- name: 'Run L0 tests'
run: |
npm run test
- name : 'Run test coverage'
if: runner.os == 'Windows' && github.event_name == 'pull_request'
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh # help actionlinter to distinguish the correct shell being used
run: |
$coverage_result = npm run coverage
$start = $false;
$middle = $false;
$end = $false;
$count = 0;
foreach ($j in $coverage_result)
{
if ($j.tostring().startswith("--------------"))
{
if (!$start)
{
$start = $true;
$start_index = $count
}
elseif (!$middle)
{
$middle = $true;
$middle_index = $count
}
elseif (!$end)
{
$end = $true;
$end_index = $count
}
}
$count++
}
$tbl_md = $coverage_result[($start_index+1)..($end_index-1)] -join "\n"
$summary = $coverage_result[($end_index + 1)..$count] -join "\n"
$comment = $tbl_md + "\n" + $summary
$url = "https://api.github.com/repos/${env:GITHUB_REPOSITORY}/issues/${env:PR_NUMBER}/comments"
$headers = @{
"Authorization" = "token ${env:GITHUB_TOKEN}"
}
Invoke-RestMethod -Method POST -Uri $url -Headers $headers -Body "{ `"body`": `"${comment}`" }"
test_action_job:
name: 'Execute the local action'
runs-on: ${{ matrix.os }}
needs: build_test_job
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- name: 'Checking out repo code'
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Test the local action
uses: ./ # Uses an action in the root directory
with:
files: './src/Tests/Resources/test.json'
env:
ID: "Value from workflow"
glossary.GlossDiv.GlossList.GlossEntry.ID: "Value from workflow"
glossary.title: "Fake title"
- name: Validate the test file
shell: pwsh
run: |
$test_file = Get-Content -Path src\Tests\Resources\test.json -Raw
Write-Host $test_file