From ffc0c3b32a76e9ba87f542a0735baa072ac62a6e Mon Sep 17 00:00:00 2001 From: Ansuel Smith Date: Tue, 16 Apr 2019 20:40:44 +0200 Subject: [PATCH] circleci: update to use workflows Signed-off-by: Ansuel Smith --- .circleci/config.yml | 62 +++++++++++++++++++--------- inizialize_gui.sh | 3 +- scripts/0-detect-build-type.sh | 6 ++- scripts/1-increment_autobuild_ver.sh | 22 +++++----- scripts/3-update_autobuild_ver.sh | 22 +++++----- scripts/6-commit_po.sh | 4 ++ scripts/7-push-release.sh | 6 +-- 7 files changed, 77 insertions(+), 48 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 54f1a10df..f7a3b3ec7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,6 @@ version: 2.1 jobs: - build: + prepare: working_directory: ~/gui_build docker: - image: ansuel/gui-autobuild-image:2 @@ -9,55 +9,77 @@ jobs: - run: name: Check built type from last git log command: bash ./scripts/0-detect-build-type.sh - #- restore_cache: - # keys: latest-file-key - run: name: Increment version from latest build command: bash ./scripts/1-increment_autobuild_ver.sh - run: name: Minify css and javascript command: bash ./scripts/1-compress_css_javascript.sh - - run: - name: Clone autobuild repo - command: bash ./scripts/2-clone_autobuild_dir.sh - run: name: Update po command: python3 ./scripts/update_po.py + - persist_to_workspace: + root: ~/gui_build + paths: + - decompressed + - data + - scripts + - inizialize_gui.sh + init_and_update: + working_directory: ~/gui_build + docker: + - image: ansuel/gui-autobuild-image:2 + steps: + - attach_workspace: + at: ~/gui_build + - run: + name: Clone autobuild repo + command: bash ./scripts/2-clone_autobuild_dir.sh - run: name: Inizialize Gui command: bash ./inizialize_gui.sh - run: name: Upload new build, build and latest.version command: bash ./scripts/3-update_autobuild_ver.sh - - run: - name: Committing updated po to master - command: bash ./scripts/6-commit_po.sh - #- save_cache: - # key: latest-file-key - # paths: - # - ~/gui-dev-build-auto/latest.version - persist_to_workspace: root: ~/gui_build paths: - compressed - scripts - data - - publish-github-release: + commit_po_changes: + working_directory: ~/gui_build docker: - image: cibuilds/github:0.10 steps: + - checkout - attach_workspace: - at: /tmp/gui_build + at: ~/gui_build + - run: + name: Committing updated po to master + command: bash ./scripts/6-commit_po.sh + publish_github_release: + working_directory: ~/gui_build + docker: + - image: cibuilds/github:0.10 + steps: + - attach_workspace: + at: ~/gui_build - run: name: "Publish Release on GitHub" - command: bash /tmp/gui_build/scripts/7-push-release.sh + command: bash ./scripts/7-push-release.sh workflows: version: 2 build_and_deploy: jobs: - - build - - publish-github-release: + - prepare + - commit_po_changes: + requires: + - prepare + - init_and_update: + requires: + - prepare + - publish_github_release: requires: - - build \ No newline at end of file + - init_and_update \ No newline at end of file diff --git a/inizialize_gui.sh b/inizialize_gui.sh index 1f2304653..f637028e9 100644 --- a/inizialize_gui.sh +++ b/inizialize_gui.sh @@ -49,7 +49,8 @@ if [ "$1" == "dev" ]; then fi if [ $CI == "true" ]; then - if [ -f ~/.dev ]; then + TYPE="$(cat $HOME/gui_build/data/type)" + if [ $TYPE == "DEV" ]; then type="_dev" fi fi diff --git a/scripts/0-detect-build-type.sh b/scripts/0-detect-build-type.sh index 91b8b49a9..4bce272fe 100755 --- a/scripts/0-detect-build-type.sh +++ b/scripts/0-detect-build-type.sh @@ -1,9 +1,11 @@ last_log="$(git log --oneline -n 1)" +mkdir $HOME/gui_build/data + if [ "$( echo "$last_log" | grep "\[STABLE\]" )" ]; then echo "Detected STABLE build." - touch ~/.stable + echo STABLE > $HOME/gui_build/data/type else echo "Detected DEV build." - touch ~/.dev + echo DEV > $HOME/gui_build/data/type fi diff --git a/scripts/1-increment_autobuild_ver.sh b/scripts/1-increment_autobuild_ver.sh index 85ba1ee0a..37f618079 100755 --- a/scripts/1-increment_autobuild_ver.sh +++ b/scripts/1-increment_autobuild_ver.sh @@ -3,11 +3,11 @@ rootdevice_file="decompressed/base/etc/init.d/rootdevice" if [ "$(echo "$last_log" | grep -o "\[[0-9]\+\.[0-9]\+\.[0-9]\+\]" | tr -d [ | tr -d ])" ]; then manual_ver="$(echo "$last_log" | grep -o "\[[0-9]\+\.[0-9]\+\.[0-9]\+\]" | tr -d [ | tr -d ])" - echo "Detected manual version: "$manual_ver - sed -i s#version_gui=TO_AUTO_COMPLETE#version_gui=$manual_ver# $rootdevice_file + echo "Detected manual version: "$ver + sed -i s#version_gui=TO_AUTO_COMPLETE#version_gui=$ver# $rootdevice_file else latest_version_link="https://raw.githubusercontent.com/Ansuel/gui-dev-build-auto/master/latest.version" - version=$(curl -s $latest_version_link) + cur_ver=$(curl -s $latest_version_link) if [ -f $HOME/gui-dev-build-auto/latest.version ]; then echo "Detected cached latest.version file... Checking it..." @@ -33,9 +33,9 @@ else echo "Increment version as this is an autobuild" - major=$(echo $version | grep -Eo "^[0-9]+") - dev_num=$(echo $version | sed -E s/[0-9]+\.[0-9]+\.//) - minor=$(echo $version | sed s#$major\.## | sed s#\\.$dev_num## ) + major=$(echo $cur_ver | grep -Eo "^[0-9]+") + dev_num=$(echo $cur_ver | sed -E s/[0-9]+\.[0-9]+\.//) + minor=$(echo $cur_ver | sed s#$major\.## | sed s#\\.$dev_num## ) if [ $((dev_num + 1)) -gt 99 ]; then echo "dev_num greater than 99 increment minor" @@ -51,10 +51,12 @@ else dev_num=$((dev_num + 1)) fi - new_version=$major.$minor.$dev_num + ver=$major.$minor.$dev_num - echo "Detected version: "$version - echo "New version to apply: "$new_version + echo "Detected version: "$cur_ver + echo "New version to apply: "$ver - sed -i s#version_gui=TO_AUTO_COMPLETE#version_gui=$new_version# $rootdevice_file + sed -i s#version_gui=TO_AUTO_COMPLETE#version_gui=$ver# $rootdevice_file fi + +echo $ver > $HOME/gui_build/data/version diff --git a/scripts/3-update_autobuild_ver.sh b/scripts/3-update_autobuild_ver.sh index dc4b7aecc..589d47663 100755 --- a/scripts/3-update_autobuild_ver.sh +++ b/scripts/3-update_autobuild_ver.sh @@ -1,12 +1,13 @@ if [ $CI == "true" ]; then - if [ -f ~/.dev ]; then + TYPE="$(cat ~/gui_build/data/type)" + if [ $TYPE == "DEV" ]; then type="_dev" - elif [ -f ~/.stable ]; then + elif [ $TYPE == "STABLE" ]; then stable_msg="STABLE" fi fi md5sum=$(md5sum compressed/GUI$type.tar.bz2 | awk '{print $1}') -version=$(cat total/etc/init.d/rootdevice | grep -m1 version_gui | cut -d'=' -f 2) +version="$(cat ~/gui_build/data/version)" if ! grep -w -q "$version" $HOME/gui-dev-build-auto/version ; then echo "Adding md5sum of new GUI to version file" echo "Version: "$version" Md5sum: "$md5sum @@ -26,10 +27,12 @@ cp compressed/GUI$type.tar.bz2 $HOME/gui-dev-build-auto/ -r; cd $HOME/gui-dev-build-auto/; if [ $CI == "true" ]; then - if [ -f ~/.stable ]; then - build_type_name="STABLE" - echo $version > stable.version - elif [ -f ~/.dev ]; then + if [ ~/gui_build/data/type ]; then + build_type_name=$(cat ~/gui_build/data/type) + if [ $build_type_name == "STABLE" ]; then + echo $version > stable.version + fi + else build_type_name="DEV" fi commit_link=https://github.com/Ansuel/tch-nginx-gui/commit/$CIRCLE_SHA1 @@ -37,11 +40,6 @@ fi echo $version > latest.version -mkdir ~/gui_build/data - -echo $version > ~/gui_build/data/version -echo $build_type_name > ~/gui_build/data/type - git add -A; git commit -a -m "[$build_type_name] Version: $version Commit: $commit_link"; git push origin master; diff --git a/scripts/6-commit_po.sh b/scripts/6-commit_po.sh index 07c19c701..9a4a0f160 100755 --- a/scripts/6-commit_po.sh +++ b/scripts/6-commit_po.sh @@ -1,3 +1,7 @@ +git config --global user.name "CircleCI"; +git config --global user.email "CircleCI"; + +ssh -o StrictHostKeyChecking=no git@github.com cd $HOME/gui_build diff --git a/scripts/7-push-release.sh b/scripts/7-push-release.sh index b93bae054..586f396af 100644 --- a/scripts/7-push-release.sh +++ b/scripts/7-push-release.sh @@ -1,7 +1,7 @@ -DIR="/tmp/gui_build/compressed" -VERSION="$(cat /tmp/gui_build/data/version)" -TYPE="$(cat /tmp/gui_build/data/type)" +DIR="$HOME/gui_build/compressed" +VERSION="$(cat $HOME/gui_build/data/version)" +TYPE="$(cat $HOME/gui_build/data/type)" if [ $TYPE == "DEV" ]; then PRERELEASE="-prerelease" fi