Skip to content

Commit 8ece2d0

Browse files
author
Sylvain Viart
committed
Drafting deploy.sh most code OK. #32
adding v0.6.2 missing tag, not yet supported by deploy.sh deploy.sh now support build target to only build for target listed in deployment.yml uploading doesn't delete assets, tested on Sylvain303 docs/pre_built_binaries.md is not uptodate
1 parent a3524cb commit 8ece2d0

File tree

7 files changed

+174
-17
lines changed

7 files changed

+174
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
docopts
22
docopts-*
33
*.swp
4+
env

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
#
2+
# Makefile for managing docopts build
3+
#
4+
# See also: deploy.sh
15

2-
DOCOPT_GO=${GOPATH}/linux_amd64/github.com/docopt/docopt-go.a
36

47
PREFIX ?= /usr/local
58

@@ -25,6 +28,7 @@ docopts-OSX: docopts.go
2528
docopts-arm: docopts.go
2629
env GOOS=linux GOARCH=arm go build -o docopts-arm docopts.go
2730

31+
# requires write access to $PREFIX
2832
install: all
2933
cp docopts docopts.sh $(PREFIX)/bin
3034

@@ -40,4 +44,4 @@ README.md: examples/legacy_bash/rock_hello_world.sh examples/legacy_bash/rock_he
4044
mv README.tmp README.md
4145

4246
clean:
43-
rm -f docopts-* docopts README.tmp
47+
rm -f docopts-* docopts README.tmp build/docopts_*

build/.placeholder

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build directory

deploy.sh

100644100755
Lines changed: 135 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
#!/usr/bin/env bash
2-
#export GITHUB_TOKEN=...
2+
#
3+
# Tools for deploying our release to github
4+
#
5+
# Usage: ./deploy.sh deploy [-n] [-r REMOTE_REPOS] [RELEASE_VERSION]
6+
# ./deploy.sh build
7+
#
8+
# Options:
9+
# -n Dry run, show with version, files and description
10+
# -r REMOTE_REPOS Specify a REMOTE_REPOS name [default: origin]
11+
#
12+
# Arguments:
13+
# RELEASE_VERSION a git tag
14+
#
15+
# Actions:
16+
# build only build using gox and deployment.yml config
17+
#
18+
# deploy.sh read description in deployment.yml
319

4-
set -euo pipefail
520

21+
DEPLOYMENT_FILE=deployment.yml
622
GITHUB_USER=sylvain303
723
GITHUB_REPO=docopts
824
TAG="v0.6.3-alpha2"
25+
BUILD_DEST_DIR=build
926

1027
create_release()
1128
{
@@ -18,13 +35,22 @@ create_release()
1835
--pre-release
1936
}
2037

38+
prepare_upload()
39+
{
40+
local build_dest_dir=$1
41+
pushd $build_dest_dir > /dev/null
42+
rm -f sha256sum.txt
43+
sha256sum * > sha256sum.txt
44+
popd > /dev/null
45+
find $build_dest_dir -type f -a ! -name .\*
46+
}
47+
2148
upload_binaries()
2249
{
2350
local filenames=$*
24-
sha256sum $filenames > sha256sum.txt
2551

2652
local f
27-
for f in $filenames sha256sum.txt
53+
for f in $filenames
2854
do
2955
echo "uploading '$f' ..."
3056
gothub upload \
@@ -37,4 +63,108 @@ upload_binaries()
3763
done
3864
}
3965

