Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Fixed bad version generation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fheinecke committed Jan 23, 2024
1 parent 8326466 commit a840233
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 41 deletions.
47 changes: 25 additions & 22 deletions .github/workflows/tag-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,49 @@ on:
- master

concurrency:
group: "Limit to one build at a time for ref ${{ format('refs/tags/{0}', inputs.artifact-tag) || github.ref }}"
group: "Limit to one build at a time for ref ${{ format('refs/tags/{0}', inputs.artifact-tag) || github.head_ref }}"
cancel-in-progress: true

env:
TESTVAR: testval

jobs:
setup:
runs-on: ubuntu-latest
outputs:
gitref: ${{ steps.set-gitref.outputs.gitref }}
environment: ${{ steps.set-variables.outputs.environment }}
version: ${{ steps.set-variables.outputs.version }}
gitref: ${{ steps.set-variables.outputs.gitref }}
steps:
# TODO this really needs to move to shared workflows. This is the ~fourth place
# that this logic has been used.
- name: Determine git ref
id: set-gitref
env:
EVENT_NAME: ${{ github.event_name}}
REF_TYPE: ${{ github.ref_type }}
REF_VALUE: ${{ inputs.artifact-tag || github.head_ref }}
run: |
# If value is a tag
if [ "$EVENT_NAME" == "workflow_dispatch" ] || [ "$REF_TYPE" == "tag" ]; then
echo "gitref=refs/tags/$REF_VALUE" >> "$GITHUB_OUTPUT"
exit 0
fi
# Otherwise, ref must be a branch
echo "gitref=refs/heads/$REF_VALUE" >> "$GITHUB_OUTPUT"
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ steps.set-gitref.outputs.gitref }}
- name: Set environment output values
id: set-variables
env:
GITHUB_EVENT_REF: ${{ github.ref || github.action_ref }}
GITHUB_EVENT_NAME: ${{ github.event_name}}
INPUT_VERSION: ${{ inputs.artifact-tag }}
SEMVER_REGEX: ^v?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?:[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
run: |
generate_version() {
GITREF=$1
VERSION_BASE=$(git describe --tags --match "v[[:digit:]]*.[[:digit:]]*.[[:digit:]]")
VERSION_METADATA=$(git show-ref --heads --tags --hash=8 "$GITREF" | head -n 1)
echo "$VERSION_BASE+$VERSION_METADATA"
# Example: v1.2.3-gen.4+g5678abcd
git describe --tags --match "v[[:digit:]]*.[[:digit:]]*.[[:digit:]]" | sed 's/\(.*\)-\(.*\)-\(.*\)/\1-gen.\2+\3/'
}
get_output_vars() {
Expand All @@ -63,38 +73,31 @@ jobs:
# Case: workflow dispatch event. Pull most vars from inputs.
echo "environment=build-stage"
echo "version=$INPUT_VERSION"
echo "gitref=$GITHUB_EVENT_REF"
;;
"pull_request")
echo "environment=build-stage"
echo "version=$(generate_version "$GITHUB_EVENT_REF")"
echo "gitref=$GITHUB_EVENT_REF"
echo "version=$(generate_version "$GITHUB_EVENT_REF_NAME")"
;;
"push")
REF_TYPE=$(echo "$GITHUB_EVENT_REF" | cut -d'/' -f2)
# Case: commit push event.
if [ "$REF_TYPE" != "tags" ]; then
echo "environment=build-stage"
echo "version=$(generate_version "$GITHUB_EVENT_REF")"
echo "gitref=$GITHUB_EVENT_REF"
echo "version=$(generate_version "$GITHUB_EVENT_REF_NAME")"
return
fi
VERSION_TAG=$(echo "$GITHUB_EVENT_REF" | cut -d'/' -f3)
# Case: tag event with prerelease version.
if [ "${VERSION_TAG#*-}" != "$VERSION_TAG" ]; then
if [ "${GITHUB_EVENT_REF_NAME#*-}" != "$GITHUB_EVENT_REF_NAME" ]; then
echo "environment=build-stage"
echo "version=$VERSION_TAG"
echo "gitref=$GITHUB_EVENT_REF"
echo "version=$GITHUB_EVENT_REF_NAME"
return
fi
# Case: tag event with release version. Only this
# should go to prod.
echo "environment=build-prod"
echo "version=$VERSION_TAG"
echo "gitref=$GITHUB_EVENT_REF"
echo "version=$GITHUB_EVENT_REF_NAME"
;;
*)
>&2 echo "Unknown GHA event $GITHUB_EVENT_NAME, failing"
Expand Down
7 changes: 4 additions & 3 deletions access/discord/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=?14.3.3
VERSION?=14.3.3
GO_VERSION=1.21.6

