Skip to content

Commit

Permalink
update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
OS-martacarlos committed Jul 22, 2024
1 parent 3f72946 commit 79e85c3
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 44 deletions.
25 changes: 8 additions & 17 deletions .github/workflows/o11_change_extensibility.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
name: (O11) Update Extensibility

on:
workflow_dispatch:
workflow_call:
inputs:
tag:
description: 'The repo version tag'
required: true
default: '0.0.1'
type: string
forgeVersion:
description: 'The plugin version on the forge'
required: true
default: '0.0.1'
type: string
mabsMin:
description: 'Minimum MABS version'
required: true
default: '9.0.0'
enviroment:
description: 'O11 Enviorment'
type: string
environment:
required: true
default: enmobile11-dev.outsystemsenterprise.com
type: choice
options:
- enmobile11-dev.outsystemsenterprise.com
- enmobile11-tst.outsystemsenterprise.com
- enmobile11.outsystemsenterprise.com
type: string

jobs:
deploy:
update:
name: Change OML Extensibility
runs-on: ubuntu-latest
steps:
Expand All @@ -42,5 +33,5 @@ jobs:
run: npm install

- name: Update Extensibility Configurations JSON
run: npm run update:tag --plugin=BarcodeAutomation --name="Barcode Automation" --mabs=${{ github.event.inputs.mabsMin }} --environment=${{ github.event.inputs.enviroment }} --repository=${{ github.repository }} --forge=${{ github.event.inputs.forgeVersion }} --branch=${{ github.event.inputs.tag }} --authentication="${{ secrets.BASICAUTH }}"
run: npm run update:tag --plugin=BarcodeAutomation --name="InAppBrowser Plugin" --mabs=${{ inputs.mabsMin }} --environment=${{ inputs.environment }} --repository=${{ github.repository }} --forge=${{ inputs.forgeVersion }} --branch=${{ inputs.tag }} --authentication="${{ secrets.BASICAUTH }}"

4 changes: 2 additions & 2 deletions .github/workflows/o11_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:

jobs:
deploy:
name: Deploy to ${{ github.event.inputs.to }}
name: Deploy to ${{ inputs.to }}
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -38,5 +38,5 @@ jobs:
run: npm install

- name: Deploying from DEV to TST
run: npm run deploy --plugin=BarcodeAutomation --from=Development --to=Testing --lifetime=${{ secrets.LIFETIME }} --authentication=${{ secrets.AUTOMATION_TOKEN }}
run: npm run deploy --plugin=BarcodeAutomation --from=${{ inputs.from }} --to=${{ inputs.to }} --lifetime=${{ secrets.LIFETIME }} --authentication='${{ secrets.AUTOMATION_TOKEN }}'

32 changes: 30 additions & 2 deletions .github/workflows/o11_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,36 @@ name: (O11) Release Plugin

on:
pull_request:
workflow_dispatch:
inputs:
tag:
description: 'The repo version tag'
required: true
default: '0.0.1'
forgeVersion:
description: 'The plugin version on the forge'
required: true
default: '0.0.1'
mabsMin:
description: 'Minimum MABS version'
required: true
default: '9.0.0'

jobs:
change-extesnsibility:
uses: ./.github/workflows/o11_change_extensibility.yml
name: Update OML Extensibility
with:
tag: ${{ inputs.tag }}
forgeVersion: ${{ inputs.forgeVersion }}
mabsMin: ${{ inputs.mabsMin }}
environment: enmobile11-dev.outsystemsenterprise.com


deploy:
name: Release plugin via LifeTime
runs-on: ubuntu-latest
needs: change-extesnsibility
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -18,10 +43,13 @@ jobs:

- name: Install dependencies
run: npm install

- name: Tag Plugin with Version
run: npm run update:version --plugin=BarcodeAutomation --lifetime=${{ secrets.LIFETIME}} --authentication='${{secrets.AUTOMATION_TOKEN}}'

- name: Deploying from DEV to TST
run: npm run deploy --plugin=BarcodeAutomation --from=Development --to=Testing --lifetime=${{ secrets.LIFETIME }} --authentication=${{ secrets.AUTOMATION_TOKEN }}
run: npm run deploy --plugin=BarcodeAutomation --from=Development --to=Testing --lifetime=${{ secrets.LIFETIME }} --authentication='${{ secrets.AUTOMATION_TOKEN }}'

- name: Deploying from TST to PROD
run: npm run deploy --plugin=BarcodeAutomation --from=Testing --to=Production --lifetime=${{ secrets.LIFETIME }} --authentication=${{ secrets.AUTOMATION_TOKEN }}
run: npm run deploy --plugin=BarcodeAutomation --from=Testing --to=Production --lifetime=${{ secrets.LIFETIME }} --authentication='${{ secrets.AUTOMATION_TOKEN }}'

