-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds actions for detecting changes in PRs and uploading them to a sem…
…antic hub
- Loading branch information
Showing
8 changed files
with
628 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!-- | ||
####################################################################### | ||
# Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
# | ||
# See the NOTICE file(s) distributed with this work for additional | ||
# information regarding copyright ownership. | ||
# | ||
# This work is made available under the terms of the | ||
# Creative Commons Attribution 4.0 International (CC-BY-4.0) license, | ||
# which is available at | ||
# https://creativecommons.org/licenses/by/4.0/legalcode. | ||
# | ||
# SPDX-License-Identifier: CC-BY-4.0 | ||
####################################################################### | ||
--> | ||
# Upload Action | ||
This action expects an JSON file with models to upload and URNs to delete in the current root directory. Based on this information, the action synchronizes the changes in the Git repository to a Semantic Hub instance. The action thus further requires the URL to the Semantic Hub instance and a token to access this instance as input paramters. | ||
|
||
## Test Cases | ||
For future developments, we propose the following test cases to be evaluated: | ||
|
||
### main branch | ||
|
||
| Model | metadata.json | expected deployed model status | | ||
----| ---- | ----- | | ||
add model | add with status RELEASED | RELEASED | ||
add model | none | RELEASED | ||
existing model | add metadata.json with status DEPRECATED | DEPRECATED | ||
add model | existing metadata.json with status DEPRECATED | DEPRECATED | ||
add two models to same namespace | add with status RELEASED | one model RELEASED and warning | ||
add two models to same namespace | none | one model RELEASED (no warning yet) | ||
delete model with status DEPRECATED | not relevant | model is deleted in Semantic Hub | ||
delete model with status RELEASED | not relevant | model is still and Semantic Hub and log error response from Semantic Hub that model cannot be deleted | ||
modify model | no addition or modification | log warning and no update of model in Semantic Hub | ||
|
||
### other branch | ||
On any other branch besides the main-branch the metadata.json should be ignored. This results in the following test cases: | ||
|
||
| Model | metadata.json | expected deployed model status | | ||
----| ---- | ----- | | ||
add model | none | DRAFT | ||
add model | add metadata.json with status DEPRECATED | DRAFT | ||
existing model | add metadata.json with status RELEASED | DRAFT | ||
delete model | not relevant | delete model from Semantic Hub | ||
|
||
|
||
|
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,27 @@ | ||
####################################################################### | ||
# Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
# | ||
# See the NOTICE file(s) distributed with this work for additional | ||
# information regarding copyright ownership. | ||
# | ||
# This work is made available under the terms of the | ||
# Creative Commons Attribution 4.0 International (CC-BY-4.0) license, | ||
# which is available at | ||
# https://creativecommons.org/licenses/by/4.0/legalcode. | ||
# | ||
# SPDX-License-Identifier: CC-BY-4.0 | ||
####################################################################### | ||
name: 'Upload Changes' | ||
description: 'Action to upload detected changes to a Semantic Hub' | ||
inputs: | ||
TOKEN: | ||
description: 'The token to acces the instance of the Semantic Hub' | ||
required: true | ||
SEMANTIC_HUB_URL: | ||
description: 'The url of the instance of the Semantic Hub' | ||
required: true | ||
|
||
runs: | ||
using: "node16" | ||
main: 'index.js' | ||
|
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,109 @@ | ||
/* | ||
# Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
# | ||
# See the NOTICE file(s) distributed with this work for additional | ||
# information regarding copyright ownership. | ||
# | ||
# This work is made available under the terms of the | ||
# Creative Commons Attribution 4.0 International (CC-BY-4.0) license, | ||
# which is available at | ||
# https://creativecommons.org/licenses/by/4.0/legalcode. | ||
# | ||
# SPDX-License-Identifier: CC-BY-4.0 | ||
*/ | ||
var cp = require('child_process') | ||
var path = require('path') | ||
var fs = require('fs') | ||
var https = require('node:https'); | ||
|
||
try { | ||
console.log("Welcome to the Upload Action"); | ||
const token = getInput('TOKEN'); | ||
const hub = getInput("SEMANTIC_HUB_URL"); | ||
const output = JSON.parse(fs.readFileSync("output.json", 'utf8')); | ||
|
||
for (let aspect of output.upload) { | ||
console.log("About to upload: " + aspect.model) | ||
uploadAspect(aspect, hub, token) | ||
} | ||
for (let urn of output.delete) { | ||
console.log("About to delete: " + urn) | ||
deleteAspect(urn, hub, token) | ||
} | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
|
||
function uploadAspect(aspect, hub, token) { | ||
|
||
console.log(hub) | ||
if (token == "") { | ||
console.log("Token is empty") | ||
} | ||
var options = { | ||
'method': 'POST', | ||
'host': hub, | ||
'path': '/hub/api/v1/models?type=BAMM&status=' + aspect.status, | ||
'headers': { | ||
'Authorization': 'Bearer ' + token, | ||
'Content-Type': 'text/plain' | ||
}, | ||
}; | ||
|
||
var req = https.request(options, function (res) { | ||
var chunks = []; | ||
|
||
res.on("data", function (chunk) { | ||
chunks.push(chunk); | ||
}); | ||
|
||
res.on("end", function (chunk) { | ||
var body = Buffer.concat(chunks); | ||
console.log(body.toString()); | ||
}); | ||
|
||
res.on("error", function (error) { | ||
console.error(error); | ||
}); | ||
}); | ||
|
||
req.write(aspect.model); | ||
|
||
req.end() | ||
} | ||
|
||
function deleteAspect(urn, hub, token) { | ||
var options = { | ||
'method': 'DELETE', | ||
'hostname': hub, | ||
'path': '/hub/api/v1/models/' + urn, | ||
'headers': { | ||
'Authorization': 'Bearer ' + token, | ||
}, | ||
'maxRedirects': 20 | ||
}; | ||
|
||
var req = https.request(options, function (res) { | ||
var chunks = []; | ||
|
||
res.on("data", function (chunk) { | ||
chunks.push(chunk); | ||
}); | ||
|
||
res.on("end", function (chunk) { | ||
var body = Buffer.concat(chunks); | ||
console.log(body.toString()); | ||
}); | ||
|
||
res.on("error", function (error) { | ||
console.error(error); | ||
}); | ||
}); | ||
|
||
req.end(); | ||
} | ||
|
||
function getInput(name) { | ||
const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''; | ||
return val.trim(); | ||
} |
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,51 @@ | ||
<!-- | ||
####################################################################### | ||
# Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
# | ||
# See the NOTICE file(s) distributed with this work for additional | ||
# information regarding copyright ownership. | ||
# | ||
# This work is made available under the terms of the | ||
# Creative Commons Attribution 4.0 International (CC-BY-4.0) license, | ||
# which is available at | ||
# https://creativecommons.org/licenses/by/4.0/legalcode. | ||
# | ||
# SPDX-License-Identifier: CC-BY-4.0 | ||
####################################################################### | ||
--> | ||
# Detect Changes Action | ||
This action validates whether and which changes in the repository need to be applied to an instance of the Semantic Hub beeing associtated with the repository. | ||
The action expects multiple arrays which either contain added, modified, renamed and deleted files from the last commit. | ||
|
||
The actual deployment to an Semantic Hub instance is done through the Upload-action which expects a JSON-file with the changes to apply. Because of that, the result of the validation action is an archived JSON-file communicating these detected changes. | ||
|
||
|
||
## Test Cases | ||
For future developments, we propose the following test cases to be evaluated: | ||
|
||
### main branch | ||
|
||
| Model | metadata.json | expected deployed model status | | ||
----| ---- | ----- | | ||
add model | add with status RELEASED | RELEASED | ||
add model | none | RELEASED | ||
existing model | add metadata.json with status DEPRECATED | DEPRECATED | ||
add model | existing metadata.json with status DEPRECATED | DEPRECATED | ||
add two models to same namespace | add with status RELEASED | one model RELEASED and warning | ||
add two models to same namespace | none | one model RELEASED (no warning yet) | ||
delete model with status DEPRECATED | not relevant | model is deleted in Semantic Hub | ||
delete model with status RELEASED | not relevant | model is still and Semantic Hub and log error response from Semantic Hub that model cannot be deleted | ||
modify model | no addition or modification | log warning and no update of model in Semantic Hub | ||
|
||
### other branch | ||
On any other branch besides the main-branch the metadata.json should be ignored. This results in the following test cases: | ||
|
||
| Model | metadata.json | expected deployed model status | | ||
----| ---- | ----- | | ||
add model | none | DRAFT | ||
add model | add metadata.json with status DEPRECATED | DRAFT | ||
existing model | add metadata.json with status RELEASED | DRAFT | ||
delete model | not relevant | delete model from Semantic Hub | ||
|
||
|
||
|
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,36 @@ | ||
####################################################################### | ||
# Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
# | ||
# See the NOTICE file(s) distributed with this work for additional | ||
# information regarding copyright ownership. | ||
# | ||
# This work is made available under the terms of the | ||
# Creative Commons Attribution 4.0 International (CC-BY-4.0) license, | ||
# which is available at | ||
# https://creativecommons.org/licenses/by/4.0/legalcode. | ||
# | ||
# SPDX-License-Identifier: CC-BY-4.0 | ||
####################################################################### | ||
name: 'Validate Changes' | ||
description: 'Action to validate detected changes in the repository as changes applicable to a Semantic Hub and to prepare an output.json file for the upload action' | ||
inputs: | ||
ADDED: | ||
description: 'The changed files, detected by a previous action' | ||
default: "[]" | ||
required: false | ||
MODIFIED: | ||
description: 'The modified files, detected by a previous action' | ||
default: "[]" | ||
required: false | ||
REMOVED: | ||
description: 'The removed files, detected by a previous action' | ||
default: "[]" | ||
required: false | ||
IS_MAIN: | ||
description: 'A boolean value indicating whether the action operates on the main branch (True) or another branch (False)' | ||
default: false | ||
required: false | ||
runs: | ||
using: "node16" | ||
main: 'index.js' | ||
|
Oops, something went wrong.