Skip to content

Testing release workflow #53

Testing release workflow

Testing release workflow #53

name: Release
run-name: "Testing release workflow"
env:
APPLICATION: "test-app"
GOLANG_BUILDER_VERSION: "1.22-bookworm"
TARGET_BASE_VERSION: "bookworm-20240722"
PACKAGE_NAME: "github.com/erigontech/erigon"
DOCKERHUB_REPOSITORY: "erigontech/dev-erigon"
BUILD_TAGS: "nosqlite,noboltdb,nosilkworm"
VERSION: "2.65.4"
VERSION_TMP: ".."
on:
push:
#branches-ignore:
# - '**'
#branches:
# - 'master'
#tags:
## only trigger on release tags:
#- 'v*.*.*'
#- 'v*.*.*-*'
workflow_dispatch:
inputs:
checkout_ref:
required: true
type: string
default: 'main'
description: 'The branch, tag or SHA to checkout and build artifacts from'
release_version:
required: false
type: string
description: 'Release version number (Pattern - v#.#.# , f.e. v2.41.3 or v3.0.0 )'
perform_release:
required: true
type: boolean
default: false
description: 'perform_release: when set then all artifacts will be published and the release
notes will be created. Otherwise build will be done and draft of the release notes will be created.'
jobs:
build:
runs-on: ubuntu-latest
name: Build ${{ matrix.arch }}
strategy:
matrix:
include:
- arch: linux/amd64/v2
id: linux-amd64-v2
goos: linux
goarch: amd64
flags_cc: x86_64-linux-gnu-gcc
flags_cxx: x86_64-linux-gnu-g++
build_dst: src
- arch: linux/arm64
id: linux-arm64
goos: linux
goarch: arm64
flags_cc: aarch64-linux-gnu-gcc
flags_cxx: aarch64-linux-gnu-g++
build_dst: src
steps:
- name: Checkout github repo
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ inputs.checkout_ref }}
- name: Check if tag ${{ inputs.release_version }} already exists. Exit pipeline if tag already exist.
run: |
if [ $( git ls-remote --exit-code --tags origin '${{ inputs.release_version }}' ) ]; then
echo "FAILURE: Tag ${{ inputs.release_version}} already exists!" ; exit 1
fi
- name: Debug content of current dir
run: |
pwd
ls -lao
set
- name: Get short commit id
id: GetShortCommitId
run: echo "short_commit_id=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_USERNAME }}
password: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build binary for the platform ${{ matrix.arch }}
run: |
docker run --rm --platform ${{ matrix.arch }} \
-e GOOS=${{ matrix.goos }} -e GOARCH=${{ matrix.goarch }} \
-w /app1/src \
-v $(pwd):/app1 \
golang:${{ env.GOLANG_BUILDER_VERSION }} \
/bin/bash -c "git config --global --add safe.directory . ; go build main.go; ls -lao"
- name: Build ${{ inputs.perform_release && 'and push' || 'without pushing' }} a docker image for ${{ matrix.arch }} platform
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: ${{ matrix.arch }}
build-args: |
BUILD_DST=${{ matrix.build_dst }}
GOLANG_BUILDER_VERSION=${{ env.GOLANG_BUILDER_VERSION }}
TARGET_BASE_VERSION=${{ env.TARGET_BASE_VERSION }}
BUILD_TAGS=${{ env.BUILD_TAGS }}
BUILD_TIMESTAMP=${{ steps.current_ts.outputs.date }}
VCS_REF_SHORT=${{ steps.GetShortCommitId.outputs.short_commit_id }}
VCS_REF_LONG=${{ github.sha }}
VERSION=${{ steps.GetVersion.outputs.ver }}
## push when perform_release==true only:
outputs: type=image,name=${{ env.DOCKERHUB_REPOSITORY }},push-by-digest=true,name-canonical=true,${{ inputs.perform_release && 'push=true' || 'push=false' }}
- name: Compress Artifact for the platform ${{ matrix.arch }}
env:
THIS_VERSION: ${{ inputs.release_version && inputs.release_version || format('SNAPSHOT-{0}',steps.GetShortCommitId.outputs.short_commit_id) }}
run: |
tar czvf ./${{ env.APPLICATION}}-${{ matrix.id }}-${THIS_VERSION}.tar.gz --transform "s,^,${{ env.APPLICATION}}-${{ matrix.id }}-${THIS_VERSION}/," -C src/ main
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ github.sha }}_${{ env.APPLICATION}}-${{ matrix.id }}.tar.gz
path: ./${{ env.APPLICATION}}-${{ matrix.id }}.tar.gz
retention-days: 1
compression-level: 0
if-no-files-found: error
- name: Debug 2
run: |
pwd
find . -ls
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.docker_build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.id }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
publish-artifacts:
needs: [ build ]
runs-on: ubuntu-latest
name: Publish artifacts
steps:
- name: Get short commit id
id: GetShortCommitId
run: echo "short_commit_id=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
- name: Download tar.gz artifacts
uses: actions/download-artifact@v4
with:
path: .
pattern: "${{ github.sha }}_*"
merge-multiple: true
- name: Download docker digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get version from Github tag
id: GetVersion
run: echo ver=$( echo ${{ github.ref_name }} | sed -e 's,.*\/,,g' ) >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKERHUB_REPOSITORY }}
tags: |
type=sha,enable=true,priority=100,prefix=sha-,suffix=,format=short
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_USERNAME }}
password: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_TOKEN }}
- name: Create manifest list and push ${{ inputs.perform_release && 'when perform_release is true' || '' }}
working-directory: /tmp/digests
if: ${{ inputs.perform_release }}
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.DOCKERHUB_REPOSITORY }}@sha256:%s ' *)
- name: Publish Release ${{ inputs.perform_release || 'draft' }}
if: ${{ inputs.release_version }}
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: gh release create "${{ inputs.release_version }}" --generate-notes --draft=false --title "Release ${{ inputs.release_version }}"
- name: Debug output
run: |
find . -ls