Skip to content

Commit 742c676

Browse files
authored
snap: update tag and fix build with newer snapcraft version (#191)
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 20c53ca commit 742c676

File tree

2 files changed

+45
-29
lines changed

2 files changed

+45
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## CloudMonkey [![Build Status](https://travis-ci.com/apache/cloudstack-cloudmonkey.svg?branch=main)](https://travis-ci.com/apache/cloudstack-cloudmonkey)[![](https://images.microbadger.com/badges/version/apache/cloudstack-cloudmonkey.svg)](https://hub.docker.com/r/apache/cloudstack-cloudmonkey)[![cloudmonkey](https://snapcraft.io/cloudmonkey/badge.svg)](https://snapcraft.io/cloudmonkey)
1+
## CloudMonkey [![Build Status](https://github.com/apache/cloudstack/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/apache/cloudstack/actions/workflows/build.yml) [![RAT Check](https://github.com/apache/cloudstack-cloudmonkey/actions/workflows/rat.yaml/badge.svg?branch=main)](https://github.com/apache/cloudstack-cloudmonkey/actions/workflows/rat.yamll) [![Lint Check](https://github.com/apache/cloudstack-cloudmonkey/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/apache/cloudstack-cloudmonkey/actions/workflows/lint.yml) [![](https://images.microbadger.com/badges/version/apache/cloudstack-cloudmonkey.svg)](https://hub.docker.com/r/apache/cloudstack-cloudmonkey) [![cloudmonkey](https://snapcraft.io/cloudmonkey/badge.svg)](https://snapcraft.io/cloudmonkey)
22

33
`cloudmonkey` :cloud::monkey_face: is a command line interface (CLI) for
44
[Apache CloudStack](http://cloudstack.apache.org).

snap/snapcraft.yaml

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,61 @@
11
name: cloudmonkey
2-
version: git
2+
# define the tag anchor on the allowed 'version' field
3+
version: &release_tag 6.5.0
34
summary: Apache CloudStack CLI
45
description: |
5-
An CLI and interactive shell that simplifies configuration and management of
6+
A CLI and interactive shell that simplifies configuration and management of
67
Apache CloudStack, the opensource IAAS cloud computing platform.
78
8-
base: core18
9+
base: core22
910
license: Apache-2.0
1011
grade: stable
1112
confinement: strict
13+
adopt-info: cloudmonkey
1214

1315
apps:
1416
cloudmonkey:
1517
command: bin/cmk
16-
plugs:
17-
- home
18-
- network
18+
plugs: [home, network]
1919

2020
parts:
2121
cloudmonkey:
22-
source: .
23-
source-type: git
24-
source-tag: 6.1.0
2522
plugin: go
26-
go-importpath: github.com/apache/cloudstack-cloudmonkey
27-
build-packages:
28-
- gcc
29-
- make
30-
- file
31-
- git
23+
source: &cmk_repo https://github.com/apache/cloudstack-cloudmonkey.git
24+
source-type: git
25+
source-tag: *release_tag
26+
source-depth: 1
27+
28+
build-snaps: [go]
29+
build-packages: [git, file, binutils]
30+
31+
build-environment:
32+
- CMK_REPO: *cmk_repo
33+
- CMK_TAG: *release_tag
34+
35+
override-pull: |
36+
set -euo pipefail
37+
craftctl default
38+
REPO="${CMK_REPO}"
39+
TAG="${CMK_TAG}"
40+
# Try to get the dereferenced commit for annotated tags first
41+
FULL_SHA="$(git ls-remote "${REPO}" "refs/tags/${TAG}^{}" | awk '{print $1}')"
42+
# If not found, fall back to the tag object itself
43+
if [ -z "${FULL_SHA}" ]; then
44+
FULL_SHA="$(git ls-remote "${REPO}" "refs/tags/${TAG}" | awk '{print $1}')"
45+
fi
46+
SHORT_SHA="${FULL_SHA:0:7}"
47+
: "${SHORT_SHA:=unknown}"
48+
echo "${SHORT_SHA}" > "$CRAFT_PART_SRC/.remote-sha"
49+
craftctl set version="${TAG}-${SHORT_SHA}"
50+
3251
override-build: |
33-
set -eu
34-
go version
35-
go mod vendor
36-
git checkout -- .
37-
git status
38-
git rev-parse HEAD
39-
go build -mod=vendor -ldflags="-s -w -X main.GitSHA=$(git rev-parse --short HEAD) -X main.BuildDate=$(date +%FT%T%z)" -o cmk cmk.go
40-
file cmk
41-
chmod +x cmk
42-
./cmk -v
43-
mkdir -p $SNAPCRAFT_PART_INSTALL/bin
44-
mv cmk $SNAPCRAFT_PART_INSTALL/bin/
45-
strip --remove-section=.comment --remove-section=.note $SNAPCRAFT_PART_INSTALL/bin/cmk
52+
set -euo pipefail
53+
cd "$CRAFT_PART_SRC"
54+
SHORT_SHA="$(cat .remote-sha 2>/dev/null || echo unknown)"
55+
BUILD_DATE="$(date +%FT%T%z)"
56+
go mod vendor || true
57+
go build -trimpath \
58+
-ldflags "-s -w -X main.GitSHA=${SHORT_SHA} -X main.BuildDate=${BUILD_DATE}" \
59+
-o cmk cmk.go
60+
install -Dm0755 cmk "$CRAFT_PART_INSTALL/bin/cmk"
61+
strip --remove-section=.comment --remove-section=.note "$CRAFT_PART_INSTALL/bin/cmk" || true

0 commit comments

Comments
 (0)