Skip to content

Commit 5bd515e

Browse files
author
Sylvain Viart
committed
deploy.sh code release git deploy #32
add --replace, first delete existing release now support release compilation too in build/ dir completed desciption on deployment.yml
1 parent 8ece2d0 commit 5bd515e

File tree

5 files changed

+152
-67
lines changed

5 files changed

+152
-67
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ README.md: examples/legacy_bash/rock_hello_world.sh examples/legacy_bash/rock_he
4444
mv README.tmp README.md
4545

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

deploy.sh

Lines changed: 113 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
#
33
# Tools for deploying our release to github
44
#
5-
# Usage: ./deploy.sh deploy [-n] [-r REMOTE_REPOS] [RELEASE_VERSION]
6-
# ./deploy.sh build
5+
# Usage: ./deploy.sh deploy [-n] [-r REMOTE_REPOS] [--replace] [RELEASE_VERSION]
6+
# ./deploy.sh build [RELEASE_VERSION]
77
#
88
# Options:
99
# -n Dry run, show with version, files and description
1010
# -r REMOTE_REPOS Specify a REMOTE_REPOS name [default: origin]
11+
# --replace Replace existing release with this one, previous release
12+
# will be deleted first.
1113
#
1214
# Arguments:
1315
# RELEASE_VERSION a git tag
1416
#
1517
# Actions:
16-
# build only build using gox and deployment.yml config
18+
# build only build using gox and deployment.yml config
19+
# deploy prepare and deploy the release
1720
#
1821
# deploy.sh read description in deployment.yml
1922

@@ -26,27 +29,53 @@ BUILD_DEST_DIR=build
2629

2730
create_release()
2831
{
32+
local release="$1"
33+
local name="$2"
34+
local description="$3"
35+
36+
# TODO: detect alpha ==> pre-release
2937
gothub release \
3038
--user $GITHUB_USER \
3139
--repo $GITHUB_REPO \
32-
--tag $TAG \
33-
--name "docopt for shell Bash" \
34-
--description "Written in Go. This binaries is for GNU/Linux 32bits and 64bits" \
40+
--tag "$release" \
41+
--name "$name" \
42+
--description "$description" \
3543
--pre-release
3644
}
3745

46+
check_release()
47+
{
48+
local release=$1
49+
gothub info \
50+
--user $GITHUB_USER \
51+
--repo $GITHUB_REPO \
52+
--tag "$release" > /dev/null 2>&1
53+
}
54+
55+
delete_release()
56+
{
57+
local release=$1
58+
gothub delete \
59+
--user $GITHUB_USER \
60+
--repo $GITHUB_REPO \
61+
--tag "$release"
62+
}
63+
3864
prepare_upload()
3965
{
4066
local build_dest_dir=$1
4167
pushd $build_dest_dir > /dev/null
42-
rm -f sha256sum.txt
68+
# remove docopts source used for build
69+
rm -f sha256sum.txt docopts.go
4370
sha256sum * > sha256sum.txt
4471
popd > /dev/null
4572
find $build_dest_dir -type f -a ! -name .\*
4673
}
4774

4875
upload_binaries()
4976
{
77+
local release=$1
78+
shift
5079
local filenames=$*
5180

5281
local f
@@ -56,9 +85,9 @@ upload_binaries()
5685
gothub upload \
5786
--user $GITHUB_USER \
5887
--repo $GITHUB_REPO \
59-
--tag $TAG \
60-
--name "$f" \
61-
--file $f \
88+
--tag "$release" \
89+
--name "$(basename $f)" \
90+
--file "$f" \
6291
--replace
6392
done
6493
}
@@ -86,59 +115,96 @@ get_arch_build_target()
86115

87116
build_binaries()
88117
{
89-
gox -osarch "$(get_arch_build_target gox)" -output="$BUILD_DEST_DIR/{{.Dir}}_{{.OS}}_{{.Arch}}"
118+
local release=$1
119+
local build_dest_dir=$2
120+
# checkout release version
121+
git show $release:./docopts.go > $build_dest_dir/docopts.go
122+
local osarch="$(get_arch_build_target gox)"
123+
pushd $build_dest_dir > /dev/null
124+
gox -osarch "$osarch" -output="docopts_{{.OS}}_{{.Arch}}"
125+
popd > /dev/null
90126
}
91127

