Skip to content

Commit

Permalink
feat: add github release automation
Browse files Browse the repository at this point in the history
  • Loading branch information
OS-martacarlos committed Jul 24, 2024
1 parent 954021c commit 49fbdf1
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 103 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/o11_change_extensibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ on:
required: true
type: string
tag:
description: 'The repo version tag'
required: true
type: string
forgeVersion:
description: 'The plugin version on the forge'
required: true
type: string
mabsMin:
description: 'Minimum MABS version'
required: true
type: string
environment:
description: 'The environment where the plugin resides'
required: true
type: string

jobs:
update:
name: Change OML Extensibility
name: '✍🏻 Change OML Extensibility'
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/o11_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ on:
required: true
default: Testing
type: string

from:
description: 'Source O11 Enviorment'
required: true
Expand All @@ -21,7 +20,7 @@ on:

jobs:
deploy:
name: Deploy to ${{ inputs.to }}
name: '🚀 Deploy to ${{ inputs.to }}'
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -35,6 +34,6 @@ jobs:
- name: Install dependencies
run: npm install

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

48 changes: 48 additions & 0 deletions .github/workflows/o11_github_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Github Release

on:
workflow_call:
inputs:
tag:
required: true
type: string
plugin:
description: 'Plugin'
required: true
type: string
environment:
description: 'The O11 environment we are downloading from'
required: true
type: string
notes:
description: 'The release notes'
required: true
type: string

jobs:
download:
name: '📦 Download OAP'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: Install dependencies
run: npm install

- name: '⬇️ Download the O11 OAP from LifeTime'
id: download_file
run: npm run download --plugin=${{inputs.plugin}} --environment=${{inputs.environment}} --lifetime=${{ secrets.LIFETIME }} --authentication='${{ secrets.AUTOMATION_TOKEN }}'

- name: '🚀 Create GitHub Release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ls
ls downloads
gh release create ${{ inputs.tag }} './downloads/asset.oap' -t "${{inputs.tag}}" -n "${{inputs.notes}}" --latest=false
25 changes: 19 additions & 6 deletions .github/workflows/o11_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,26 @@ on:
description: 'Minimum MABS version'
required: true
type: string

releaseNotes:
description: 'Release Notes'
required: true
type: string

jobs:
change-extensibility:
uses: ./.github/workflows/o11_change_extensibility.yml
name: Update OML Extensibility
name: '✍🏻 Update OML Extensibility'
secrets: inherit
with:
plugin: BarcodeAutomation
plugin: BarcodeAutomation
configName: InAppBrowser Plugin
tag: ${{ github.event.inputs.tag }}
forgeVersion: ${{ github.event.inputs.forgeVersion }}
mabsMin: ${{ github.event.inputs.mabsMin }}
environment: enmobile11-dev.outsystemsenterprise.com


deploy:
name: Release plugin via LifeTime
name: '🔌 Deploy plugin across LifeTime'
runs-on: ubuntu-latest
needs: change-extensibility
steps:
Expand Down Expand Up @@ -61,4 +63,15 @@ jobs:

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


