Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic semantic versioning #593

Merged
merged 8 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 0 additions & 99 deletions .github/workflows/docker-publish-opr-node-images.yaml

This file was deleted.

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

on:
push:
branches:
- pschork/semver
pschork marked this conversation as resolved.
Show resolved Hide resolved
tags:
- v*
pull_request:
workflow_dispatch:
inputs:
force:
description: "Force untagged release (expert mode)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the usecase for pushing an untagged release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows someone to release a feature branch for debugging. Running the workflow manually should be rare.

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'
29 changes: 29 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
increment: None
branches:
main:
mode: ContinuousDelivery
tag: pre
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^master$|^main$
source-branches:
- release
tracks-release-branches: true
is-release-branch: false
is-mainline: true
pre-release-weight: 55000
release:
mode: ContinuousDelivery
tag: rc
increment: None
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^v*|^releases?[/-]
source-branches:
- main
- release
tracks-release-branches: false
is-release-branch: true
is-mainline: false
pre-release-weight: 30000
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}"
Loading