Skip to content

225 create and example to show how to use lemontreeautomation docker container for pipeline tasks #480

225 create and example to show how to use lemontreeautomation docker container for pipeline tasks

225 create and example to show how to use lemontreeautomation docker container for pipeline tasks #480

# 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 }}`
})