7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
],
"scripts": {
"update:tag": "node ./scripts/change-extensibility.js",
"deploy": "node ./scripts/deploy.js",
"bump:version:major": "node ./scripts/bump-version major",
"bump:version:minor": "node ./scripts/bump-version minor",
"bump:version:patch": "node ./scripts/bump-version patch",
"bump:version:pre": "node ./scripts/bump-version prerelease"
"update:version": "node ./scripts/tag-applications-o11.js",
"deploy": "node ./scripts/deploy.js"
},
"devDependencies": {

Expand Down
41 changes: 23 additions & 18 deletions scripts/change-extensibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let url = "https://" + environment + "/CodeUpdater/rest/Bulk/ExtensabilityUpdate

let extensibilityChangeJson = {
plugin :{
url: repository+"#"+branch,
url: `https://${repository}#${branch}`,
},
metadata: {
"mabs-min": mabsMin ? mabsMin : "9.0.0",
Expand All @@ -31,7 +31,7 @@ let extensibilityChangeJson = {
}

console.log(extensibilityChangeJson);
let extensibilityChangeString = JSON.stringify(extensibilityChangeJson);
let extensibilityChangeString = JSON.stringify(extensibilityChangeJson, null, '\t');
let buffer = new Buffer.from(extensibilityChangeString);
let base64 = buffer.toString('base64');

Expand All @@ -42,27 +42,32 @@ let body = [{

console.log(
"Started changing extensibility in module " + pluginSpaceName +
".\n -- Extensibility will be configured to: " + repository+"#"+branch +
".\n -- Extensibility will be configured to: " + extensibilityChangeJson.plugin.url +
`\n with forge version ${pluginForgeVersion} and mabs min ${mabsMin}` +
"\nin environment:" + environment
);



const response = fetch(url, {
method: "POST", // *GET, POST, PUT, DELETE, etc.
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
credentials: "same-origin", // include, *same-origin, omit
headers: {
"Content-Type": "application/json",
Authorization: basicAuthentication
},
body: JSON.stringify(body), // body data type must match "Content-Type" header
}).then((res) => {
if(res.ok && res.status == 200)
async function updateOML() {
const response = await fetch(url, {
method: "POST", // *GET, POST, PUT, DELETE, etc.
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
credentials: "same-origin", // include, *same-origin, omit
headers: {
"Content-Type": "application/json",
Authorization: basicAuthentication
},
body: JSON.stringify(body), // body data type must match "Content-Type" header
})

if(response.ok && response.status == 200)
console.log("Successfully updated OML");
else console.log(res)
})


else {
let error = await response.text();
console.error(error)
throw Error("Couldn't update extensibility.")
}
}

updateOML()
141 changes: 141 additions & 0 deletions scripts/tag-applications-o11.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
async function getEnvironmentKey(base, env, auth){
let url = `${base}/environments`;

let response = await fetch(url, {
method: 'GET',
headers: {
Authorization: auth
}
})

if(response.ok && response.status == 200){
let list = await response.json();
return (list.filter((detail) => detail.Name == env)[0]).Key
}

console.log(response.status)
let answer = await response.text()
console.log(answer)
throw Error("Couldn't get environment key. Please check logs for more info.")

}

async function getAppKey(base, pluginSpaceName, auth){
let url = `${base}/applications?IncludeEnvStatus=true`;

let response = await fetch(url, {
method: 'GET',
headers: {
Authorization: auth
}
})

if(response.ok && response.status == 200){
let list = await response.json();

let app = list.filter((a) => a.Name == pluginSpaceName)[0];
return app.Key
}
}

async function getModules(base, pluginKey, inEnv, auth){
let url = `${base}/environments/${inEnv}/applications/${pluginKey}?IncludeEnvStatus=true&IncludeModules=true`;

let response = await fetch(url, {
method: 'GET',
headers: {
Authorization: auth
}
})

if(response.ok && response.status == 200){
let app = await response.json();
return app.AppStatusInEnvs[0].ModuleStatusInEnvs.map((m) => m.ModuleVersionKey )
}
}


async function getLatestAppVersion(base, appKey, auth) {
let url = `${base}/applications/${appKey}/versions`;

let response = await fetch(url, {
method: 'GET',
headers: {
Authorization: auth
}
})

if(response.ok && response.status == 200){
let list = await response.json();

if(list.length > 0)
return list[0].Version;
return '1.0.0';
}
}

async function createVersion(base, appKey, inEnv, version, modules, auth){
let url = `${base}/environments/${inEnv}/applications/${appKey}/versions`;
let body = {
ChangeLog: "New version created by github action",
Version: version,
MobileVersions: [],
ModuleVersionKeys: modules

}
let response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: auth
},
body: JSON.stringify(body)
})

if(response.ok && response.status == 201){
let res = await response.json();
return res.ApplicationVersionKey;
}

console.log(response.status)
let answer = await response.text()
console.log(answer)
throw Error("Coulnd't tag application.")


}

async function tagApp(baseURL, pluginSpaceName, auth){
let fromKey = await getEnvironmentKey(baseURL, "Development", auth);
let pluginKey = await getAppKey(baseURL, pluginSpaceName, auth);
console.log(`plugin key: ${pluginKey}`);

let modules = await getModules(baseURL, pluginKey, fromKey, auth);
console.log(modules)

let version = await getLatestAppVersion(baseURL,pluginKey, auth);
console.log(`last tagged version: ${version}`);

let [_, major, minor, patch] = version.match(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/) ?? [];
let newVersion = `${major}.${minor}.${parseInt(patch) + 1}`;
console.log(`next version: ${newVersion}`);

let appKey = await createVersion(baseURL, pluginKey, fromKey, newVersion, modules, auth);
console.log(`new plugin version tag created, app key is ${appKey}`)
}



if(process.env.npm_config_authentication == null) {
throw new Error("Missing authentication argument");
}

let pluginSpaceName = process.env.npm_config_plugin;
let authentication = process.env.npm_config_authentication;
let baseURL = process.env.npm_config_lifetime;

baseURL = `https://${baseURL}/lifetimeapi/rest/v2`;

tagApp(baseURL, pluginSpaceName, authentication);


0 comments on commit 79e85c3

Please sign in to comment.