-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
170 create xmi after git commit and upload to nexus (#171)
Post Commit XMI Upload and Download in a GitHub Action
- Loading branch information
1 parent
8ad0af0
commit 3108925
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |