Fix release automation

This commit is contained in:
Ivan Diaz 2020-12-04 18:20:53 -03:00
parent ca54d19bd9
commit e4a7fe8783
5 changed files with 177 additions and 79 deletions

View File

@ -99,9 +99,13 @@ jobs:
npm i
npm run modify-files
cd ../..
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
git config --global user.email "ivan@opensupports.com"
git config --global user.name "CircleCI-BOT"
git add .
git commit -m "Release $VERSION"
git push origin master
git checkout -b release-${VERSION}
git push origin release-${VERSION}
- persist_to_workspace:
root: .
@ -133,7 +137,7 @@ jobs:
sudo apt-get install lftp
make build-release-bundles
make upload-bundles
make deploy-prerelease-tag
# make push-prerelease-tag
make populate-staging-release
- persist_to_workspace:
@ -145,12 +149,16 @@ parameters:
version:
type: string
default: ""
run_build:
type: boolean
default: true
workflows:
build:
when:
condition:
- equal: [ master, << pipeline.git.branch >> ]
and:
- equal: [ master, << pipeline.git.branch >> ]
- << pipeline.parameters.run_build >>
jobs:
- install_composer_packages
- install_node_packages:

View File

@ -4,47 +4,36 @@
deploy-staging-files:
./build.sh
mv dist/opensupports_dev.zip .
FOLDER=dev1 DOMAIN=dev1.opensupports.com make deploy-instance-files
FOLDER=dev2 DOMAIN=dev2.opensupports.com make deploy-instance-files
make upload-bundles
deploy-instance-files:
lftp -c "open -u $(FTP_USER),$(FTP_PASSWORD) $(FTP_HOST); set ssl:verify-certificate no; mirror -R client/build /${FOLDER}"
lftp -c "open -u $(FTP_USER),$(FTP_PASSWORD) $(FTP_HOST); set ssl:verify-certificate no; put -O /${FOLDER}/api/ api/index.php"
lftp -c "open -u $(FTP_USER),$(FTP_PASSWORD) $(FTP_HOST); set ssl:verify-certificate no; put -O /${FOLDER}/api/ api/.htaccess"
lftp -c "open -u $(FTP_USER),$(FTP_PASSWORD) $(FTP_HOST); set ssl:verify-certificate no; put -O /${FOLDER}/api/ api/composer.json"
lftp -c "open -u $(FTP_USER),$(FTP_PASSWORD) $(FTP_HOST); set ssl:verify-certificate no; put -O /${FOLDER}/api/ api/composer.lock"
lftp -c "open -u $(FTP_USER),$(FTP_PASSWORD) $(FTP_HOST); set ssl:verify-certificate no; mirror -R api/controllers/ /${FOLDER}/api/controllers/"
lftp -c "open -u $(FTP_USER),$(FTP_PASSWORD) $(FTP_HOST); set ssl:verify-certificate no; mirror -R api/data/ /${FOLDER}/api/data/"
lftp -c "open -u $(FTP_USER),$(FTP_PASSWORD) $(FTP_HOST); set ssl:verify-certificate no; mirror -R api/libs/ /${FOLDER}/api/libs/"
lftp -c "open -u $(FTP_USER),$(FTP_PASSWORD) $(FTP_HOST); set ssl:verify-certificate no; mirror -R api/models/ /${FOLDER}/api/models/"
lftp -c "open -u $(FTP_USER),$(FTP_PASSWORD) $(FTP_HOST); set ssl:verify-certificate no; mirror -R api/files/ /${FOLDER}/api/files"
lftp -c "open -u $(FTP_USER),$(FTP_PASSWORD) $(FTP_HOST); set ssl:verify-certificate no; mirror -R api/vendor/ /${FOLDER}/api/vendor" || true
(curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://${DOMAIN}/api/clear.php || true)
deploy-staging-population:
curl -u ${CIRCLE_API_USER_TOKEN}: \
-d 'build_parameters[CIRCLE_JOB]=deploy_dev1' \
https://circleci.com/api/v1.1/project/github/opensupports/staging-population/tree/master
curl -u ${CIRCLE_API_USER_TOKEN}: \
-d 'build_parameters[CIRCLE_JOB]=deploy_dev2' \
https://circleci.com/api/v1.1/project/github/opensupports/staging-population/tree/master
curl -u ${CIRCLE_API_USER_TOKEN}: \
-d 'build_parameters[CIRCLE_JOB]=deploy_dev3' \
https://circleci.com/api/v1.1/project/github/opensupports/staging-population/tree/master
curl --request POST \
--url https://circleci.com/api/v2/project/github/opensupports/staging-population/pipeline \
--header 'Circle-Token: ${CIRCLE_API_USER_TOKEN}' \
--header 'content-type: application/json' \
--data '{"branch":"master","parameters":{"server_to_deploy": "dev1"}}'
curl --request POST \
--url https://circleci.com/api/v2/project/github/opensupports/staging-population/pipeline \
--header 'Circle-Token: ${CIRCLE_API_USER_TOKEN}' \
--header 'content-type: application/json' \
--data '{"branch":"master","parameters":{"server_to_deploy": "dev2"}}'
curl --request POST \
--url https://circleci.com/api/v2/project/github/opensupports/staging-population/pipeline \
--header 'Circle-Token: ${CIRCLE_API_USER_TOKEN}' \
--header 'content-type: application/json' \
--data '{"branch":"master","parameters":{"server_to_deploy": "dev3"}}'
build-release-bundles:
ifndef VERSION
$(error VERSION is not set)
endif
$(eval UPGRADE_ZIP="opensupports_v$(VERSION)_update.zip")
./build.sh
mv dist/opensupports_dev.zip .
cp opensupports_dev.zip ${UPGRADE_ZIP} && \
mv opensupports_dev.zip opensupports_v${VERSION}.zip && \
zip -d ${UPGRADE_ZIP} "api/config.php" && \
zip -r ${UPGRADE_ZIP} "version_upgrades/${VERSION}" && \
zip -r ${UPGRADE_ZIP} "version_upgrades/mysql_connect.php"
(( \
zip -r ${UPGRADE_ZIP} "version_upgrades/${VERSION}" && \
zip -r ${UPGRADE_ZIP} "version_upgrades/mysql_connect.php" \
) || true)
upload-bundles:
for file in *.zip ; do \
@ -52,31 +41,27 @@ upload-bundles:
done
push-prerelease-tag:
ifndef VERSION
$(error VERSION is not set)
endif
echo -e "Release v${VERSION}\n====\n" > log.txt && \
git log $(git describe --tags --abbrev=0 @^)..@ --pretty=format:'%s' >> log.txt && \
./version_upgrades/release_script/node_modules/.bin/github-release upload \
--owner opensupports \
--repo opensupports \
--draft true\
--tag "v$(VERSION)" \
--release-name "Release v$(VERSION)" \
--body "$(<log.txt)" \
opensupports_v${VERSION}.zip opensupports_v${VERSION}_update.zip
git log $(git describe --tags --abbrev=0 @^)..@ --pretty=format:'%s' >> log.txt
# ./version_upgrades/release_script/node_modules/.bin/github-release upload \
# --owner opensupports \
# --repo opensupports \
# --draft true\
# --tag "v$(VERSION)" \
# --release-name "Release v$(VERSION)" \
# --body "$(<log.txt)" \
# opensupports_v${VERSION}.zip opensupports_v${VERSION}_update.zip
populate-staging-release:
ifndef VERSION
$(error VERSION is not set)
endif
curl -u ${CIRCLE_API_USER_TOKEN}: \
-d 'build_parameters[CIRCLE_JOB]=deploy_westeros' \
-d 'build_parameters[VERSION]=${VERSION}' \
https://circleci.com/api/v1.1/project/github/opensupports/staging-population/tree/master
curl -u ${CIRCLE_API_USER_TOKEN}: \
-d 'build_parameters[CIRCLE_JOB]=deploy_senate' \
-d 'build_parameters[VERSION]=${VERSION}' \
https://circleci.com/api/v1.1/project/github/opensupports/staging-population/tree/master
curl --request POST \
--url https://circleci.com/api/v2/project/github/opensupports/staging-population/pipeline \
--header 'Circle-Token: ${CIRCLE_API_USER_TOKEN}' \
--header 'content-type: application/json' \
--data '{"branch":"master","parameters":{"server_to_deploy": "westeros", "version_to_deploy": "${VERSION}"}}'
curl --request POST \
--url https://circleci.com/api/v2/project/github/opensupports/staging-population/pipeline \
--header 'Circle-Token: ${CIRCLE_API_USER_TOKEN}' \
--header 'content-type: application/json' \
--data '{"branch":"master","parameters":{"server_to_deploy": "senate", "version_to_deploy": "${VERSION}_update"}}'
deploy-staging-release: build-release-bundles upload-bundles populate-staging-release

View File

@ -1,5 +1,5 @@
const editJsonFile = require('edit-json-file');
const regexReplace = require('regex-replace');
const replace = require('replace-in-file');
const WORKDIR = `${__dirname}/../..`;
@ -22,23 +22,23 @@ updateJSONVersion(`${WORKDIR}/client/package-lock.json`);
updateJSONVersion(`${WORKDIR}/server/apidoc.json`);
// Replace in places
regexReplace(
`opensupports_version = '${OLD_VERSION}';`,
`opensupports_version = '${NEW_VERSION}';`,
`${WORKDIR}/client/src/config.js`
);
regexReplace(
`opensupports_version = '${OLD_VERSION}';`,
`opensupports_version = '${NEW_VERSION}';`,
`${WORKDIR}/client/src/index.php`
);
regexReplace(
`* @apiVersion ${OLD_VERSION}`,
`* @apiVersion ${NEW_VERSION}`,
`${WORKDIR}/server`
);
regexReplace(
`v${OLD_VERSION}`,
`v${NEW_VERSION}`,
`${WORKDIR}/README.md`
);
replace({
files: `${WORKDIR}/client/src/config.js`,
from: `opensupports_version = '${OLD_VERSION}';`,
to: `opensupports_version = '${NEW_VERSION}';`
});
replace({
files: `${WORKDIR}/client/src/index.php`,
from: `opensupports_version = '${OLD_VERSION}';`,
to: `opensupports_version = '${NEW_VERSION}';`
});
replace({
files: `${WORKDIR}/server/**/*.php`,
from: `* @apiVersion ${OLD_VERSION}`,
to: `* @apiVersion ${NEW_VERSION}`
});
replace({
files: `${WORKDIR}/client/src/config.js`,
from: `v${OLD_VERSION}`,
to: `v${NEW_VERSION}`
});

View File

@ -346,6 +346,12 @@
"universalify": "^0.1.0"
}
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
"dev": true
},
"get-caller-file": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
@ -420,6 +426,20 @@
}
}
},
"glob": {
"version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"graceful-fs": {
"version": "4.2.4",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz",
@ -438,6 +458,22 @@
"integrity": "sha512-nARK1wSKoBBrtcoESlHBx36c1Ln/gnbNQi1eB6MeTUefJIT3NvUOsV15bClga0k38f0q/kN5xxrGSDS3EFnm9w==",
"dev": true
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"requires": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"dev": true
},
"is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
@ -706,6 +742,12 @@
"integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==",
"dev": true
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true
},
"querystringify": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz",
@ -745,6 +787,68 @@
"yargs": "^15.3.1"
}
},
"replace-in-file": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/replace-in-file/-/replace-in-file-6.1.0.tgz",
"integrity": "sha512-URzjyF3nucvejuY13HFd7O+Q6tFJRLKGHLYVvSh+LiZj3gFXzSYGnIkQflnJJulCAI2/RTZaZkpOtdVdW0EhQA==",
"dev": true,
"requires": {
"chalk": "^4.0.0",
"glob": "^7.1.6",
"yargs": "^15.3.1"
},
"dependencies": {
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
"integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==",
"dev": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"requires": {
"has-flag": "^4.0.0"
}
}
}
},
"require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",

View File

@ -11,6 +11,7 @@
"devDependencies": {
"edit-json-file": "^1.5.0",
"github-release-cli": "^2.0.0",
"regex-replace": "^2.3.1"
"regex-replace": "^2.3.1",
"replace-in-file": "^6.1.0"
}
}