Skip to content

Commit

Permalink
Automatic semantic versioning (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
pschork committed Jun 4, 2024
1 parent b6dc720 commit 67529ef
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 106 deletions.
99 changes: 0 additions & 99 deletions .github/workflows/docker-publish-opr-node-images.yaml

This file was deleted.

78 changes: 78 additions & 0 deletions .github/workflows/docker-publish-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: docker-publish-release

on:
push:
tags:
- v*
pull_request:
workflow_dispatch:
inputs:
force:
description: "Force untagged release (expert mode)"
required: false
default: false
type: boolean

env:
REGISTRY: ghcr.io
CACHE-FROM: /tmp/.buildx-cache
CACHE-TO: /tmp/.buildx-cache-new

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.x'

- name: Determine SemVer
uses: gittools/actions/gitversion/[email protected]
with:
useConfigFile: true

- run: |
echo "SemVer ${{ env.fullSemVer }} Forced ${{ github.event.inputs.force }}"
name: Display SemVer
- name: Setup Buildx
uses: docker/setup-buildx-action@v1
with:
install: true
driver-opts: image=moby/buildkit:master

- name: Cache docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
if: ${{ success() }}

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
if: ${{ success() }}

# Build And Push Image
- name: Build docker image release
run: make docker-release-build
if: ${{ success() }}

# Publish if release is tagged or force == true
- name: Push docker image release
run: make docker-release-push
if: startsWith(github.ref, 'refs/tags/v') || github.event.inputs.force == 'true'
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ branches:
increment: None
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^releases?[/-]
regex: ^v*|^releases?[/-]
source-branches:
- main
- release
Expand Down
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
.PHONY: compile-el compile-dl clean protoc lint build unit-tests integration-tests-churner integration-tests-indexer integration-tests-inabox integration-tests-inabox-nochurner integration-tests-graph-indexer

ifeq ($(wildcard .git/*),)
$(warning semver disabled - building from release zip)
GITCOMMIT := ""
GITDATE := ""
SEMVER := $(shell basename $(CURDIR))
else
GITCOMMIT := $(shell git rev-parse --short HEAD)
GITDATE := $(shell git log -1 --format=%cd --date=unix)
SEMVER := $(shell docker run --rm --volume "$(PWD):/repo" gittools/gitversion:5.12.0 /repo -output json -showvariable SemVer)
ifeq ($(SEMVER), )
$(warning semver disabled - docker not installed)
SEMVER := "0.0.0"
endif
endif

RELEASE_TAG := $(or $(RELEASE_TAG),latest)

PROTOS := ./api/proto
PROTOS_DISPERSER := ./disperser/api/proto
PROTO_GEN := ./api/grpc
Expand Down Expand Up @@ -75,3 +92,12 @@ integration-tests-graph-indexer:
integration-tests-dataapi:
make dataapi-build
go test -v ./disperser/dataapi

docker-release-build:
RELEASE_TAG=${SEMVER} docker compose -f docker-compose-release.yaml build --build-arg SEMVER=${SEMVER} --build-arg GITCOMMIT=${GITCOMMIT} --build-arg GITDATE=${GITDATE}

docker-release-push:
RELEASE_TAG=${SEMVER} docker compose -f docker-compose-release.yaml push

semver:
echo "${SEMVER}"
12 changes: 12 additions & 0 deletions docker-compose-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is used for building and pushing images
services:
node:
build:
context: .
dockerfile: node/cmd/Dockerfile
image: ghcr.io/layr-labs/eigenda/opr-node:${RELEASE_TAG}
nodeplugin:
build:
context: .
dockerfile: node/plugin/cmd/Dockerfile
image: ghcr.io/layr-labs/eigenda/opr-nodeplugin:${RELEASE_TAG}
20 changes: 14 additions & 6 deletions node/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
ifeq ($(wildcard ../.git/*),)
$(warning semver disabled - building from release zip)
GITCOMMIT := ""
GITDATE := ""
SEMVER := $(shell basename $(CURDIR))
else
GITCOMMIT := $(shell git rev-parse --short HEAD)
GITDATE := $(shell git log -1 --format=%cd --date=unix)

# GitVersion provides the semantic versioning for the project.
SEMVER := $(shell docker run --rm --volume "${PWD}/../:/repo" gittools/gitversion:5.12.0 /repo -output json -showvariable SemVer)
SEMVER := $(shell docker run --rm --volume "$(PWD)/../:/repo" gittools/gitversion:5.12.0 /repo -output json -showvariable SemVer)
ifeq ($(SEMVER), )
SEMVER = "0.0.0" # Fallback if docker is not installed or gitversion fails
$(warning semver disabled - docker not installed)
SEMVER := "0.0.0"
endif
endif

RELEASE_TAG := $(or $(RELEASE_TAG),latest)

build: clean
go mod tidy
go build -o ./bin/node ./cmd
Expand All @@ -17,10 +25,10 @@ clean:
docker: docker-node docker-plugin

docker-node:
cd ../ && docker build --build-arg SEMVER=${SEMVER} --build-arg GITCOMMIT=${GITCOMMIT} --build-arg GITDATE=${GITDATE} . -t opr-node:${SEMVER} -t opr-node:latest -f node/cmd/Dockerfile
cd ../ && docker build --build-arg SEMVER=${SEMVER} --build-arg GITCOMMIT=${GITCOMMIT} --build-arg GITDATE=${GITDATE} . -t opr-node:${SEMVER} -t opr-node:${RELEASE_TAG} -f node/cmd/Dockerfile

docker-plugin:
cd ../ && docker build --build-arg SEMVER=${SEMVER} --build-arg GITCOMMIT=${GITCOMMIT} --build-arg GITDATE=${GITDATE} . -t opr-nodeplugin:${SEMVER} -t opr-nodeplugin:latest -f node/plugin/cmd/Dockerfile
cd ../ && docker build --build-arg SEMVER=${SEMVER} --build-arg GITCOMMIT=${GITCOMMIT} --build-arg GITDATE=${GITDATE} . -t opr-nodeplugin:${SEMVER} -t opr-nodeplugin:${RELEASE_TAG} -f node/plugin/cmd/Dockerfile

semver:
echo "${SEMVER}"

0 comments on commit 67529ef

Please sign in to comment.