diff --git a/.gitignore b/.gitignore index d822f98..19556bf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ .eslintcache coverage node_modules -out \ No newline at end of file +out diff --git a/bamboo-specs/bamboo.yaml b/bamboo-specs/bamboo.yaml index efba2f3..bb78e16 100644 --- a/bamboo-specs/bamboo.yaml +++ b/bamboo-specs/bamboo.yaml @@ -3,3 +3,6 @@ --- !include 'increment.yaml' + +--- +!include 'build.yaml' diff --git a/bamboo-specs/build.yaml b/bamboo-specs/build.yaml new file mode 100644 index 0000000..3310a08 --- /dev/null +++ b/bamboo-specs/build.yaml @@ -0,0 +1,68 @@ +--- +version: 2 +plan: + project-key: AJL + key: VSCODEADBLOCKSYNTAXBUILD + name: vscode adblock syntax - build release +variables: + dockerNode: adguard/node-ssh:18.13--0 + +stages: + - Build: + manual: false + final: false + jobs: + - Build + +Build: + key: BUILD + other: + clean-working-dir: true + docker: + image: ${bamboo.dockerNode} + volumes: + ${system.YARN_DIR}: "${bamboo.cacheYarn}" + tasks: + - checkout: + force-clean-build: true + - script: + interpreter: SHELL + scripts: + - |- + set -x + set -e + ls -al + + yarn install ${bamboo.varsYarn} + yarn build-txt + + rm -rf node_modules + - inject-variables: + file: dist/build.txt + scope: RESULT + namespace: inject + - any-task: + plugin-key: com.atlassian.bamboo.plugins.vcs:task.vcs.tagging + configuration: + selectedRepository: defaultRepository + tagName: v${bamboo.inject.version} + requirements: + - adg-docker: true + +triggers: [] + +branches: + create: manually + delete: never + link-to-jira: true + +notifications: + - events: + - plan-status-changed + recipients: + - webhook: + name: Build webhook + url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo +labels: [] +other: + concurrent-build-plugin: system-default diff --git a/package.json b/package.json index 7c8d56d..bd00c62 100644 --- a/package.json +++ b/package.json @@ -101,6 +101,7 @@ "lint:md": "markdownlint .", "lint:ts": "eslint . --cache --ext .ts", "test": "jest", + "build-txt": "ts-node-esm tools/build-txt.ts", "increment": "yarn version --patch --no-git-tag-version", "generate-vsix": "vsce package --yarn --out vscode-adblock.vsix", "postinstall": "cd client && yarn && cd ../server && yarn && cd ..", diff --git a/tools/build-txt.ts b/tools/build-txt.ts new file mode 100644 index 0000000..c2203e5 --- /dev/null +++ b/tools/build-txt.ts @@ -0,0 +1,40 @@ +/** + * @file Output the version number to a build.txt file + */ +import fs from 'fs'; +import path from 'path'; + +const UPPER_LEVEL = '../'; + +const OUTPUT_FOLDER_NAME = 'out'; +const OUTPUT_FILE_NAME = 'build.txt'; +const PKG_FILE_NAME = 'package.json'; + +// Computed constants +const outputFolderLocation = path.join(__dirname, UPPER_LEVEL, OUTPUT_FOLDER_NAME); +const pkgFileLocation = path.join(__dirname, UPPER_LEVEL, PKG_FILE_NAME); + +// Read package.json +const pkg = JSON.parse(fs.readFileSync(pkgFileLocation, 'utf-8')); + +if (!pkg.version) { + throw new Error('Missing required field "version" in package.json'); +} + +const main = (): void => { + const content = `version=${pkg.version}`; + + // Create the output folder if it doesn't exist + if (!fs.existsSync(outputFolderLocation)) { + fs.mkdirSync(outputFolderLocation); + } + + // Write the output file + const file = path.resolve(outputFolderLocation, OUTPUT_FILE_NAME); + fs.writeFileSync(file, content); + + // eslint-disable-next-line no-console + console.log(`Wrote ${content} to ${file} was successful`); +}; + +main();