#!/usr/bin/env bash # # Usage: # ./publish.sh set -o nounset set -o pipefail set -o errexit proc log { echo @Argv !1 > !2 } proc versioned-dest { var label = $(1:-$(hostname)) # what machine we ran it on var branch = $[git rev-parse --abbrev-ref HEAD] log "branch $branch" var hash = $[git rev-parse $branch] var short_hash = $(hash:0:8) log "hash $short_hash" var dest = ""oilshell.org/git-branch/$branch/$short_hash/$label"" echo $dest } proc spec { var user = $1 var host = $2 var dest = '' dest := ""$[versioned-dest]/spec"" ssh $user@$host mkdir -p $dest # rsync is faster than scp and has the --no-target-directory behavior. # We need --copy-links because the CSS files are symlinks. rsync --archive --verbose --copy-links \ _tmp/spec/ $user@$host:$dest/ echo "Visit http://$dest/RESULTS.html" } # TODO: These should really go to the oilshell.org__deploy repo. # Publish unit tests proc unit { echo 'Hello from publish.sh' } # Wild Tests. NOTE: There's code for this in the oilshell.org repo. proc compress-wild { var dest = '_tmp/wild-deploy' mkdir -p $dest var out = "$PWD/$dest/wild.wwz" # abs path for zip rm -f -v $out pushd _tmp/wild/www time zip -r -q $out . # recursive, quiet popd test/wild-runner.sh link-static $dest ls -l -h $dest } proc wild { var user = $1 var host = $2 var dest = '' dest := $[versioned-dest] # no wild/ suffix, since it's wild.wwz/ ssh $user@$host mkdir -p $dest rsync --archive --verbose --copy-links \ _tmp/wild-deploy/ $user@$host:$dest/ echo "Visit http://$dest/wild.wwz/" } @Argv (CommandList children: [ (C {(set)} {(-o)} {(nounset)}) (C {(set)} {(-o)} {(pipefail)}) (C {(set)} {(-o)} {(errexit)}) (FuncDef name: log body: (BraceGroup children: [ (SimpleCommand words: [{(echo)} {(DQ ($ VSub_At "$@"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:1 arg_word:{(2)} spids:[45])] ) ] spids: [36] ) spids: [32 35] ) (FuncDef name: versioned-dest body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:label) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: { (CommandSubPart command_list: (CommandList children:[(C {(hostname)})]) left_token: spids: [64 66] ) } ) spids: [61 67] ) } spids: [60] ) ] spids: [58] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:branch) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(git)} {(rev-parse)} {(--abbrev-ref)} {(HEAD)})] ) left_token: spids: [77 85] ) } spids: [76] ) ] spids: [74] ) (C {(log)} {(DQ ("branch ") ($ VSub_Name "$branch"))}) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:hash) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(git)} {(rev-parse)} {($ VSub_Name "$branch")})] ) left_token: spids: [99 105] ) } spids: [98] ) ] spids: [96] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:short_hash) op: Equal rhs: { (BracedVarSub token: suffix_op: (Slice begin: (ArithWord w:{(Lit_Digits 0)}) length: (ArithWord w:{(Lit_Digits 8)}) ) spids: [111 117] ) } spids: [110] ) ] spids: [108] ) (C {(log)} {(DQ ("hash ") ($ VSub_Name "$short_hash"))}) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:dest) op: Equal rhs: { (DQ (oilshell.org/git-branch/) ($ VSub_Name "$branch") (/) ($ VSub_Name "$short_hash") (/) ($ VSub_Name "$label") ) } spids: [131] ) ] spids: [129] ) (C {(echo)} {($ VSub_Name "$dest")}) ] spids: [55] ) spids: [51 54] ) (FuncDef name: spec body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:user) op: Equal rhs: {($ VSub_Number "$1")} spids: [158] ) ] spids: [156] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:host) op: Equal rhs: {($ VSub_Number "$2")} spids: [164] ) ] spids: [162] ) (Assignment keyword: Assign_Local pairs: [(assign_pair lhs:(LhsName name:dest) op:Equal spids:[171])] spids: [169] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dest) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children:[(C {(versioned-dest)})]) left_token: spids: [176 178] ) (/spec) ) } spids: [174] ) ] spids: [174] ) (C {(ssh)} {($ VSub_Name "$user") (Lit_Other "@") ($ VSub_Name "$host")} {(mkdir)} {(-p)} {($ VSub_Name "$dest")} ) (C {(rsync)} {(--archive)} {(--verbose)} {(--copy-links)} {(_tmp/spec/)} {($ VSub_Name "$user") (Lit_Other "@") ($ VSub_Name "$host") (Lit_Other ":") ($ VSub_Name "$dest") (/) } ) (C {(echo)} {(DQ ("Visit http://") ($ VSub_Name "$dest") (/RESULTS.html))}) ] spids: [153] ) spids: [149 152] ) (FuncDef name: unit body: (BraceGroup children:[(C {(echo)} {(SQ <"Hello from publish.sh">)})] spids:[249]) spids: [245 248] ) (FuncDef name: compress-wild body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:dest) op: Equal rhs: {(_tmp/wild-deploy)} spids: [273] ) ] spids: [271] ) (C {(mkdir)} {(-p)} {($ VSub_Name "$dest")}) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:out) op: Equal rhs: {($ VSub_Name "$PWD") (/) ($ VSub_Name "$dest") (/wild.wwz)} spids: [287] ) ] spids: [285] ) (C {(rm)} {(-f)} {(-v)} {($ VSub_Name "$out")}) (C {(pushd)} {(_tmp/wild/www)}) (TimeBlock pipeline:(C {(zip)} {(-r)} {(-q)} {($ VSub_Name "$out")} {(.)})) (C {(popd)}) (C {(test/wild-runner.sh)} {(link-static)} {($ VSub_Name "$dest")}) (C {(ls)} {(-l)} {(-h)} {($ VSub_Name "$dest")}) ] spids: [268] ) spids: [264 267] ) (FuncDef name: wild body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:user) op: Equal rhs: {($ VSub_Number "$1")} spids: [359] ) ] spids: [357] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:host) op: Equal rhs: {($ VSub_Number "$2")} spids: [365] ) ] spids: [363] ) (Assignment keyword: Assign_Local pairs: [(assign_pair lhs:(LhsName name:dest) op:Equal spids:[372])] spids: [370] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dest) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children:[(C {(versioned-dest)})]) left_token: spids: [377 379] ) ) } spids: [375] ) ] spids: [375] ) (C {(ssh)} {($ VSub_Name "$user") (Lit_Other "@") ($ VSub_Name "$host")} {(mkdir)} {(-p)} {($ VSub_Name "$dest")} ) (C {(rsync)} {(--archive)} {(--verbose)} {(--copy-links)} {(_tmp/wild-deploy/)} {($ VSub_Name "$user") (Lit_Other "@") ($ VSub_Name "$host") (Lit_Other ":") ($ VSub_Name "$dest") (/) } ) (C {(echo)} {(DQ ("Visit http://") ($ VSub_Name "$dest") (/wild.wwz/))}) ] spids: [354] ) spids: [350 353] ) (C {(DQ ($ VSub_At "$@"))}) ] )