release:
uses: ./.github/workflows/o11_github_release.yml
name: '🚀 Create Github release'
secrets: inherit
needs: deploy
with:
tag: ${{ github.event.inputs.tag }}
environment: Production
plugin: BarcodeAutomation
notes: ${{ github.event.inputs.releaseNotes }}

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"build": "rimraf ./dist && vite build",
"update:tag": "node ./scripts/change-extensibility.js",
"update:version": "node ./scripts/tag-applications-o11.js",
"deploy": "node ./scripts/deploy.js"
"deploy": "node ./scripts/deploy.js",
"download": "node ./scripts/download.js"
},
"engines": [],
"devDependencies": {
Expand Down
28 changes: 4 additions & 24 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
const utils = require('./utils')

async function getEnvironmentKey(base, env, auth){
let url = `${base}/environments`;

let response = await fetch(url, {
method: 'GET',
headers: {
"Content-Type": "application/json",
Authorization: auth
}
})

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

async function getLatestTagKey(base, pluginKey, auth){
let url = `${base}/applications/${pluginKey}/versions`;
Expand Down Expand Up @@ -138,8 +121,8 @@ baseURL = `https://${baseURL}/lifetimeapi/rest/v2`;
startDeploy(baseURL, fromEnvironment, toEnvironment, pluginSpaceName, basicAuthentication);

async function startDeploy(baseURL, fromEnvironment, toEnvironment, pluginSpaceName, auth){
let fromKey = await getEnvironmentKey(baseURL, fromEnvironment, auth);
let toKey = await getEnvironmentKey(baseURL, toEnvironment, auth);
let fromKey = await utils.getEnvironmentKey(baseURL, fromEnvironment, auth);
let toKey = await utils.getEnvironmentKey(baseURL, toEnvironment, auth);

let pluginKey = await utils.getAppKey(baseURL, pluginSpaceName, auth);
console.log(`plugin key: ${pluginKey}`)
Expand All @@ -166,7 +149,4 @@ async function startDeploy(baseURL, fromEnvironment, toEnvironment, pluginSpaceN
}, 10000)


}



}
64 changes: 64 additions & 0 deletions scripts/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const utils = require('./utils');
const fs = require("fs");
const { finished } = require('stream/promises');
const { Readable } = require('stream');
const path = require("path");


const DOWNLOAD_FOLDER = "downloads";

async function download(url) {

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

if(!response.ok || response.status != 200) {
let error = await response.text();
console.error(error);
throw Error("Couldn't download file :(((.")
}
let file = response.body;

if (!fs.existsSync(DOWNLOAD_FOLDER)){
console.log("Create downloads folder: " + DOWNLOAD_FOLDER);
fs.mkdirSync(DOWNLOAD_FOLDER);
}

const destination = path.resolve(`./${DOWNLOAD_FOLDER}/asset.oap`);
const fileStream = fs.createWriteStream(destination, { flags: 'wx' });
await finished(Readable.fromWeb(file).pipe(fileStream));
console.log(`Finifhed writing to ${destination}`);
}


async function downloadOAP(baseURL, pluginName, inEnv, auth) {
let envKey = await utils.getEnvironmentKey(baseURL, inEnv, auth);
let pluginKey = await utils.getAppKey(baseURL, pluginName, auth);

let downloadEndpoint = `${baseURL}/environments/${envKey}/applications/${pluginKey}/content`
const response = await fetch(downloadEndpoint, {
method: 'GET',
headers: {
Authorization: auth
}
})

if(response.ok && response.status == 200){
let downloadInfo = await response.json()
await download(downloadInfo.url)
}
}

let pluginSpaceName = process.env.npm_config_plugin;
let baseURL = process.env.npm_config_lifetime;
let auth = process.env.npm_config_authentication;
let environment = process.env.npm_config_environment;
baseURL = `https://${baseURL}/lifetimeapi/rest/v2`;



downloadOAP(baseURL, pluginSpaceName, environment, auth)
66 changes: 4 additions & 62 deletions scripts/tag-applications-o11.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
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
}
}
const utils = require('./utils')

async function getModules(base, pluginKey, inEnv, auth){
let url = `${base}/environments/${inEnv}/applications/${pluginKey}?IncludeEnvStatus=true&IncludeModules=true`;
Expand All @@ -54,26 +16,6 @@ async function getModules(base, pluginKey, inEnv, auth){
}
}


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 = {
Expand Down Expand Up @@ -106,14 +48,14 @@ async function createVersion(base, appKey, inEnv, version, modules, auth){
}

async function tagApp(baseURL, pluginSpaceName, auth){
let fromKey = await getEnvironmentKey(baseURL, "Development", auth);
let pluginKey = await getAppKey(baseURL, pluginSpaceName, auth);
let fromKey = await utils.getEnvironmentKey(baseURL, "Development", auth);
let pluginKey = await utils.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);
let version = await utils.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-]+)*))?$/) ?? [];
Expand Down
Loading

0 comments on commit 49fbdf1

Please sign in to comment.