Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Commit

Permalink
Tweak things so we build both Bootstrap v3 and v4
Browse files Browse the repository at this point in the history
  • Loading branch information
cvrebert committed Nov 2, 2015
1 parent e2a7dde commit 341bf80
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 26 deletions.
3 changes: 3 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions 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
3 changes: 2 additions & 1 deletion 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
48 changes: 27 additions & 21 deletions gruntworker.py
Expand Up @@ -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():
Expand Down Expand Up @@ -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.")
Expand All @@ -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])
2 changes: 0 additions & 2 deletions gruntworker.sh

This file was deleted.

4 changes: 2 additions & 2 deletions setup_droplet.sh
Expand Up @@ -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
Expand Down

0 comments on commit 341bf80

Please sign in to comment.