diff --git a/README.md b/README.md index 613dfaec..be285a10 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## 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) +## 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) `cloudmonkey` :cloud::monkey_face: is a command line interface (CLI) for [Apache CloudStack](http://cloudstack.apache.org). diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index e068632a..374fb691 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,45 +1,61 @@ name: cloudmonkey -version: git +# define the tag anchor on the allowed 'version' field +version: &release_tag 6.5.0 summary: Apache CloudStack CLI description: | - An CLI and interactive shell that simplifies configuration and management of + A CLI and interactive shell that simplifies configuration and management of Apache CloudStack, the opensource IAAS cloud computing platform. -base: core18 +base: core22 license: Apache-2.0 grade: stable confinement: strict +adopt-info: cloudmonkey apps: cloudmonkey: command: bin/cmk - plugs: - - home - - network + plugs: [home, network] parts: cloudmonkey: - source: . - source-type: git - source-tag: 6.1.0 plugin: go - go-importpath: github.com/apache/cloudstack-cloudmonkey - build-packages: - - gcc - - make - - file - - git + source: &cmk_repo https://github.com/apache/cloudstack-cloudmonkey.git + source-type: git + source-tag: *release_tag + source-depth: 1 + + build-snaps: [go] + build-packages: [git, file, binutils] + + build-environment: + - CMK_REPO: *cmk_repo + - CMK_TAG: *release_tag + + override-pull: | + set -euo pipefail + craftctl default + REPO="${CMK_REPO}" + TAG="${CMK_TAG}" + # Try to get the dereferenced commit for annotated tags first + FULL_SHA="$(git ls-remote "${REPO}" "refs/tags/${TAG}^{}" | awk '{print $1}')" + # If not found, fall back to the tag object itself + if [ -z "${FULL_SHA}" ]; then + FULL_SHA="$(git ls-remote "${REPO}" "refs/tags/${TAG}" | awk '{print $1}')" + fi + SHORT_SHA="${FULL_SHA:0:7}" + : "${SHORT_SHA:=unknown}" + echo "${SHORT_SHA}" > "$CRAFT_PART_SRC/.remote-sha" + craftctl set version="${TAG}-${SHORT_SHA}" + override-build: | - set -eu - go version - go mod vendor - git checkout -- . - git status - git rev-parse HEAD - 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 - file cmk - chmod +x cmk - ./cmk -v - mkdir -p $SNAPCRAFT_PART_INSTALL/bin - mv cmk $SNAPCRAFT_PART_INSTALL/bin/ - strip --remove-section=.comment --remove-section=.note $SNAPCRAFT_PART_INSTALL/bin/cmk + set -euo pipefail + cd "$CRAFT_PART_SRC" + SHORT_SHA="$(cat .remote-sha 2>/dev/null || echo unknown)" + BUILD_DATE="$(date +%FT%T%z)" + go mod vendor || true + go build -trimpath \ + -ldflags "-s -w -X main.GitSHA=${SHORT_SHA} -X main.BuildDate=${BUILD_DATE}" \ + -o cmk cmk.go + install -Dm0755 cmk "$CRAFT_PART_INSTALL/bin/cmk" + strip --remove-section=.comment --remove-section=.note "$CRAFT_PART_INSTALL/bin/cmk" || true