From 451a5d6779cd704c6fa202459282b272e7acf486 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 25 Oct 2019 08:38:29 +0200 Subject: [PATCH] Create release script --- .github/workflows/deploy.yml | 33 ++++--- bin/build_web_extensions | 11 --- bin/deploy_cli | 27 ++++++ bin/deploy_containers | 34 +++++++ bin/deploy_node_modules | 33 +++++++ bin/deploy_web_extensions | 25 +++++ bin/release | 134 +++++++++++++++++++++++++++ bin/release_web_extensions | 54 ----------- bin/tag | 85 ----------------- containers/deploy | 14 --- packages/deploy | 15 --- packages/lesspass-pure/vue.config.js | 15 +++ packages/lesspass-web-extension/package.json | 1 - 13 files changed, 289 insertions(+), 192 deletions(-) delete mode 100755 bin/build_web_extensions create mode 100755 bin/deploy_cli create mode 100755 bin/deploy_containers create mode 100755 bin/deploy_node_modules create mode 100755 bin/deploy_web_extensions create mode 100755 bin/release delete mode 100755 bin/release_web_extensions delete mode 100755 bin/tag delete mode 100755 containers/deploy delete mode 100755 packages/deploy create mode 100644 packages/lesspass-pure/vue.config.js diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 27a4704..fe651e4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,22 +12,20 @@ jobs: - uses: actions/checkout@v1 - name: deploy containers run: | - cd containers - ./deploy + ./bin/deploy_containers env: QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }} QUAY_PASSWORD: ${{ secrets.QUAY_PASSWORD }} - deploy-packages: + deploy-node-modules: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: deploy packages + - name: deploy node modules run: | - cd packages - ./deploy + ./bin/deploy_node_modules env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} deploy-cli: runs-on: ubuntu-latest @@ -38,12 +36,23 @@ jobs: with: python-version: '3.x' - name: deploy cli + run: | + ./bin/deploy_cli env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + + deploy-web-extensions: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: deploy web extensions run: | - cd cli - python -m pip install --upgrade pip - pip install setuptools wheel twine - python setup.py sdist bdist_wheel - twine upload dist/* + ./bin/deploy_web_extensions + env: + EXTENSION_ID: ${{ secrets.EXTENSION_ID }} + CLIENT_ID: ${{ secrets.CLIENT_ID }} + CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} + REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} + WEB_EXT_API_KEY: ${{ secrets.WEB_EXT_API_KEY }} + WEB_EXT_API_SECRET: ${{ secrets.WEB_EXT_API_SECRET }} diff --git a/bin/build_web_extensions b/bin/build_web_extensions deleted file mode 100755 index 08c91bd..0000000 --- a/bin/build_web_extensions +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o pipefail -set -o nounset - -yarn install -yarn workspace lesspass-pure run build -rm -rf packages/lesspass-web-extension/extension/dist -mkdir packages/lesspass-web-extension/extension/dist -cp -r packages/lesspass-pure/dist/. packages/lesspass-web-extension/extension/dist/ diff --git a/bin/deploy_cli b/bin/deploy_cli new file mode 100755 index 0000000..5acc892 --- /dev/null +++ b/bin/deploy_cli @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +function check_env_variables_are_setted { + if [ -z "${TWINE_USERNAME}" ] || [ -z "${TWINE_PASSWORD}" ]; then + echo "Need to set TWINE_USERNAME and TWINE_PASSWORD env variables to release cli" + exit 1 + fi +} + +set +o errexit + +check_env_variables_are_setted + +set -o errexit +set -o pipefail +set -o nounset + +function push_cli_on_pypi { + pushd cli + python -m pip install --upgrade pip + pip install setuptools wheel twine + python setup.py sdist bdist_wheel + twine upload dist/* + popd +} + +push_cli_on_pypi \ No newline at end of file diff --git a/bin/deploy_containers b/bin/deploy_containers new file mode 100755 index 0000000..1439a7f --- /dev/null +++ b/bin/deploy_containers @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +function check_env_variables_are_setted { + if [ -z "${QUAY_USERNAME}" ] || [ -z "${QUAY_PASSWORD}" ]; then + echo "Need to set QUAY_USERNAME and QUAY_PASSWORD env variables to release containers" + exit 1 + fi +} + +set +o errexit + +check_env_variables_are_setted + +set -o errexit +set -o pipefail +set -o nounset + +function build_and_push_container { + pushd containers + container=$1 + docker build --tag lesspass/${container} ./${container} + docker tag lesspass/${container} quay.io/lesspass/${container} + docker push quay.io/lesspass/${container} + popd +} + +function build_and_push_containers { + docker login --username="${QUAY_USERNAME}" --password="${QUAY_PASSWORD}" quay.io + build_and_push_container webserver + build_and_push_container backend + build_and_push_container frontend +} + +build_and_push_containers \ No newline at end of file diff --git a/bin/deploy_node_modules b/bin/deploy_node_modules new file mode 100755 index 0000000..2fdb18c --- /dev/null +++ b/bin/deploy_node_modules @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +function check_env_variables_are_setted { + if [ -z "${NPM_TOKEN}" ]; then + echo "Need to set NPM_TOKEN env variable to release node modules" + exit 1 + fi +} + +set +o errexit + +check_env_variables_are_setted + +set -o errexit +set -o pipefail +set -o nounset + +function push_packages_on_npm { + grep --fixed-strings --line-regexp --silent "//registry.npmjs.org/:_authToken=$NPM_TOKEN" ~/.npmrc + if [ $? == 1 ] + then + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc + fi + projects="lesspass lesspass-crypto lesspass-entropy lesspass-fingerprint lesspass-pure lesspass-render-password" + for project in ${projects} + do + pushd packages/${project} + yarn publish --new-version + popd + done +} + +push_packages_on_npm \ No newline at end of file diff --git a/bin/deploy_web_extensions b/bin/deploy_web_extensions new file mode 100755 index 0000000..5bc19cb --- /dev/null +++ b/bin/deploy_web_extensions @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +function check_env_variables_are_setted { + if [ -z "${EXTENSION_ID}" ] || [ -z "${CLIENT_ID}" ] || [ -z "${CLIENT_SECRET}" ] || [ -z "${REFRESH_TOKEN}" ] || [ -z "${WEB_EXT_API_KEY}" ] || [ -z "${WEB_EXT_API_SECRET}" ]; then + echo "Need to set EXTENSION_ID, CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN, WEB_EXT_API_KEY and WEB_EXT_API_SECRET env variables to release web extensions" + exit 1 + fi +} + +set +o errexit + +check_env_variables_are_setted + +set -o errexit +set -o pipefail +set -o nounset + +function release_web_extensions { + yarn workspace lesspass-web-extension run release + VERSION=$(grep -Po '(?<="version": ")[^"]*' package.json) + echo "Download sources on https://github.com/lesspass/lesspass/releases/tag/${VERSION}" + echo "Upload them on https://addons.mozilla.org/en-US/developers/" +} + +release_web_extensions \ No newline at end of file diff --git a/bin/release b/bin/release new file mode 100755 index 0000000..a079d26 --- /dev/null +++ b/bin/release @@ -0,0 +1,134 @@ +#!/usr/bin/env bash + +RED='\033[0;31m' +NOCOLOR='\033[0m' + +function print_error { + echo -e "${RED}$1${NOCOLOR}" +} + +function check_current_directory_is_root { + if [ ! -f README.md ]; then + print_error "You seems to be in the wrong directory" + print_error "Execute this script from the root of lesspass with ./bin/${0##*/}" + exit 1 + fi +} + +function check_repository_is_clean { + git remote update + git add . + git status + git diff-index --quiet HEAD --; + if [ $? == 1 ] + then + print_error "Git repository not clean. Aborting." + exit 1 + fi +} + +function check_branch_is_master { + BRANCH_NAME=$(git branch | grep \* | cut -d ' ' -f2) + if [ $BRANCH_NAME != "master" ] + then + print_error "Current branch is not master. Aborting." + exit 1 + fi +} + +function check_bump_type_is_defined { + bump_type="${1}" + if [ "${bump_type}" != "major" ] && [ "${bump_type}" != "minor" ] && [ "${bump_type}" != "patch" ] + then + print_error "Error: No bump type specified (major, minor, patch). Aborting." + exit 1 + fi +} + +set +o errexit + +check_branch_is_master +bump_type="${1:-}" +check_bump_type_is_defined ${bump_type} +check_current_directory_is_root +check_repository_is_clean + +set -o errexit +set -o pipefail +set -o nounset + +function increment_version { + IFS='.' read -a versions <<< "${1}" + + major=${versions[0]} + minor=${versions[1]} + patch=${versions[2]} + + case "${2}" in + "major") + major=$((major + 1)) + minor=0 + patch=0 + ;; + "minor") + minor=$((minor + 1)) + patch=0 + ;; + "patch") + patch=$((patch + 1)) + ;; + esac + + new_version="$major.$minor.$patch" + echo ${new_version} +} + +function replace_versions_in_files { + sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" package.json + sed -i "s/__version__ = \"${1}\"/__version__ = \"${2}\"/g" cli/lesspass/version.py + sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" mobile/package.json + sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" mobile/src/version.json + sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass/package.json + sed -i "s/\"lesspass-entropy\": \"${1}\"/\"lesspass-entropy\": \"${2}\"/g" packages/lesspass/package.json + sed -i "s/\"lesspass-fingerprint\": \"${1}\"/\"lesspass-fingerprint\": \"${2}\"/g" packages/lesspass/package.json + sed -i "s/\"lesspass-render-password\": \"${1}\"/\"lesspass-render-password\": \"${2}\"/g" packages/lesspass/package.json + sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-crypto/package.json + sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-entropy/package.json + sed -i "s/\"lesspass-crypto\": \"${1}\"/\"lesspass-crypto\": \"${2}\"/g" packages/lesspass-entropy/package.json + sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-fingerprint/package.json + sed -i "s/\"lesspass-crypto\": \"${1}\"/\"lesspass-crypto\": \"${2}\"/g" packages/lesspass-fingerprint/package.json + sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-pure/package.json + sed -i "s/\"lesspass\": \"${1}\"/\"lesspass\": \"${2}\"/g" packages/lesspass-pure/package.json + sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-render-password/package.json + sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-site/package.json + sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-web-extension/package.json + sed -i "s/\"lesspass-pure\": \"${1}\"/\"lesspass-pure\": \"${2}\"/g" packages/lesspass-web-extension/package.json + sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-web-extension/extension/manifest.json +} + +function build_web_extensions { + yarn install + yarn workspace lesspass-pure run build + rm -rf packages/lesspass-web-extension/extension/dist + mkdir packages/lesspass-web-extension/extension/dist + cp -r packages/lesspass-pure/dist/. packages/lesspass-web-extension/extension/dist/ +} + +function build_mobile_app { + pushd mobile/android/ + ./gradlew assembleRelease + popd +} + +function tag { + git add . + git commit --message="LessPass version ${1}" + git tag "${1}" +} + +current_version=$( grep -Po '(?<="version": ")[^"]*' package.json ) +new_version=$( increment_version ${current_version} ${bump_type} ) +replace_versions_in_files ${current_version} ${new_version} +build_web_extensions +build_mobile_app +tag ${new_version} diff --git a/bin/release_web_extensions b/bin/release_web_extensions deleted file mode 100755 index 04c7047..0000000 --- a/bin/release_web_extensions +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env bash - -set +o errexit - -function check_branch_is_master { - BRANCH_NAME=$(git branch | grep \* | cut -d ' ' -f2) - if [ $BRANCH_NAME != "master" ] - then - echo >&2 "Current branch is not master. Aborting." - exit 1 - fi -} - -function check_tag_is_present { - git describe --exact-match --tags - if [ $? != 0 ] - then - echo >&2 "Current revision is not tagged. Aborting." - exit 1 - fi -} - -function check_repository_is_clean { - git remote update - git status - git diff-index --quiet HEAD --; - if [ $? == 1 ] - then - echo >&2 "Git repository not clean. Aborting." - exit 1 - fi -} - -function check_env_variables_setted { - if [ -z "$EXTENSION_ID" ] || [ -z "$CLIENT_ID" ] || [ -z "$CLIENT_SECRET" ] || [ -z "$REFRESH_TOKEN" ] || [ -z "$WEB_EXT_API_KEY" ] || [ -z "$WEB_EXT_API_SECRET" ]; then - echo "Need to set EXTENSION_ID, CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN, WEB_EXT_API_KEY and WEB_EXT_API_SECRET env variables to release web extensions" - exit 1 - fi -} - -check_branch_is_master -check_tag_is_present -check_env_variables_setted -yarn workspace lesspass-web-extension run build -yarn workspace lesspass-pure run build -check_repository_is_clean - -set -o errexit -set -o pipefail -set -o nounset - -yarn workspace lesspass-web-extension run release -VERSION=$(grep -Po '(?<="version": ")[^"]*' package.json) -echo "See the new release on https://github.com/lesspass/lesspass/releases/tag/${VERSION}" diff --git a/bin/tag b/bin/tag deleted file mode 100755 index ea19426..0000000 --- a/bin/tag +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env bash - -set +o errexit - -git diff-index --quiet HEAD -if [ $? == 1 ] -then - echo >&2 "Git repository not clean. Aborting." - exit 1 -fi - -set -o errexit -set -o pipefail -set -o nounset - -function increment_version { - IFS='.' read -a versions <<< "${1}" - - major=${versions[0]} - minor=${versions[1]} - patch=${versions[2]} - - case "${2}" in - "major") - major=$((major + 1)) - minor=0 - patch=0 - ;; - "minor") - minor=$((minor + 1)) - patch=0 - ;; - "patch") - patch=$((patch + 1)) - ;; - esac - - new_version="$major.$minor.$patch" - echo ${new_version} -} - -function replace_versions_in_files { - sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" package.json - sed -i "s/__version__ = \"${1}\"/__version__ = \"${2}\"/g" cli/lesspass/version.py - sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" mobile/package.json - sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" mobile/src/version.json - sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass/package.json - sed -i "s/\"lesspass-entropy\": \"${1}\"/\"lesspass-entropy\": \"${2}\"/g" packages/lesspass/package.json - sed -i "s/\"lesspass-fingerprint\": \"${1}\"/\"lesspass-fingerprint\": \"${2}\"/g" packages/lesspass/package.json - sed -i "s/\"lesspass-render-password\": \"${1}\"/\"lesspass-render-password\": \"${2}\"/g" packages/lesspass/package.json - sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-crypto/package.json - sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-entropy/package.json - sed -i "s/\"lesspass-crypto\": \"${1}\"/\"lesspass-crypto\": \"${2}\"/g" packages/lesspass-entropy/package.json - sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-fingerprint/package.json - sed -i "s/\"lesspass-crypto\": \"${1}\"/\"lesspass-crypto\": \"${2}\"/g" packages/lesspass-fingerprint/package.json - sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-pure/package.json - sed -i "s/\"lesspass\": \"${1}\"/\"lesspass\": \"${2}\"/g" packages/lesspass-pure/package.json - sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-render-password/package.json - sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-site/package.json - sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-web-extension/package.json - sed -i "s/\"lesspass-pure\": \"${1}\"/\"lesspass-pure\": \"${2}\"/g" packages/lesspass-web-extension/package.json - sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-web-extension/extension/manifest.json - sed -i "s/VERSION=\"${1}\"/VERSION=\"${2}\"/g" containers/deploy -} - -function tag { - git add . - git commit --message="LessPass version ${1}" - git tag "${1}" -} - -__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -__root="$(cd "$(dirname "${__dir}")" && pwd)" -pushd ${__root} -bump_type="${1:-}" -if [ "${bump_type}" == "major" ] || [ "${bump_type}" == "minor" ] || [ "${bump_type}" == "patch" ] -then - current_version=$(grep -Po '(?<="version": ")[^"]*' package.json) - new_version=$( increment_version ${current_version} ${bump_type} ) - replace_versions_in_files ${current_version} ${new_version} - tag ${new_version} -else - echo >&2 "Error: No bump type specified (major, minor, patch). Aborting." - exit 1 -fi \ No newline at end of file diff --git a/containers/deploy b/containers/deploy deleted file mode 100755 index d2d780e..0000000 --- a/containers/deploy +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -set -e - -build_and_push () { - PROJECT=$1 - docker build --tag lesspass/${PROJECT} ./${PROJECT} - docker tag lesspass/${PROJECT} quay.io/lesspass/${PROJECT} - docker push quay.io/lesspass/${PROJECT} -} - -docker login --username="${QUAY_USERNAME}" --password="${QUAY_PASSWORD}" quay.io -build_and_push webserver -build_and_push backend -build_and_push frontend diff --git a/packages/deploy b/packages/deploy deleted file mode 100755 index 256b632..0000000 --- a/packages/deploy +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -set -e - -install_and_publish () { - PROJECT=$1 - pushd ${PROJECT} - yarn publish - popd -} - -projects="lesspass lesspass-crypto lesspass-entropy lesspass-fingerprint lesspass-pure lesspass-render-password" -for project in ${projects} -do - install_and_publish ${project} -done diff --git a/packages/lesspass-pure/vue.config.js b/packages/lesspass-pure/vue.config.js new file mode 100644 index 0000000..a3ed438 --- /dev/null +++ b/packages/lesspass-pure/vue.config.js @@ -0,0 +1,15 @@ +module.exports = { + css: { + extract: { + filename: "lesspass.min.css" + } + }, + configureWebpack: { + output: { + filename: "lesspass.min.js" + }, + optimization: { + splitChunks: false + } + } +}; diff --git a/packages/lesspass-web-extension/package.json b/packages/lesspass-web-extension/package.json index a496bb7..9be58d8 100644 --- a/packages/lesspass-web-extension/package.json +++ b/packages/lesspass-web-extension/package.json @@ -7,7 +7,6 @@ "scripts": { "start": "cd extension && web-ext run", "test": "echo 0", - "build": "cd ../.. && ./bin/build_web_extensions && cd packages/lesspass-web-extension", "release": "npm run release:cws && npm run release:amo", "release:amo": "cd extension && web-ext-submit", "release:cws": "cd extension && webstore upload --auto-publish"