Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/gruntworker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Rebert <code@chrisrebert.com>2015-11-02 12:37:54 +0300
committerChris Rebert <code@chrisrebert.com>2015-11-02 12:37:54 +0300
commit341bf802ec756aa8683be6354c136c14a8432cea (patch)
treecdd36ed433a3009bc1ad71586a1ef981e6f75c6b
parente2a7dde683ce6f102e4e77bdd7792c8f4fa99321 (diff)
Tweak things so we build both Bootstrap v3 and v4
-rwxr-xr-xgruntworker-v3.sh3
-rwxr-xr-xgruntworker-v4.sh3
-rw-r--r--gruntworker.crontab3
-rwxr-xr-xgruntworker.py48
-rwxr-xr-xgruntworker.sh2
-rwxr-xr-xsetup_droplet.sh4
6 files changed, 37 insertions, 26 deletions
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 <primary-branch-name>")
+ 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