92128
yaml_keys ()
93129
{
94130
yq.v2 r "$1" "$2" | sed -n -e '/^\([^ ]\([^:]\+\)\?\):/ s/:.*// p'
95131
}
96132

97-
main_deploy()
133+
show_release_data()
98134
{
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
135+
local release=$1
136+
local name="$2"
137+
local description="$3"
108138

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)
139+
local repository=$(git remote -v | grep $ARGS_REMOTE_REPOS | grep push | head -1)
122140

123-
if $ARGS_n ; then
124-
cat << EOT
141+
cat << EOT
125142
GITHUB_TOKEN: $GITHUB_TOKEN
126143
build_dir: $BUILD_DEST_DIR
127144
repository: $repository
128-
tag: $TAG
145+
name: $name
146+
tag: $release
129147
files: $UPLOAD_FILES
130148
sha256sum.txt:
131149
$(indent $BUILD_DEST_DIR/sha256sum.txt)
132150
description:
133151
$(indent "$description")
134152
EOT
153+
}
154+
155+
check_name_description()
156+
{
157+
local name="$1"
158+
local description="$2"
159+
if [[ -z $description || $description == null || -z $name || $name == null ]] ; then
160+
echo "description or name not found for tag '$TAG' in $DEPLOYMENT_FILE"
161+
echo "available git tags:"
162+
indent "$(git tag)"
163+
echo "available git tags in $DEPLOYMENT_FILE:"
164+
indent "$(yaml_keys $DEPLOYMENT_FILE releases)"
165+
return 1
166+
fi
167+
}
168+
169+
main_deploy()
170+
{
171+
# redefine GITHUB_TOKEN to test if exported for strict mode
172+
GITHUB_TOKEN=${GITHUB_TOKEN:-}
173+
174+
local description=$(yq.v2 r $DEPLOYMENT_FILE "releases[$TAG].description")
175+
local name=$(yq.v2 r $DEPLOYMENT_FILE "releases[$TAG].name")
176+
177+
check_name_description "$name" "$description"
178+
179+
build_binaries $TAG $BUILD_DEST_DIR
180+
UPLOAD_FILES=$(prepare_upload $BUILD_DEST_DIR)
181+
182+
if $ARGS_n ; then
183+
show_release_data $TAG "$name" "$description"
135184
exit 0
136185
else
137186
if [[ -z $GITHUB_TOKEN ]] ; then
138187
echo "GITHUB_TOKEN must be exported"
139188
return 1
140189
fi
141-
upload_binaries $UPLOAD_FILES
190+
191+
if check_release $TAG ; then
192+
echo "release: already $TAG exists"
193+
if $ARGS_replace ; then
194+
echo "deleting existing release $TAG"
195+
delete_release $TAG
196+
echo "creating release $TAG"
197+
create_release $TAG "$name" "$description"
198+
else
199+
echo "use --replace to replace the existing release"
200+
echo "only upload new files"
201+
fi
202+
else
203+
echo "release: $TAG doesn't exists yet"
204+
echo "creating release $TAG ..."
205+
create_release $TAG "$name" "$description"
206+
fi
207+
upload_binaries $TAG $UPLOAD_FILES
142208
fi
143209
}
144210

@@ -155,10 +221,17 @@ if [[ $0 == $BASH_SOURCE ]] ; then
155221

156222
docopt_print_ARGS -G
157223

224+
if [[ -n $ARGS_RELEASE_VERSION ]] ; then
225+
TAG=$ARGS_RELEASE_VERSION
226+
else
227+
# fetch last tag from git
228+
TAG=$(git describe --abbrev=0)
229+
fi
230+
158231
if $ARGS_build ; then
159-
# build only
232+
echo "build only ..."
160233
echo "dest build dir: $BUILD_DEST_DIR/"
161-
build_binaries
234+
build_binaries $TAG $BUILD_DEST_DIR
162235
ls -l $BUILD_DEST_DIR
163236
exit 0
164237
elif [[ $ARGS_deploy ]] ; then

