From 341bf802ec756aa8683be6354c136c14a8432cea Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 2 Nov 2015 01:37:54 -0800 Subject: Tweak things so we build both Bootstrap v3 and v4 --- gruntworker-v3.sh | 3 +++ gruntworker-v4.sh | 3 +++ gruntworker.crontab | 3 ++- gruntworker.py | 48 +++++++++++++++++++++++++++--------------------- gruntworker.sh | 2 -- setup_droplet.sh | 4 ++-- 6 files changed, 37 insertions(+), 26 deletions(-) create mode 100755 gruntworker-v3.sh create mode 100755 gruntworker-v4.sh delete mode 100755 gruntworker.sh diff --git a/gruntworker-v3.sh b/gruntworker-v3.sh new file mode 100755 index 0000000..917b746 --- /dev/null +++ b/gruntworker-v3.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cd /home/gruntworker/bootstrap-v3 +flock -xn /var/lock/gruntworker-v3 /opt/gruntworker/gruntworker.py master diff --git a/gruntworker-v4.sh b/gruntworker-v4.sh new file mode 100755 index 0000000..96b21c6 --- /dev/null +++ b/gruntworker-v4.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cd /home/gruntworker/bootstrap-v4 +flock -xn /var/lock/gruntworker-v4 /opt/gruntworker/gruntworker.py v4-dev diff --git a/gruntworker.crontab b/gruntworker.crontab index 76de795..d185a7f 100644 --- a/gruntworker.crontab +++ b/gruntworker.crontab @@ -1 +1,2 @@ -*/10 * * * * gruntworker /usr/local/bin/gruntworker.sh 2>&1 >> /var/log/gruntworker.log +*/10 * * * * gruntworker /usr/local/bin/gruntworker-v3.sh 2>&1 >> /var/log/gruntworker-v3.log +*/10 * * * * gruntworker /usr/local/bin/gruntworker-v4.sh 2>&1 >> /var/log/gruntworker-v4.log diff --git a/gruntworker.py b/gruntworker.py index 4e08ee4..044d030 100755 --- a/gruntworker.py +++ b/gruntworker.py @@ -29,33 +29,34 @@ def run_for_output(cmd): return check_output(cmd, input=b'') -def reset_to_master_and_die(): - log("Attempting to reset current checkout & branch to local master...") +def reset_to_primary_and_die(primary_branch): + log("Attempting to reset current checkout & branch to local {}...".format(primary_branch)) try: - run_expecting_success([b'git', b'checkout', b'-f', b'master']) + run_expecting_success([b'git', b'checkout', b'-f', primary_branch.encode('utf8')]) except CalledProcessError: - log("Error forcibly checking out master; Failed!") + log("Error forcibly checking out {}; Failed!".format(primary_branch)) exit(1) -def fetch_origin(): +def fetch_origin(primary_branch): log("Fetching from origin...") try: - run_expecting_success([b'git', b'fetch', b'origin', b'+master']) + run_expecting_success([b'git', b'fetch', b'origin', ('+' + primary_branch).encode('utf8')]) except CalledProcessError: log("Error fetching from origin; Failed!") exit(1) -def update_master(to_commitish=b'FETCH_HEAD'): - log("Setting local master to {0}...".format(to_commitish.decode('utf8', 'replace'))) +def update_primary(primary_branch, to_commitish=b'FETCH_HEAD'): + primary_bytes = primary_branch.encode('utf8') + log("Setting local {0} to {1}...".format(primary_branch, to_commitish.decode('utf8', 'replace'))) try: run_expecting_success([b'git', b'checkout', b'-q', b'-f', to_commitish]) - run_expecting_success([b'git', b'branch', b'-f', b'master', to_commitish]) - run_expecting_success([b'git', b'checkout', b'-q', b'-f', b'master']) + run_expecting_success([b'git', b'branch', b'-f', primary_bytes, to_commitish]) + run_expecting_success([b'git', b'checkout', b'-q', b'-f', primary_bytes]) except CalledProcessError: - log("Error setting local master to {0}!".format(to_commitish)) - reset_to_master_and_die() + log("Error setting local {0} to {1}!".format(primary_branch, to_commitish)) + reset_to_primary_and_die(primary_branch) def update_npm(): @@ -123,19 +124,19 @@ def get_modified_files(): return [line[3:] for line in lines if line[:2] == b' M'] -def push_or_err(): +def push_or_err(primary_branch): log("Pushing to origin...") try: - run_expecting_success([b'git', b'push', b'origin', b'master']) + run_expecting_success([b'git', b'push', b'origin', primary_branch.encode('utf8')]) except CalledProcessError: log("Error pushing to origin!") raise -def main(): +def main(primary_branch): orig_commit_sha = get_head_commit_sha() - fetch_origin() - update_master() + fetch_origin(primary_branch) + update_primary(primary_branch) post_fetch_commit_sha = get_head_commit_sha() if post_fetch_commit_sha == orig_commit_sha: log("Fetch didn't change HEAD commit; Done.") @@ -149,14 +150,19 @@ def main(): return run_expecting_success([b'git', b'add', b'--'] + modified_files) run_expecting_success([b'git', b'commit', b'-m', b"automatic `grunt dist`\n\n[ci skip]"]) - push_or_err() + push_or_err(primary_branch) except Exception: # pylint: disable=W0703 - log("Resetting master branch & checkout back to commit {} ...".format(post_fetch_commit_sha)) - update_master(to_commitish=post_fetch_commit_sha) + log("Resetting primary branch & checkout back to commit {} ...".format(post_fetch_commit_sha)) + update_primary(primary_branch, to_commitish=post_fetch_commit_sha) log("Failed!") else: log("Successfully pushed changes; Done.") if __name__ == '__main__': - main() + from sys import argv + argv.pop() + if len(argv) != 1: + log("USAGE: gruntworker.py ") + exit(2) + main(argv[0]) diff --git a/gruntworker.sh b/gruntworker.sh deleted file mode 100755 index a904937..0000000 --- a/gruntworker.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -flock -xn /var/lock/gruntworker /opt/gruntworker/gruntworker.py diff --git a/setup_droplet.sh b/setup_droplet.sh index 56db8d3..1a2b670 100755 --- a/setup_droplet.sh +++ b/setup_droplet.sh @@ -28,9 +28,9 @@ aptitude install nodejs apt-get -y --no-install-recommends install openssh-client git python3 python3-dev # other dependencies npm install -g grunt-cli # dependency git clone https://github.com/twbs/gruntworker.git ~/gruntworker -cp ~/gruntworker/gruntworker.sh /usr/local/bin/ cp ~/gruntworker/gruntworker.py /usr/local/bin/ -chmod u=rwx,go=rx /usr/local/bin/gruntworker.* +cp ~/gruntworker/gruntworker-*.sh /usr/local/bin/ +chmod u=rwx,go=rx /usr/local/bin/gruntworker* useradd -m gruntworker # setup SSH keys -- cgit v1.2.3