Skip to content

Commit

Permalink
ci: move tags binding to the script
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Jan 27, 2022
1 parent dbd1ab4 commit 4c929f9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 13 deletions.
31 changes: 22 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,32 @@ jobs:
uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .env
- shell: bash
run: echo "RELEASE_TAG=$(make tag)" >> $GITHUB_ENV;
- uses: actions/setup-go@v2
with:
go-version: "${{ env.GO_VERSION }}"
- name: Define and set tags
shell: bash
id: set_tags
run: |
export cross_tags="$(./scripts/image-tags.sh cross)"
export cross_base_tags="$(./scripts/image-tags.sh cross-base)"
cross_tags="${cross_tags//'%'/'%25'}"
cross_tags="${cross_tags//$'\n'/'%0A'}"
cross_tags="${cross_tags//$'\r'/'%0D'}"
cross_base_tags="${cross_base_tags//'%'/'%25'}"
cross_base_tags="${cross_base_tags//$'\n'/'%0A'}"
cross_base_tags="${cross_base_tags//$'\r'/'%0D'}"
echo "::set-output name=cross_tags::$cross_tags"
echo "::set-output name=cross_base_tags::$cross_base_tags"
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Install cosign
uses: sigstore/[email protected]
- uses: actions/setup-go@v2
with:
go-version: "${{ env.GO_VERSION }}"
- name: Install git-chglog
run: go install github.com/git-chglog/git-chglog/cmd/git-chglog@${{ env.GIT_CHGLOG_VERSION }}
- name: Build and push base images
Expand All @@ -48,8 +63,7 @@ jobs:
push: true
file: Dockerfile.base
tags: |
ghcr.io/goreleaser/goreleaser-cross-base:${{env.RELEASE_TAG}}
goreleaser/goreleaser-cross-base:${{env.RELEASE_TAG}}
${{ steps.set_tags.outputs.cross_base_tags }}
build-args: |
"GO_VERSION=${{env.GO_VERSION}}"
"GORELEASER_VERSION=${{env.GORELEASER_VERSION}}"
Expand All @@ -64,8 +78,7 @@ jobs:
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/goreleaser/goreleaser-cross:${{env.RELEASE_TAG}}
goreleaser/goreleaser-cross:${{env.RELEASE_TAG}}
${{ steps.set_tags.outputs.cross_tags }}
build-args: |
"GO_VERSION=${{env.GO_VERSION}}"
"OSX_SDK=${{env.OSX_SDK}}"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ vendor
.docker-creds
changelog.md
cosign.key
.tmpenv
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
include .env

REGISTRY ?= ghcr.io
TAG_VERSION := v$(GO_VERSION)

ifeq ($(REGISTRY),)
IMAGE_BASE_NAME := goreleaser/goreleaser-cross-base:$(TAG_VERSION)
Expand Down Expand Up @@ -77,7 +76,7 @@ docker-push: $(patsubst %, docker-push-base-%,$(SUBIMAGES))
docker-push: $(patsubst %, docker-push-%,$(SUBIMAGES))

.PHONY: manifest-create-base
manifest-create:
manifest-create-base:
@echo "creating base manifest $(IMAGE_BASE_NAME)"
docker manifest create $(IMAGE_BASE_NAME) $(foreach arch,$(SUBIMAGES), --amend $(IMAGE_BASE_NAME)-$(arch))

Expand All @@ -89,7 +88,7 @@ manifest-create:
docker manifest create $(IMAGE_NAME)-base $(foreach arch,$(SUBIMAGES), --amend $(IMAGE_NAME)-base-$(arch))

.PHONY: manifest-push-base
manifest-push:
manifest-push-base:
@echo "pushing base manifest $(IMAGE_BASE_NAME)"
docker manifest push $(IMAGE_BASE_NAME)

Expand All @@ -104,4 +103,4 @@ tags:

.PHONY: tag
tag:
@echo $(TAG_VERSION)
@echo $(GORELEASER_TAG)
37 changes: 37 additions & 0 deletions scripts/image-tags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

# in akash even minor part of the tag indicates release belongs to the MAINNET
# using it as scripts simplifies debugging as well as portability
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

function generate_tags {
hub="goreleaser/$1"
ghcr=ghcr.io/$hub

tag=$(make tag)
GORELEASER_VERSION=v$GORELEASER_VERSION

if [[ $("${SCRIPT_DIR}"/is_prerelease.sh "$tag") == true ]]; then
echo "$hub:$tag"
echo "$hub:$tag.$GORELEASER_VERSION"
echo "$ghcr:$tag"
echo "$ghcr:$tag.$GORELEASER_VERSION"
else
echo "$hub:latest"
echo "$hub:$tag"
echo "$hub:$tag-$GORELEASER_VERSION"
echo "$ghcr:latest"
echo "$ghcr:$tag-$GORELEASER_VERSION"
fi

exit 0
}

case $1 in
cross-base)
generate_tags goreleaser-cross-base
;;
cross)
generate_tags goreleaser-cross
;;
esac
12 changes: 12 additions & 0 deletions scripts/is_prerelease.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# in akash even minor part of the tag indicates release belongs to the MAINNET
# using it as scripts simplifies debugging as well as portability
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

if [[ $# -ne 1 ]]; then
echo "illegal number of parameters"
exit 1
fi

[[ -n $("${SCRIPT_DIR}"/semver.sh get prerel "$1") ]] && echo true || echo false

0 comments on commit 4c929f9

Please sign in to comment.