deployment.yml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build:
1010
releases:
1111
# to key match the git tag
1212
v0.6.3-alpha2:
13-
name: "docopts binary transitional"
13+
name: "docopts binary transitional v0.6.3-alpha2"
1414
description: |
1515
This is a transitional release.
1616
@@ -29,21 +29,31 @@ releases:
2929
- added Makefile
3030
- added build_doc.sh PoC markdown preprocessor
3131
32-
all examples written for docopts:
33-
- shebang conversion `#!/bin/bash` ==> `#!/usr/bin/env bash`
34-
- legacy example completed
35-
- example from README extracted a file, and merged in README via build_doc.sh
36-
- sshdiff full example coded
37-
- added examples with `--auto -G`
38-
39-
docopts.sh helper:
40-
- is more documented in the code
41-
- as a documenation in docs/README.md
42-
- now supports bash strict mode (`set -euo pipefail`)
43-
- now supports `--auto -G` to auto parse with global vars (no bash 4 associative array)
44-
45-
`docopts` behavior sould be unchanged:
46-
- add mangled name collision detection
32+
all examples written for docopts:
33+
- shebang conversion `#!/bin/bash` ==> `#!/usr/bin/env bash`
34+
- legacy example completed
35+
- example from README extracted a file, and merged in README via build_doc.sh
36+
- sshdiff full example coded
37+
- added examples with `--auto -G`
38+
39+
docopts.sh helper:
40+
- is more documented in the code
41+
- as a documenation in docs/README.md
42+
- now supports bash strict mode (`set -euo pipefail`)
43+
- now supports `--auto -G` to auto parse with global vars (no bash 4 associative array)
44+
45+
`docopts` behavior sould be unchanged:
46+
- add mangled name collision detection
47+
48+
v0.6.3-alpha1:
49+
name: "docopts for Bash first release in golang"
50+
description: |
51+
This is a transitional release. It is a complete rewrite of the python's code in go.
52+
It supports all the previous API plus some extra command line options.
53+
54+
Fully compatible with previous 0.6.2 python code for Bash.
55+
56+
based on https://github.com/docopt/docopts/tree/packaging-debian
4757
4858
v0.6.2:
4959
name: "first release in Go"

docopts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
"sort"
1717
)
1818

19-
var Version string = `docopts 0.6.3
19+
var Version string = `docopts 0.6.3-alpha2
2020
Copyright (C) 2013 Vladimir Keleshev, Lari Rasku.
21-
Copyleft (Ɔ) 2018 Sylvain Viart (golang version).
21+
Copyleft (Ɔ) 2019 Sylvain Viart (golang version).
2222
License MIT <http://opensource.org/licenses/MIT>.
2323
This is free software: you are free to change and redistribute it.
2424
There is NO WARRANTY, to the extent permitted by law.

docs/pre_built_binaries.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# docopts pre-built binaries
22

3-
`docopts` is a shell helper mainly for bash as now, for parsing arguments using [docopt language](https://docopt.org).
3+
`docopts` is a shell helper mainly for bash as now, for parsing command-line arguments using the
4+
[docopt language](https://docopt.org).
45

5-
This implementation use Go, and we provide pre-built binaries on releases.
6+
This implementation use Go, and we provide pre-built binaries on available for download from
7+
github releases.
68

79
The sha256sum is provided to ensure the uploaded binaries are conform to the
810
one built by the uploader.
@@ -13,8 +15,8 @@ You can simply download the one you want from
1315
[releases](https://github.com/docopt/docopts/releases).
1416

1517
Or we provide a command line helper if you cloned this repository, that will
16-
simply download from our repository and provide a `docopts` binary in the
17-
current folder.
18+
simply download the good binary format from our repository and provide a `docopts` binary in
19+
your current folder.
1820

1921

2022
```
@@ -24,7 +26,7 @@ current folder.
2426
## Release binaries
2527

2628
This section is for developper. In order to release binaries you will need
27-
some granted access to github.
29+
some granted access to github API.
2830

2931
You will also need some more developper tools.
3032

@@ -94,20 +96,20 @@ make
9496
### deploy
9597

9698
We provide a deploy script, which will take the last git tag, and a deployment
97-
message configured in a yaml file `deployment.yml`.
99+
message written in a yaml file `deployment.yml`.
98100

99101
So you need to create the release text in `deployment.yml` before you run
100102
`deploy.sh`.
101103

102104
See what will going on:
103105

104106
```
105-
./deploy.sh -n
107+
./deploy.sh deploy -n
106108
```
107109

108110
Deploy and replace existing binaries for this release.
109111

110112
```
111-
./deploy.sh -n
113+
./deploy.sh deploy --replace
112114
```
113115

0 commit comments

Comments
 (0)