-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·97 lines (88 loc) · 3.25 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
set -euxo pipefail
if [ ! -v CI ]; then
GITHUB_REPOSITORY='rgl/spin-http-go-example'
fi
HELLO_SOURCE_URL="https://github.com/${GITHUB_REPOSITORY:-rgl/spin-http-go-example}"
if [[ "${GITHUB_REF:-v0.0.0-dev}" =~ \/v([0-9]+(\.[0-9]+)+(-.+)?) ]]; then
HELLO_VERSION="${BASH_REMATCH[1]}"
else
HELLO_VERSION='0.0.0-dev'
fi
HELLO_REVISION="${GITHUB_SHA:-0000000000000000000000000000000000000000}"
HELLO_TITLE="$(basename "$GITHUB_REPOSITORY")"
HELLO_DESCRIPTION='Example Spin HTTP Application written in Go'
HELLO_LICENSE='ISC'
HELLO_AUTHOR_NAME="$(perl -ne 'print $1 if /authorName\s+=\s+"(.+)"/' <meta.go)"
HELLO_VENDOR="$(perl -ne 'print $1 if /authorUrl\s+=\s+".+\/\/(.+)"/' <meta.go)"
function dependencies {
go mod download
}
function build {
sed -i -E "s,([[:space:]]sourceUrl[[:space:]]+=[[:space:]]+).+,\1\"$HELLO_SOURCE_URL\",g" meta.go
sed -i -E "s,([[:space:]]version[[:space:]]+=[[:space:]]+).+,\1\"$HELLO_VERSION\",g" meta.go
sed -i -E "s,([[:space:]]revision[[:space:]]+=[[:space:]]+).+,\1\"$HELLO_REVISION\",g" meta.go
spin build
rm -rf dist
install -d dist
cp *.wasm spin.toml dist/
}
function release {
local image="ghcr.io/$GITHUB_REPOSITORY:$HELLO_VERSION"
local image_created="$(date --utc '+%Y-%m-%dT%H:%M:%S.%NZ')"
local artifact_name="$(basename "$HELLO_SOURCE_URL").tgz"
# publish the application as a docker container image or as an oci image artifact.
if true; then
docker build \
--label "org.opencontainers.image.created=$image_created" \
--label "org.opencontainers.image.source=$HELLO_SOURCE_URL" \
--label "org.opencontainers.image.version=$HELLO_VERSION" \
--label "org.opencontainers.image.revision=$HELLO_REVISION" \
--label "org.opencontainers.image.title=$HELLO_TITLE" \
--label "org.opencontainers.image.description=$HELLO_DESCRIPTION" \
--label "org.opencontainers.image.licenses=$HELLO_LICENSE" \
--label "org.opencontainers.image.vendor=$HELLO_VENDOR" \
--label "org.opencontainers.image.authors=$HELLO_AUTHOR_NAME" \
-t "$image" \
.
docker push "$image"
else
# TODO https://github.com/fermyon/spin/issues/2236.
spin registry push \
--annotation "org.opencontainers.image.created=$image_created" \
--annotation "org.opencontainers.image.source=$HELLO_SOURCE_URL" \
--annotation "org.opencontainers.image.version=$HELLO_VERSION" \
--annotation "org.opencontainers.image.revision=$HELLO_REVISION" \
--annotation "org.opencontainers.image.title=$HELLO_TITLE" \
--annotation "org.opencontainers.image.description=$HELLO_DESCRIPTION" \
--annotation "org.opencontainers.image.licenses=$HELLO_LICENSE" \
--annotation "org.opencontainers.image.vendor=$HELLO_VENDOR" \
--annotation "org.opencontainers.image.authors=$HELLO_AUTHOR_NAME" \
"$image"
fi
# create the release binary artifact.
cd dist
rm -f "$artifact_name"
tar czf "$artifact_name" *
echo "sha256 $(sha256sum *.tgz)" >release-notes.md
cd ..
}
function main {
local command="$1"; shift
case "$command" in
dependencies)
dependencies "$@"
;;
build)
build "$@"
;;
release)
release "$@"
;;
*)
echo "ERROR: Unknown command $command"
exit 1
;;
esac
}
main "$@"