40-
upload_binaries docopts docopts-32bits docopts-OSX
66+
indent()
67+
{
68+
local arg="$1"
69+
if [[ -f "$arg" ]] ; then
70+
sed -e 's/^/ /' "$arg"
71+
else
72+
sed -e 's/^/ /' <<< "$arg"
73+
fi
74+
}
75+
76+
get_arch_build_target()
77+
{
78+
local arch_list=$(yq.v2 r $DEPLOYMENT_FILE build | sed -e 's/^- //')
79+
if [[ $# -eq 1 && $1 == 'gox' ]] ; then
80+
# join output and trim
81+
tr $'\n' ' ' <<< "$arch_list" | sed -e 's/ $//'
82+
else
83+
echo "$arch_list"
84+
fi
85+
}
86+
87+
build_binaries()
88+
{
89+
gox -osarch "$(get_arch_build_target gox)" -output="$BUILD_DEST_DIR/{{.Dir}}_{{.OS}}_{{.Arch}}"
90+
}
91+
92+
yaml_keys ()
93+
{
94+
yq.v2 r "$1" "$2" | sed -n -e '/^\([^ ]\([^:]\+\)\?\):/ s/:.*// p'
95+
}
96+
97+
main_deploy()
98+
{
99+
# redefine GITHUB_TOKEN to test if exported for strict mode
100+
GITHUB_TOKEN=${GITHUB_TOKEN:-}
101+
102+
if [[ -n $ARGS_RELEASE_VERSION ]] ; then
103+
TAG=$ARGS_RELEASE_VERSION
104+
else
105+
# fetch last tag from git
106+
TAG=$(git describe --abbrev=0)
107+
fi
108+
109+
repository=$(git remote -v | grep $ARGS_REMOTE_REPOS | grep push | head -1)
110+
description=$(yq.v2 r $DEPLOYMENT_FILE "releases[$TAG].description")
111+
if [[ -z $description || $description == null ]] ; then
112+
echo "description not found for tag '$TAG' in $DEPLOYMENT_FILE"
113+
echo "available git tags: ($repository)"
114+
indent "$(git tag)"
115+
echo "available git tags in $DEPLOYMENT_FILE:"
116+
indent "$(yaml_keys $DEPLOYMENT_FILE releases)"
117+
return 1
118+
fi
119+
120+
build_binaries
121+
UPLOAD_FILES=$(prepare_upload $BUILD_DEST_DIR)
122+
123+
if $ARGS_n ; then
124+
cat << EOT
125+
GITHUB_TOKEN: $GITHUB_TOKEN
126+
build_dir: $BUILD_DEST_DIR
127+
repository: $repository
128+
tag: $TAG
129+
files: $UPLOAD_FILES
130+
sha256sum.txt:
131+
$(indent $BUILD_DEST_DIR/sha256sum.txt)
132+
description:
133+
$(indent "$description")
134+
EOT
135+
exit 0
136+
else
137+
if [[ -z $GITHUB_TOKEN ]] ; then
138+
echo "GITHUB_TOKEN must be exported"
139+
return 1
140+
fi
141+
upload_binaries $UPLOAD_FILES
142+
fi
143+
}
144+
145+
if [[ $0 == $BASH_SOURCE ]] ; then
146+
# bash strict mode
147+
set -euo pipefail
148+
149+
# we add our repository path to run our local docopts binary
150+
# you will have to build it first of course.
151+
PATH=$(dirname $0):$PATH
152+
source docopts.sh --auto -G "$@"
153+
# fix docopt bug https://github.com/docopt/docopt/issues/386
154+
ARGS_REMOTE_REPOS=${ARGS_REMOTE_REPOS:-$ARGS_r}
155+
156+
docopt_print_ARGS -G
157+
158+
if $ARGS_build ; then
159+
# build only
160+
echo "dest build dir: $BUILD_DEST_DIR/"
161+
build_binaries
162+
ls -l $BUILD_DEST_DIR
163+
exit 0
164+
elif [[ $ARGS_deploy ]] ; then
165+
main_deploy
166+
else
167+
echo "no command found: $*"
168+
exit 1
169+
fi
170+
fi

deployment.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
---
2+
build:
3+
- darwin/386
4+
- darwin/amd64
5+
- linux/386
6+
- linux/amd64
7+
- linux/arm
8+
# doesn't compile
9+
#- android/arm
210
releases:
311
# to key match the git tag
412
v0.6.3-alpha2:
513
name: "docopts binary transitional"
614
description: |
7-
This is a transitional release.
15+
This is a transitional release.
816
917
It supports all the previous API plus some extra command line options.
1018
Fully compatible with previous 0.6.2 python code for Bash.
@@ -37,3 +45,19 @@ releases:
3745
`docopts` behavior sould be unchanged:
3846
- add mangled name collision detection
3947
48+
v0.6.2:
49+
name: "first release in Go"
50+
description: |
51+
This is a transitional release.
52+
53+
Dopopt for shell.
54+
55+
It supports all the previous API.
56+
Fully compatible with previous 0.6.1 python code for Bash.
57+
See: https://github.com/docopt/docopts/tree/v0.6.1%2Bfix
58+
59+
based on master branch
60+
61+
changes:
62+
- now written in Go, no more python dependancies
63+

docs/pre_built_binaries.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ current folder.
2424
## Release binaries
2525

2626
This section is for developper. In order to release binaries you will need
27-
some granted access to github, and to more tools.
27+
some granted access to github.
28+
29+
You will also need some more developper tools.
2830

2931
Most of the tools require a working [Go developper
30-
environment](https://golang.org/doc/code.html#Organization). Which should be not too
32+
environment](https://golang.org/doc/code.html#Organization). Which should not be too
3133
complicated to setup.
3234

33-
You will also need some more developper tools.
34-
3535
Go for it:
3636

3737
### gox
@@ -58,7 +58,7 @@ https://help.github.com/articles/creating-an-access-token-for-command-line-use
5858

5959
The token needs to have `repos` auth priviledges.
6060

61-
then export it as a bash environment variable
61+
then export it as a bash environment variable:
6262

6363
```
6464
export GITHUB_TOKEN="you token here"
@@ -77,7 +77,7 @@ git push origin v0.6.3-alpha2
7777

7878
See: http://mikefarah.github.io/yq/
7979

80-
For extracting yaml data from deployment.yml
80+
For extracting yaml data from `deployment.yml`
8181

8282
```
8383
go get gopkg.in/mikefarah/yq.v2

sha256sum.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)