-
Notifications
You must be signed in to change notification settings - Fork 3
212 lines (196 loc) · 9.96 KB
/
publishReviewSession.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Copyright (c) Robert Bosch GmbH
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
name: Publish Review Session
on:
pull_request_target:
types:
- opened
- edited
- reopened
- synchronize
- review_requested
env:
ModelName: DemoModel
ModelExtension: eapx
ReviewSessionURL: https://nexus.lieberlieber.com/repository/lemontree-session
LemonTreePipelineToolsRemovePrerenderedDiagramsExecutable: https://nexus.lieberlieber.com/repository/lemontree-pipeline-tools/LemonTree.Pipeline.Tools.RemovePrerenderedDiagrams.exe
jobs:
PublishReviewSession:
defaults:
run:
shell: pwsh
runs-on: windows-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
lfs: true
fetch-depth: 0
- name: Get relevant commit IDs
id: CommitIds
run: |
git fetch
$baseId = git merge-base origin/$env:GITHUB_BASE_REF origin/$env:GITHUB_HEAD_REF
Write-Output "baseCommitId=$baseId" >> $env:GITHUB_OUTPUT
$sourceId = git show-ref --hash origin/$env:GITHUB_HEAD_REF
Write-Output "sourceCommitId=$sourceId" >> $env:GITHUB_OUTPUT
$targetId = git show-ref --hash origin/$env:GITHUB_BASE_REF
Write-Output "targetCommitId=$targetId" >> $env:GITHUB_OUTPUT
Write-Output "target branch: $env:GITHUB_BASE_REF"
Write-Output "source branch: $env:GITHUB_HEAD_REF"
Write-Output "target commit: $targetId"
Write-Output "source commit: $sourceId"
Write-Output "base commit: $baseId"
- name: Create sessionfile name
id: session_file
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const repoName = context.payload.pull_request.base.repo.name
const prNumber = context.payload.pull_request.number
const baseSHA = '${{steps.CommitIds.outputs.targetCommitId}}'
const headSHA = '${{steps.CommitIds.outputs.sourceCommitId}}'
const filename = [repoName, 'PR', prNumber, baseSHA, headSHA].join('-') + '.ltsfs'
console.log(`Filename will be: ${filename}`)
return filename
- name: Download base-commit file
id: baseDownload
run: |
git fetch origin ${{steps.CommitIds.outputs.baseCommitId}}
$pointer = git cat-file blob ${{steps.CommitIds.outputs.baseCommitId}}:${{env.ModelName}}.${{env.ModelExtension}}
$sha = ($pointer[1] -split(":"))[1]
if($sha -ne $null){
$shaPart1 = $sha.Substring(0,2)
$shaPart2 = $sha.Substring(2,2)
Write-Output "Model SHA: $sha"
git cat-file --filters ${{steps.CommitIds.outputs.baseCommitId}}:${{env.ModelName}}.${{env.ModelExtension}} | Out-Null
copy ".git\lfs\objects\$shaPart1\$shaPart2\$sha" "${{env.ModelName}}_base.${{env.ModelExtension}}"
Write-Output "result=downloaded" >> $env:GITHUB_OUTPUT
}
else{
Write-Output "result=notFound" >> $env:GITHUB_OUTPUT
}
- name: Post new model comment to PR
if: steps.baseDownload.outputs.result == 'notFound'
uses: actions/github-script@v6
with:
script: |
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Model not found on base commit / fork-off point`
})
- name: Download source branch head file
if: steps.baseDownload.outputs.result == 'downloaded'
id: headDownload
run: |
git fetch origin $env:GITHUB_HEAD_REF
$pointer = git cat-file blob ${{steps.CommitIds.outputs.sourceCommitId}}":${{env.ModelName}}.${{env.ModelExtension}}"
$sha = ($pointer[1] -split(":"))[1]
$shaPart1 = $sha.Substring(0,2)
$shaPart2 = $sha.Substring(2,2)
Write-Output "Model SHA: $sha"
git cat-file --filters ${{steps.CommitIds.outputs.sourceCommitId}}":${{env.ModelName}}.${{env.ModelExtension}}" | Out-Null
copy ".git\lfs\objects\$shaPart1\$shaPart2\$sha" "${{env.ModelName}}_head.${{env.ModelExtension}}"
# download Lemontree.Automation on a runner and setup the license
- uses: LieberLieber/setup-LemonTree.Automation@v5
id: GetLTA
with:
License: ${{secrets.LTALICENSE}}
#ExeLocation &"${{steps.GetLTA.outputs.LemonTreeAutomationExecutable}}"
- name: Check for merge conflicts
if: steps.baseDownload.outputs.result == 'downloaded'
id: mergeCheck
run: |
&"${{steps.GetLTA.outputs.LemonTreeAutomationExecutable}}" merge --base ${{env.ModelName}}_base.${{env.ModelExtension}} --theirs ${{env.ModelName}}.${{env.ModelExtension}} --mine ${{env.ModelName}}_head.${{env.ModelExtension}} --dryrun --sfs ${{ steps.session_file.outputs.result }} --abortOnConflict true
Write-Output "result=$LASTEXITCODE" >> $env:GITHUB_OUTPUT
Write-Output "Return code: $LASTEXITCODE"
if($LASTEXITCODE -eq 0){
Write-Output "No merge conflicts, setting message"
ecWrite-Outputho "message=[Review Session file](${{env.ReviewSessionURL}}/${{ steps.session_file.outputs.result }})\n:heavy_check_mark: **No merge conflicts in model**\n\nInstall [LemonTree 3.3+](https://www.lieberlieber.com/lemontree/en/) to open the Review Session file." >> $env:GITHUB_OUTPUT
}
elseif($LASTEXITCODE -eq 2){
Write-Output "Internal Error when diffing. Please report such errors to [email protected]"
exit 2
}
elseif($LASTEXITCODE -eq 3){
Write-Output "Merge conflicts, setting message"
Write-Output "message=[Review Session file](${{env.ReviewSessionURL}}/${{ steps.session_file.outputs.result }})\n:x: **Please resolve merge conflicts in model first**\n\nInstall [LemonTree 3.3+](https://www.lieberlieber.com/lemontree/en/) to open the Review Session file." >> $env:GITHUB_OUTPUT
exit 0
}
elseif($LASTEXITCODE -eq 6){
Write-Output "Licensing issue of LemonTree.Automation"
}
else{
Write-Output "Unknown error"
}
# - name: Remove DIAGRAMIMAGEMAPS for Diff
# if: steps.mergeCheck.outputs.result == 0
# run: |
# while (Test-Path Alias:curl) {Remove-Item Alias:curl} #remove the alias binding from curl to Invoke-WebRequest
# curl "${{env.LemonTreePipelineToolsRemovePrerenderedDiagramsExecutable}}" --output LemonTree.Pipeline.Tools.RemovePrerenderedDiagrams.exe
# Write-Output ".\LemonTree.Pipeline.Tools.RemovePrerenderedDiagrams.exe remove --Model ${{env.ModelName}}_base.${{env.ModelExtension}}"
# .\LemonTree.Pipeline.Tools.RemovePrerenderedDiagrams.exe remove --Model ${{env.ModelName}}_base.${{env.ModelExtension}}
# Write-Output ".\LemonTree.Pipeline.Tools.RemovePrerenderedDiagrams.exe remove --Model ${{env.ModelName}}_head.${{env.ModelExtension}}"
# .\LemonTree.Pipeline.Tools.RemovePrerenderedDiagrams.exe remove --Model ${{env.ModelName}}_head.${{env.ModelExtension}}
- name: Create review session file
id: checkSession
run: |
$Message = "${{ steps.mergeCheck.outputs.message }}"
$sfsfilename ="${{ steps.session_file.outputs.result }}"
$mergecheckresult = ${{ steps.mergeCheck.outputs.result}}
if ($mergecheckresult -eq 0)
{
$output = &'${{steps.GetLTA.outputs.LemonTreeAutomationExecutable}}' diff --theirs ${{env.ModelName}}_base.${{env.ModelExtension}} --mine ${{env.ModelName}}_head.${{env.ModelExtension}} --sfs ${{ steps.session_file.outputs.result }}
Write-Output $output
ForEach ($line in $($output -split "`r`n"))
{
if ($line.EndsWith('Found 0 different elements.'))
{
Write-Output "No differences we don't need to publish the session file."
$Message = ":heavy_check_mark: **Model is identical!**"
$sfsfilename ="";
}
}
}
Write-Output "$Message"
Write-Output "SfsFileName=$sfsfilename" >> $env:GITHUB_OUTPUT
Write-Output "message=$Message" >> $env:GITHUB_OUTPUT
exit 0
- name: Upload
if: steps.baseDownload.outputs.result == 'downloaded'
run: |
$sessionFileName = "${{ steps.checkSession.outputs.SfsFileName }}"
if ([string]::IsNullOrEmpty($sessionFileName))
{
Write-Output "Nothing to upload"
}
else
{
$targetUrl = "${{env.ReviewSessionURL}}/${{ steps.session_file.outputs.result }}"
Write-Output "Uploading $sessionFileName to Nexus: $targetUrl"
while (Test-Path Alias:curl) {Remove-Item Alias:curl} #remove the alias binding from curl to Invoke-WebRequest
curl "-u${{secrets.NEXUSAUTHENTICATION}}" -T $sessionFileName $targetUrl
}
- name: Archive Session Files
if: steps.baseDownload.outputs.result == 'downloaded'
uses: actions/upload-artifact@v4
with:
name: Review Session File
path: ${{ steps.session_file.outputs.result }}
retention-days: 5
- name: Create PR comment
if: steps.baseDownload.outputs.result == 'downloaded'
uses: actions/github-script@v6
with:
script: |
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${{ steps.checkSession.outputs.message }}`
})