BUILDDIR ?= build
Expand All @@ -16,11 +16,12 @@ RELEASE=$(RELEASE_NAME)-$(GITTAG)-$(OS)-$(ARCH)-bin

RELEASE_MESSAGE = "Building with GOOS=$(OS) GOARCH=$(ARCH)."

DOCKER_VERSION = $(subst +,_,$(VERSION))
DOCKER_NAME = teleport-plugin-discord
DOCKER_PRIVATE_REGISTRY = 146628656107.dkr.ecr.us-west-2.amazonaws.com
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_ECR_PUBLIC_REGISTRY = public.ecr.aws/gravitational
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_BUILD_ARGS = --build-arg GO_VERSION=${GO_VERSION} --build-arg ACCESS_PLUGIN=discord --build-arg GITREF=$(GITREF) --build-arg VERSION=$(VERSION)

.PHONY: $(BINARY)
Expand Down
5 changes: 3 additions & 2 deletions access/email/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ RELEASE=$(RELEASE_NAME)-$(GITTAG)-$(OS)-$(ARCH)-bin

RELEASE_MESSAGE = "Building with GOOS=$(OS) GOARCH=$(ARCH)."

DOCKER_VERSION = $(subst +,_,$(VERSION))
DOCKER_NAME = teleport-plugin-email
DOCKER_PRIVATE_REGISTRY = 146628656107.dkr.ecr.us-west-2.amazonaws.com
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_ECR_PUBLIC_REGISTRY = public.ecr.aws/gravitational
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_BUILD_ARGS = --build-arg GO_VERSION=${GO_VERSION} --build-arg ACCESS_PLUGIN=email --build-arg GITREF=$(GITREF) --build-arg VERSION=$(VERSION)

.PHONY: $(BINARY)
Expand Down
7 changes: 4 additions & 3 deletions access/jira/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=?14.3.3
VERSION?=14.3.3
GO_VERSION=1.21.6

BUILDDIR ?= build
Expand All @@ -16,11 +16,12 @@ RELEASE=$(RELEASE_NAME)-$(GITTAG)-$(OS)-$(ARCH)-bin

RELEASE_MESSAGE = "Building with GOOS=$(OS) GOARCH=$(ARCH)."

DOCKER_VERSION = $(subst +,_,$(VERSION))
DOCKER_NAME = teleport-plugin-jira
DOCKER_PRIVATE_REGISTRY = 146628656107.dkr.ecr.us-west-2.amazonaws.com
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_ECR_PUBLIC_REGISTRY = public.ecr.aws/gravitational
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_BUILD_ARGS = --build-arg GO_VERSION=${GO_VERSION} --build-arg ACCESS_PLUGIN=jira --build-arg GITREF=$(GITREF) --build-arg VERSION=$(VERSION)

.PHONY: $(BINARY)
Expand Down
5 changes: 3 additions & 2 deletions access/mattermost/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ RELEASE=$(RELEASE_NAME)-$(GITTAG)-$(OS)-$(ARCH)-bin

RELEASE_MESSAGE = "Building with GOOS=$(OS) GOARCH=$(ARCH)."

DOCKER_VERSION = $(subst +,_,$(VERSION))
DOCKER_NAME = teleport-plugin-mattermost
DOCKER_PRIVATE_REGISTRY = 146628656107.dkr.ecr.us-west-2.amazonaws.com
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_ECR_PUBLIC_REGISTRY = public.ecr.aws/gravitational
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_BUILD_ARGS = --build-arg GO_VERSION=${GO_VERSION} --build-arg ACCESS_PLUGIN=mattermost --build-arg GITREF=$(GITREF) --build-arg VERSION=$(VERSION)

