diff --git a/Jenkinsfile b/Jenkinsfile index 7428e9a..7b50b56 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,11 +1,22 @@ pipeline { parameters { + booleanParam(name: 'deploy', defaultValue: true, description: 'Deploy build') + booleanParam(name: 'deploy_io', defaultValue: false, description: 'Deploy build to github.io') + booleanParam(name: 'deploy_io_exchange', defaultValue: false, description: 'Exchange deployed build to github.io with previous commit') + booleanParam(name: 'store', defaultValue: false, description: 'Store build') + booleanParam(name: 'release', defaultValue: false, description: 'Release build') + booleanParam(name: 'release_comment', defaultValue: true, description: 'Add comment to each issue and pull request resolved') + password(name: 'GH_TOKEN', defaultValue: '', description: 'Github user token. Note: don\'t use a password, will be logged to console on error.') choice(name: 'destination', description: 'Destination folder', choices: ['asterics-web-devlinux/WebACS', 'asterics-web-devwindows/WebACS', 'asterics-web-production/WebACS' ]) choice(name: 'agent', description: 'Agent', choices: ['Linux', 'Win']) choice(name: 'image', description: 'Docker Image', choices: ['node:10', 'node:11']) gitParameter(name: 'BRANCH', branchFilter: 'origin.*?/(.*)', defaultValue: 'master', type: 'PT_BRANCH_TAG', useRepository: 'WebACS') } + triggers { + // pollSCM('H/15 * * * *') + pollSCM('* * * * *') + } agent none stages { stage('Cleanup') { @@ -30,6 +41,20 @@ pipeline { ''' } } + stage('Prepare: Release/Store') { + when { + anyOf { + equals expected: true, actual: params.release + equals expected: true, actual: params.store + } + } + agent { + label params.agent + } + steps { + sh 'cd dist && zip -r ../WebACS.zip *' + } + } stage('Test') { agent { docker { @@ -45,31 +70,97 @@ pipeline { ''' } } - stage('Archive') { - agent { - label params.agent - } - steps { - sh 'cd dist && zip -r ../WebACS.zip *' - archiveArtifacts artifacts: 'WebACS.zip', fingerprint: true - } - } - stage('Deploy') { - environment { - SERVER = credentials('server') - } - agent { - label params.agent - } - steps { - sh ''' - mkdir build - mv dist build/WebACS - ''' - script { - def remote = [ name: 'studyathome', host: 'studyathome.technikum-wien.at', user: env.SERVER_USR, password: env.SERVER_PSW, allowAnyHosts: true ] - sshRemove remote: remote, path: "/var/www/html/${params.destination}", failOnError: false - sshPut remote: remote, from: 'build/WebACS', into: "/var/www/html/${params.destination.replace("/WebACS", "")}" + stage('Output') { + parallel { + stage('Deploy') { + when { + equals expected: true, actual: params.deploy + } + agent { + label params.agent + } + environment { + SERVER = credentials('server') + } + steps { + sh ''' + mkdir build + ln -s ../dist build/WebACS + ''' + script { + def remote = [ name: 'studyathome', host: 'studyathome.technikum-wien.at', user: env.SERVER_USR, password: env.SERVER_PSW, allowAnyHosts: true ] + sshRemove remote: remote, path: "/var/www/html/${params.destination}", failOnError: false + sshPut remote: remote, from: 'build/WebACS', into: "/var/www/html/${params.destination.replace("/WebACS", "")}" + } + } + } + stage('Deploy: Github IO') { + when { + equals expected: true, actual: params.deploy_io + } + agent { + label params.agent + } + steps { + sh ''' + git clone -b gh-pages --single-branch https://github.com/asterics/WebACS.git gh-pages + ''' + script { + if (params.deploy_io_exchange) { + sh ''' + cd gh-pages + git log + git reset --hard HEAD~1 + git log + ''' + } + } + sh ''' + rm -rf gh-pages/* + cp -r dist/* gh-pages/ + cd gh-pages + git add . + git add -u . + git -c user.name='Mr. Jenkins' -c user.email='studyathome@technikum-wien.at' commit -m 'docs: release WebACS' + git push -f https://$GH_TOKEN@github.com/asterics/WebACS.git + ''' + } + } + stage('Store') { + when { + equals expected: true, actual: params.store + } + agent { + label params.agent + } + steps { + archiveArtifacts artifacts: 'WebACS.zip', fingerprint: true + archiveArtifacts artifacts: 'dist/build.json', fingerprint: true + } + } + stage('Release') { + when { + // branch 'master' + // changeset 'assets' + equals expected: true, actual: params.release + } + agent { + docker { + image params.image + label params.agent + } + } + environment { + GIT_BRANCH = "$BRANCH" + } + steps { + sh ''' + git checkout $BRANCH + git pull + yarn release:prepare + yarn release --branch $BRANCH + ''' + } } } } diff --git a/index.js b/index.js index bdd4a87..16f3be6 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,4 @@ import "./assets/css/webACS.css"; import webACS from "./src/webACS.js"; -// import "./node_modules/jquery-ui/ui/" - webACS(); \ No newline at end of file diff --git a/package.json b/package.json index 39a6c52..8a0eed0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "WebACS", - "version": "3.0.1", + "version": "3.0.0", "description": "Assistive Technology Rapid Integration and Construction Set", "main": "index.js", "repository": "https://github.com/asterics/WebACS.git", @@ -10,8 +10,11 @@ "scripts": { "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot", "build": "cross-env NODE_ENV=production webpack --progress --hide-modules", + "postbuild": "node src/scripts/logBuild.js", "test:watch": "cross-env NODE_ENV=test jest --watch", - "test": "cross-env NODE_ENV=test jest" + "test": "cross-env NODE_ENV=test jest", + "release": "semantic-release", + "release:prepare": "yarn add -D semantic-release@15 @semantic-release/commit-analyzer @semantic-release/changelog @semantic-release/exec" }, "devDependencies": { "@babel/cli": "^7.2.3", diff --git a/release.config.js b/release.config.js new file mode 100644 index 0000000..c2bd877 --- /dev/null +++ b/release.config.js @@ -0,0 +1,61 @@ +const { release_comment } = process.env; +const successComment = release_comment === "true" + ? ":tada: This issue has been resolved in version ${nextRelease.version} :tada:\n\nThe release is available on [GitHub release]()" + : false; + +module.exports = { + repositoryUrl: "https://github.com/asterics/WebACS", + tagFormat: "v${version}", + plugins: [ + [ + "@semantic-release/npm", + { + npmPublish: false + // tarballDir: "dist" + } + ], + [ + "@semantic-release/github", + { + assets: [{ path: "WebACS-v*.zip", label: "AsTeRICS WebACS" }, { path: "dist/build.json", label: "build.json" }], + successComment + } + ], + [ + "@semantic-release/commit-analyzer", + { + preset: "angular", + releaseRules: [{ type: "docs", scope: "README", release: "patch" }, { type: "major", release: "major" }], + parserOpts: { + noteKeywords: ["BREAKING CHANGE", "BREAKING CHANGES"] + } + } + ], + [ + "@semantic-release/release-notes-generator", + { + preset: "angular", + parserOpts: { + noteKeywords: ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"] + }, + writerOpts: { + commitsSort: ["subject", "scope"] + } + } + ], + [ + "@semantic-release/changelog", + { + changelogFile: "CHANGELOG.md" + } + ], + [ + "@semantic-release/exec", + { + prepareCmd: "node src/scripts/semantic-release/prepare.js ${nextRelease.version} ${options.branch} ${commits.length} ${Date.now()}" + } + ] + ], + dryRun: false, + ci: false +}; diff --git a/src/scripts/logBuild.js b/src/scripts/logBuild.js new file mode 100644 index 0000000..5c10088 --- /dev/null +++ b/src/scripts/logBuild.js @@ -0,0 +1,14 @@ +const { BRANCH } = process.env; +const { writeFileSync } = require("fs"); +const { join } = require("path"); +const { execSync } = require("child_process"); + +const branch = BRANCH || execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf8" }).replace("\n", ""); +const commitId = execSync("git rev-parse HEAD", { encoding: "utf8" }).replace("\n", ""); +const commitUrl = "https://github.com/asterics/WebACS/commit/" + commitId; +const date = Date(); + +const buildInfo = JSON.stringify({ date, branch, commitId, commitUrl }, null, 4); +console.log("Creating build information:") +console.log(buildInfo); +writeFileSync(join(process.cwd(), "dist/build.json"), buildInfo, "utf8"); \ No newline at end of file diff --git a/src/scripts/semantic-release/prepare.js b/src/scripts/semantic-release/prepare.js new file mode 100644 index 0000000..706abef --- /dev/null +++ b/src/scripts/semantic-release/prepare.js @@ -0,0 +1,13 @@ +const { lstatSync, readdirSync, symlinkSync } = require("fs"); + +let version = process.argv[2]; + +/* Search `WebACS.zip` in root folder */ +const release = readdirSync(process.cwd()) + .filter(e => !lstatSync(e).isDirectory()) + .filter(e => e.match(/^WebACS.zip$/)); + +/* Rename if `WebACS.zip` found */ +if (release.length > 0) { + symlinkSync("WebACS.zip", `WebACS-v${version}.zip`); +}