-
Notifications
You must be signed in to change notification settings - Fork 2.4k
114 lines (99 loc) · 4.01 KB
/
assets_validation.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
114
name: Validating the Building of Public Assets
on:
push:
paths-ignore:
- '**/*.md'
- 'mkdocs.yml'
- 'src/docs/**/*'
branches: [ main ]
pull_request:
branches: [ main, release/** ]
concurrency:
group: ${{ github.head_ref || github.run_id }}-assets_validation
cancel-in-progress: true
jobs:
test-npm-build:
name: Test building assets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Rebuild packages
run: |
npm install
gulp rebuild
- name: Check if git has changes
shell: pwsh
run: |
$changes = git status --porcelain
if ($changes)
{
Write-Output 'Please make sure to build the assets properly before pushing, see https://docs.orchardcore.net/en/latest/docs/guides/gulp-pipeline/.'
Write-Output 'The following files changed:'
Write-Output $changes
Write-Output 'You can also download the attached artifact to see the changes.'
Write-Output ''
Write-Output '---------------------------------------'
Write-Output ''
$changeLines = $changes -split '`n'
$changedFiles = @()
$hasNonCrlfChange = $false
foreach ($line in $changeLines)
{
if ($line -match '^\s?(M|A|\?\?)\s+(.*)$')
{
$changeType = $matches[1]
$file = $matches[2]
Write-Output "Diff for: $file"
if ($changeType -eq 'M')
{
# File is modified; use git diff to get the diff of the modified file.
# The diff will be sent to stderr so we need to redirect it to stdout to capture it.
git diff -- $file 2>&1 >> tmp.txt
$diffOutput = Get-Content tmp.txt
Remove-Item tmp.txt
# Filtering out this pattern is necessary because certain CRLF line endings are not replaced by
# gulp-eol, so the output files can still have some CRLF.
if ($($diffOutput ?? '').Contains('CRLF will be replaced by LF the next time Git touches it'))
{
Write-Output "Warning: CRLF will be replaced by LF in $file. Fix this if you can, but certain CRLF line endings can't be replaced."
}
else
{
Write-Output $diffOutput
$hasNonCrlfChange = $true
}
}
elseif ($changeType -eq '??')
{
# File is (untracked); display the file contents.
Get-Content -Path $file
$hasNonCrlfChange = $true
}
$changedFiles += $file
Write-Output ''
Write-Output '---------------------------------------'
Write-Output ''
}
}
if (-not $hasNonCrlfChange)
{
Write-Output 'No non-CRLF changes found. Repository is clean.'
exit 0
}
# Convert the array of changed files to a single string with each file on a new line so actions/upload-artifact
# can consume it.
$changedFilesString = $changedFiles -join "`n"
"CHANGED_FILES<<ENDOFSTRING`n$($changedFilesString)`nENDOFSTRING" >> $Env:GITHUB_ENV
exit -1
}
else
{
Write-Host "No uncommitted changes found. Repository is clean."
}
- name: Upload changed files as artifact
uses: actions/upload-artifact@v4
if: failure()
with:
name: changed-files
path: ${{ env.CHANGED_FILES }}
retention-days: 30