-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #645 from adobecom/MWPW-145723
MWPW-145723 Automate EdgeWorker bundle version increment
- Loading branch information
Showing
4 changed files
with
233 additions
and
6 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 |
---|---|---|
|
@@ -14,8 +14,8 @@ on: | |
required: true | ||
default: 'Acrobat_DC_web_stg' | ||
options: | ||
- 'Acrobat_DC_web_stg' | ||
- 'Acrobat_DC_web_prod' | ||
- 'Acrobat_DC_web_stg' | ||
- 'Acrobat_DC_web_prod' | ||
network: | ||
description: 'Network' | ||
type: choice | ||
|
@@ -24,6 +24,11 @@ on: | |
options: | ||
- 'staging' | ||
- 'production' | ||
description: | ||
description: 'Bundle Description' | ||
type: string | ||
required: true | ||
default: 'Bundle Description' | ||
|
||
jobs: | ||
deploy-edgeworker: | ||
|
@@ -38,8 +43,11 @@ jobs: | |
- name: Build Edge Worker Scripts | ||
run: | | ||
npm run ewbuild | ||
npm run ewprod2stg | ||
npm run ewprod2stg | ||
npm run ewsetbundle ${{ inputs.edgeworker }} "${{ inputs.description }}" | ||
env: | ||
EDGERC: ${{ secrets.AKAMAI_EDGERC }} | ||
|
||
- name: Deploy Edge Worker | ||
uses: jdmevo123/[email protected] | ||
env: | ||
|
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,89 @@ | ||
/** | ||
* Environment variables: | ||
* - EDGERC: The content of the .edgerc file | ||
* Command Arguments: | ||
* - edgeworker name: The name of the EdgeWorker | ||
* example: 'Acrobat_DC_web_prod' or 'Acrobat_DC_web_stg' | ||
* - description: The description of the bundle | ||
*/ | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
const EdgeGrid = require('akamai-edgegrid'); | ||
const { compareVersions } = require('compare-versions'); | ||
|
||
const egSend = (eg, path, method, body) => { | ||
eg.auth({ path, method, body }); | ||
|
||
return new Promise((resolve, reject) => { | ||
eg.send(function (error, response, body) { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(JSON.parse(body)); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
|
||
async function main() { | ||
const edgeworkerName = process.argv.length > 2 ? process.argv[2] : null; | ||
const description = process.argv.length > 3 ? process.argv[3] : null; | ||
|
||
if (!edgeworkerName) { | ||
console.error('Please provide the name of the EdgeWorker'); | ||
process.exit(1); | ||
} | ||
|
||
if (process.env.EDGERC) { | ||
fs.writeFileSync('.edgerc', process.env.EDGERC, 'utf8'); | ||
} | ||
|
||
const edgercPath = fs.existsSync('.edgerc') ? '.edgerc' : `${os.homedir()}/.edgerc`; | ||
|
||
const eg = new EdgeGrid({ path: edgercPath, section: 'edgeworkers' }); | ||
|
||
let body = await egSend(eg, '/edgeworkers/v1/ids', 'GET'); | ||
const edgeWorkers = body.edgeWorkerIds; | ||
const edgeWorker = edgeWorkers.find((ew) => ew.name === edgeworkerName); | ||
|
||
if (!edgeWorker) { | ||
console.error(`EdgeWorker ${edgeworkerName} not found`); | ||
process.exit(1); | ||
} | ||
|
||
body = await egSend( | ||
eg, | ||
`/edgeworkers/v1/ids/${edgeWorker.edgeWorkerId}/versions`, | ||
'GET' | ||
); | ||
const versions = body.versions.map((x) => x.version).sort(compareVersions); | ||
const latestVersion = versions[versions.length - 1]; | ||
|
||
console.log(`The latest version of ${edgeworkerName} is ${latestVersion}`); | ||
|
||
const bundleJsonPath = `edgeworkers/${edgeworkerName}/bundle.json`; | ||
|
||
if (!fs.existsSync(bundleJsonPath)) { | ||
console.error(`Bundle file ${bundleJsonPath} not found`); | ||
process.exit(1); | ||
} | ||
|
||
let bundleJson = JSON.parse(fs.readFileSync(bundleJsonPath, 'utf8')); | ||
|
||
let versionSegs = latestVersion.split('.').map(x => parseInt(x)); | ||
versionSegs[versionSegs.length - 1] += 1; | ||
|
||
bundleJson['edgeworker-version'] = versionSegs.join('.'); | ||
|
||
if (description) { | ||
bundleJson.description = description; | ||
} | ||
|
||
console.log(`New bundle info: ${JSON.stringify(bundleJson, null, 2)}`); | ||
|
||
fs.writeFileSync(bundleJsonPath, JSON.stringify(bundleJson, null, 2), 'utf8'); | ||
} | ||
|
||
main(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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