Skip to content

Commit

Permalink
170 create xmi after git commit and upload to nexus (#171)
Browse files Browse the repository at this point in the history
Post Commit XMI Upload and Download in a GitHub Action
  • Loading branch information
danielsiegl authored Sep 30, 2022
1 parent 8ad0af0 commit 3108925
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,4 @@ MigrationBackup/
/example-scripts/powershell/session_A_B.ltses
/example-scripts/powershell/session_A_B.ltses - Copy.xml
/example-scripts/powershell/session_A_B.ltses.xml
/*.xmi
10 changes: 10 additions & 0 deletions example-scripts/powershell/CreateNexusCredentials.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
param
(
[Parameter(Mandatory = $true, HelpMessage="Enter: 'Username:Password'")][string] $Credential
)
$repoPath = git rev-parse --show-toplevel
$file = Join-Path -Path $repoPath -ChildPath "..\nexus.inf"
$file = [System.IO.Path]::GetFullPath($file)
echo $file
#not the best of all options - but it is a way to demonstrate the workflow.
$Credential | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "$file"
19 changes: 19 additions & 0 deletions example-scripts/powershell/DownloadPostCommitXMI.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#this script downloads xmi files from the artifact storage to be used by pipeline tools.
#typically it will run on an build agent like GitHub Actions


$gitcommitId = git rev-parse HEAD
$url = "https://nexus.lieberlieber.com/service/rest/v1/search?repository=xmi&name=$gitcommitId*"
Write-Host $url
$json = Invoke-RestMethod -Uri $url -Method Get

foreach ($url in $json.items.assets.downloadUrl) {
$url = $url.Insert(4,"s")
$file = $url.Substring($url.lastIndexOf('/') + 1)
if($file.StartsWith($gitcommitId))
{
Write-Host $file
$content = ((Invoke-WebRequest -Uri $url -Method Get) -replace "")
[IO.File]::WriteAllLines($file, $content)
}
}
17 changes: 17 additions & 0 deletions example-scripts/powershell/PostCommitXMIExport.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Create the EA object
Echo "Create EA"
$ea = New-Object -ComObject "EA.Repository" -Strict
Echo "Created EA"
$ea.OpenFile("C:\github\LemonTree.Automation.Workflows\DemoModel.eapx")

foreach($model in $ea.models)
{
echo $model.PackageGUID
}



$theProject = $ea.GetProjectInterface();
$theProject.ExportPackageXMI("{02BAEABD-6A12-4489-BCA3-8D33C05B81DB}",22,0,-1,0,0,"C:\github\LemonTree.Automation.Workflows\export.xmi");
$ea.CloseFile()
$ea.Exit()
58 changes: 58 additions & 0 deletions example-scripts/powershell/post-commit.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#powershell script to run from the post-commit file in ./git/hooks
#It will publish an XMI file to in our case Nexus to be used by pipelinetools that handle EA XMI
#to embedded this script in your hook file simply add the next line to the post-commit file.
#c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy RemoteSigned -File 'example-scripts\powershell\post-commit.ps1'

#Parameters
#need to be setup for your repo
$eaModel = "DemoModel.eapx"

#prepare environment
Write-Output "post-commit publish of XMI to Nexus"
$repoPath = git rev-parse --show-toplevel
$modelfile = Join-Path -Path $repoPath -ChildPath $eaModel
$gitcommitId = git rev-parse HEAD

#prepare upload to Artifact Provider
$file = Join-Path -Path $repoPath -ChildPath "..\nexus.inf"
$file = [System.IO.Path]::GetFullPath($file)
#not the savest way on earth but a pragmatic solution for the sake of this demo
$SecureCredential = Get-Content "$file" | ConvertTo-SecureString
$login = (New-Object PSCredential "username",$SecureCredential).GetNetworkCredential().Password
$targetUrl = "https://nexus.lieberlieber.com/repository/xmi/"

#start EA and load the Model
Write-Output "Create EA"
$ea = New-Object -ComObject "EA.Repository" -Strict
Write-Output "Created EA Instance"
Write-Output "Model File : $modelfile"
Write-Output "Open Model"
$ea.OpenFile($modelfile)
$theProject = $ea.GetProjectInterface();

#XMI Export one file per Model Root
Write-Output "Running XMI Export"
foreach($model in $ea.models)
{
$modelName = $model.Name
$packageGuid = $model.PackageGUID
#we don't want to upload the LemonTree.Components Stuff
if (-Not $modelName.Equals("MPMS Specification and Configuration"))
{
$xmiFileName = "$gitcommitId-$modelName.xmi"
$xmiFile = Join-Path -Path $repoPath -ChildPath "$xmiFileName"
Write-Output "Exporting $modelName with $packageGuid to $xmiFile"
$result = $theProject.ExportPackageXMI("$packageGuid",22,0,-1,0,0,$xmiFile);

Write-Output "Uploading $xmiFile to Nexus: $targetUrl"
#it only works like this for me with curl.exe
&curl.exe "-u$login" -T "$xmiFile" "$targetUrl"
}
}
Write-Output "Finished XMI Export"

#cleanup
$ea.CloseFile()
$ea.Exit()
Write-Output "Disposed EA"
Write-Output "Finished"

0 comments on commit 3108925

Please sign in to comment.