Skip to content

Commit

Permalink
update release for classic
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnuj committed May 16, 2023
1 parent 8e882b7 commit 3f19574
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 8 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ on:
branches:
- main
- test
- classic
- release/v*
- classic/v*
push:
branches:
- main
- test
- classic
- release/v*
- classic/v*
tags:
- 'v*'

Expand Down Expand Up @@ -60,7 +62,8 @@ jobs:
type=edge,branch=test
type=semver,pattern={{tag}}
type=semver,pattern={{version}}
type=raw,value=classic,event=branch,enable=${{ github.ref == format('refs/heads/{0}', 'classic') }}
type=raw,value=latest,event=branch,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=classic,event=branch,enable=${{startsWith(github.ref, format('refs/heads/{0}/v', 'classic')) }}
- name: Build docker image
uses: docker/build-push-action@v3
Expand All @@ -71,3 +74,4 @@ jobs:
# platforms: linux/amd64,linux/arm64
tags: ${{ env.DOCKER_METADATA_OUTPUT_TAGS }}
labels: ${{ env.DOCKER_METADATA_OUTPUT_LABELS }}

59 changes: 59 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+' # Push events to matching v*, i.e. v1.0, v20.15.10
- 'v[0-9]+.[0-9]+.[0-9]+-rc[0-9]' # Push events to matching v*, i.e. v1.0-rc1, v20.15.10-rc5
- 'v[0-9]+.[0-9]+.[0-9]+-classic'

jobs:
release:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Create release for ${{github.ref_name}}
run: gh release create ${{github.ref_name}} --prerelease --generate-notes --repo ${{github.repository}}

artifacts:
if: startsWith(github.ref, 'refs/tags/')
needs: release
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
build_type: ['build-release-arm64', 'build-release-amd64']
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set version tag
run: echo "VERSION=$(echo ${{github.ref_name}} | sed 's/^v//')" >> $GITHUB_ENV
- name: Create build directory
run: mkdir -p build/release
- name: Build ${{matrix.build_type}}
run: make ${{matrix.build_type}}
- name: Upload the artifacts to release
run: gh release upload ${{github.ref_name}} ./build/release/*

calculate-checksums:
needs: artifacts
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Create build directory
run: mkdir -p build/release
- name: Download artifacts
run: gh release download ${{github.ref_name}} --pattern '*.tar.gz' --dir build/release --repo ${{github.repository}}
- name: Create checksums
run: |
cd build/release
sha256sum *.tar.gz > checksum.txt
- name: Display checksums
run: cat build/release/checksum.txt
- name: Upload the checksum to release
run: gh release upload ${{github.ref_name}} build/release/checksum.txt --repo ${{github.repository}}
62 changes: 57 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#!/usr/bin/make -f

BUILDDIR=build
BUILDDIR ?= $(CURDIR)/build
DOCKER := $(shell which docker)
SHA256_CMD = sha256sum
GO_VERSION ?= "1.20"

ifeq (,$(VERSION))
VERSION := $(shell git describe --tags)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif

build: go.sum
ifeq ($(OS),Windows_NT)
Expand All @@ -12,10 +23,51 @@ endif

build-static:
mkdir -p $(BUILDDIR)
docker buildx build --tag terramoney/mantlemint ./
docker create --name temp terramoney/mantlemint:latest
docker cp temp:/usr/local/bin/mantlemint $(BUILDDIR)/
docker rm temp
$(DOCKER) buildx build --tag terramoney/mantlemint ./
$(DOCKER) create --name temp terramoney/mantlemint:latest
$(DOCKER) cp temp:/usr/local/bin/mantlemint $(BUILDDIR)/
$(DOCKER) rm temp

install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./


build-release-amd64: go.sum $(BUILDDIR)/
$(DOCKER) buildx create --name mantlemint-builder || true
$(DOCKER) buildx use mantlemint-builder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg BUILDPLATFORM=linux/amd64 \
--build-arg GOOS=linux \
--build-arg GOARCH=amd64 \
-t mantlemint:local-amd64 \
--load \
-f Dockerfile .
$(DOCKER) rm -f mantlemint-builder || true
$(DOCKER) create -ti --name mantlemint-builder mantlemint:local-amd64
$(DOCKER) cp mantlemint-builder:/usr/local/bin/mantlemint $(BUILDDIR)/release/mantlemint
tar -czvf $(BUILDDIR)/release/mantlemint_$(VERSION)_Linux_x86_64.tar.gz -C $(BUILDDIR)/release/ mantlemint
rm $(BUILDDIR)/release/mantlemint
$(DOCKER) rm -f mantlemint-builder

build-release-arm64: go.sum $(BUILDDIR)/
$(DOCKER) buildx create --name mantlemint-builder || true
$(DOCKER) buildx use mantlemint-builder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg BUILDPLATFORM=linux/arm64 \
--build-arg GOOS=linux \
--build-arg GOARCH=arm64 \
-t mantlemint:local-arm64 \
--load \
-f Dockerfile .
$(DOCKER) rm -f mantlemint-builder || true
$(DOCKER) create -ti --name mantlemint-builder mantlemint:local-arm64
$(DOCKER) cp mantlemint-builder:/usr/local/bin/mantlemint $(BUILDDIR)/release/mantlemint
tar -czvf $(BUILDDIR)/release/mantlemint_$(VERSION)_Linux_aarch64.tar.gz -C $(BUILDDIR)/release/ mantlemint
rm $(BUILDDIR)/release/mantlemint
$(DOCKER) rm -f mantlemint-builder

0 comments on commit 3f19574

Please sign in to comment.