.PHONY: $(BINARY)
Expand Down
5 changes: 3 additions & 2 deletions access/msteams/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ RELEASE=$(RELEASE_NAME)-$(GITTAG)-$(OS)-$(ARCH)-bin

RELEASE_MESSAGE = "Building with GOOS=$(OS) GOARCH=$(ARCH)."

DOCKER_VERSION = $(subst +,_,$(VERSION))
DOCKER_NAME = teleport-plugin-msteams
DOCKER_PRIVATE_REGISTRY = 146628656107.dkr.ecr.us-west-2.amazonaws.com
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_ECR_PUBLIC_REGISTRY = public.ecr.aws/gravitational
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_BUILD_ARGS = --build-arg GO_VERSION=${GO_VERSION} --build-arg ACCESS_PLUGIN=msteams --build-arg GITREF=$(GITREF) --build-arg VERSION=$(VERSION)

.PHONY: $(BINARY)
Expand Down
5 changes: 3 additions & 2 deletions access/pagerduty/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ RELEASE=$(RELEASE_NAME)-$(GITTAG)-$(OS)-$(ARCH)-bin

RELEASE_MESSAGE = "Building with GOOS=$(OS) GOARCH=$(ARCH)."

DOCKER_VERSION = $(subst +,_,$(VERSION))
DOCKER_NAME = teleport-plugin-pagerduty
DOCKER_PRIVATE_REGISTRY = 146628656107.dkr.ecr.us-west-2.amazonaws.com
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_ECR_PUBLIC_REGISTRY = public.ecr.aws/gravitational
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_BUILD_ARGS = --build-arg GO_VERSION=${GO_VERSION} --build-arg ACCESS_PLUGIN=pagerduty --build-arg GITREF=$(GITREF) --build-arg VERSION=$(VERSION)

.PHONY: $(BINARY)
Expand Down
5 changes: 3 additions & 2 deletions access/slack/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ RELEASE=$(RELEASE_NAME)-$(GITTAG)-$(OS)-$(ARCH)-bin

RELEASE_MESSAGE = "Building with GOOS=$(OS) GOARCH=$(ARCH)."

DOCKER_VERSION = $(subst +,_,$(VERSION))
DOCKER_NAME = teleport-plugin-slack
DOCKER_PRIVATE_REGISTRY = 146628656107.dkr.ecr.us-west-2.amazonaws.com
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_ECR_PUBLIC_REGISTRY = public.ecr.aws/gravitational
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_BUILD_ARGS = --build-arg GO_VERSION=${GO_VERSION} --build-arg ACCESS_PLUGIN=slack --build-arg GITREF=$(GITREF) --build-arg VERSION=$(VERSION)

.PHONY: $(BINARY)
Expand Down
5 changes: 3 additions & 2 deletions event-handler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ KEYLEN = 1024
CLOUD_ADDR=evilmartians.teleport.sh:443
IDENTITY_FILE=example/keys/identity

DOCKER_VERSION = $(subst +,_,$(VERSION))
DOCKER_NAME=teleport-plugin-event-handler
DOCKER_PRIVATE_REGISTRY = 146628656107.dkr.ecr.us-west-2.amazonaws.com
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_ECR_PUBLIC_REGISTRY = public.ecr.aws/gravitational
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_BUILD_ARGS = --build-arg GO_VERSION=${GO_VERSION} --build-arg GITREF=$(GITREF) --build-arg VERSION=$(VERSION)

RELEASE_NAME = teleport-event-handler
Expand Down
2 changes: 1 addition & 1 deletion event-handler/build.assets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ OS ?= $(shell go env GOOS)
ARCH ?= $(shell go env GOARCH)

HOSTNAME=buildbox
BUILDBOX ?= teleport-plugins-event-handler:$(VERSION)
BUILDBOX ?= teleport-plugins-event-handler:$(DOCKER_VERSION)
GOCACHE ?= $(HOME)/.cache/go-build
DOCKERFLAGS := --rm \
-v "$(TOP)":$(SRCDIR) \
Expand Down

0 comments on commit a840233

Please sign in to comment.