diff --git a/.github/workflows/o11_change_extensibility.yml b/.github/workflows/o11_change_extensibility.yml index 8801fe3..97f9db0 100644 --- a/.github/workflows/o11_change_extensibility.yml +++ b/.github/workflows/o11_change_extensibility.yml @@ -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: @@ -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 }}" diff --git a/.github/workflows/o11_deploy.yml b/.github/workflows/o11_deploy.yml index 715d249..3afa5e6 100644 --- a/.github/workflows/o11_deploy.yml +++ b/.github/workflows/o11_deploy.yml @@ -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 @@ -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 }}' diff --git a/.github/workflows/o11_release.yml b/.github/workflows/o11_release.yml index 3cccef6..3a575c2 100644 --- a/.github/workflows/o11_release.yml +++ b/.github/workflows/o11_release.yml @@ -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 @@ -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 }}' diff --git a/package.json b/package.json index 8133659..24f2d56 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/scripts/change-extensibility.js b/scripts/change-extensibility.js index 2f9ae0b..0a5a9e6 100644 --- a/scripts/change-extensibility.js +++ b/scripts/change-extensibility.js @@ -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", @@ -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'); @@ -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() \ No newline at end of file diff --git a/scripts/tag-applications-o11.js b/scripts/tag-applications-o11.js new file mode 100644 index 0000000..0b0343b --- /dev/null +++ b/scripts/tag-applications-o11.js @@ -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); + +