Testing release workflow #130
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
run-name: "Testing release workflow" | |
env: | |
APPLICATION: "erigon" | |
GOLANG_BUILDER_VERSION: "1.22-bookworm" | |
TARGET_BASE_VERSION: "bookworm-20240722" | |
APP_REPO: "erigontech/erigon" | |
BUILD_TAGS: "nosqlite,noboltdb,nosilkworm" | |
DOCKERHUB_REPOSITORY_DEV: "erigontech/dev-erigon" | |
DOCKERHUB_REPOSITORY_PRD: "erigontech/dev-erigon" | |
GITHUB_AUTOMATION_EMAIL: "[email protected]" | |
GITHUB_AUTOMATION_NAME: "Erigon Github Automation" | |
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 to checkout and build artifacts from. By default "main".' | |
release_version: | |
required: false | |
type: string | |
description: 'Release version number (Pattern - v#.#.# , f.e. v2.41.3 or v3.0.0 or v3.0.0-alpha1 for pre-releases)' | |
perform_release: | |
required: true | |
type: boolean | |
default: false | |
description: 'perform_release: when set then all artifacts will be published and the DRAFT of the release | |
notes will be created.' | |
jobs: | |
init: | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 30 | |
name: Init | |
outputs: | |
my_git_ref_id: ${{ steps.getCommitId.outputs.id }} | |
my_short_commit_id: ${{ steps.getCommitId.outputs.short_commit_id }} | |
steps: | |
- name: Fast checkout git repository in order to get commit id for further checkouts by this workflow | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 ## 4.1.7 release | |
with: | |
repository: ${{ env.APP_REPO }} | |
fetch-depth: 1 | |
ref: ${{ inputs.checkout_ref }} | |
- name: Check if tag ${{ inputs.release_version }} already exists. Exit workflow if tag already exist. | |
if: ${{ inputs.perform_release }} | |
run: | | |
if git ls-remote --exit-code --quiet --tags origin '${{ inputs.release_version }}'; then | |
echo "ERROR: tag ${{ inputs.release_version }} exists and workflow is performing release. Exit." | |
exit 1 | |
else | |
echo "OK: tag ${{ inputs.release_version }} does not exists. Proceeding." | |
fi | |
- name: Get commit id | |
id: getCommitId | |
run: | | |
echo "id=$(git log -1 --format='%H')" >> $GITHUB_OUTPUT | |
echo "short_commit_id=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT | |
build: | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 30 | |
name: Build ${{ matrix.id }} | |
needs: [ init ] | |
strategy: | |
matrix: | |
include: | |
- arch: linux/amd64/v2 | |
id: linux-amd64 | |
goos: linux | |
goarch: amd64 | |
docker_run_envs: -e CC=x86_64-linux-gnu-gcc -e CXX=x86_64-linux-gnu-g++ -e CGO_LDFLAGS="-s -w -extldflags '-static'" | |
build_docker_image: true | |
- arch: linux/arm64 | |
id: linux-arm64 | |
goos: linux | |
goarch: arm64 | |
docker_run_envs: -e CC=aarch64-linux-gnu-gcc -e CXX=aarch64-linux-gnu-g++ -e CGO_LDFLAGS="-s -w -extldflags '-static'" | |
build_docker_image: true | |
- arch: linux/arm64 | |
id: darwin-arm64 | |
goos: darwin | |
goarch: arm64 | |
docker_run_envs: -e CC=oa64-clang -e CXX=oa64-clang++ -e CGO_LDFLAGS="-s -w -extldflags '-static'" | |
build_docker_image: false | |
- arch: linux/amd64/v2 | |
id: darwin-amd64 | |
goos: darwin | |
goarch: amd64 | |
docker_run_envs: -e CC=o64-clang -e CXX=o64-clang++ -e CGO_LDFLAGS="-s -w" | |
build_docker_image: false | |
steps: | |
- name: Checkout github repo | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 ## 4.1.7 release | |
with: | |
repository: ${{ env.APP_REPO }} | |
fetch-depth: 1 | |
ref: ${{ needs.init.outputs.my_git_ref_id }} | |
- name: Debug content of current dir | |
run: | | |
pwd | |
ls -lao | |
set | |
- name: Login to Docker Hub | |
if: ${{ matrix.build_docker_image }} | |
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 ## v3.3.0 | |
with: | |
username: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_USERNAME }} | |
password: ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_TOKEN }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf ## v3.2.0 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db ## v3.6.1 | |
- name: Build binaries for the platform ${{ matrix.arch }} | |
run: | | |
docker run --rm --platform ${{ matrix.arch }} \ | |
-e GOOS=${{ matrix.goos }} -e GOARCH=${{ matrix.goarch }} \ | |
${{ matrix.docker_run_envs }} \ | |
-w /${{ env.APPLICATION }}/ \ | |
-v $(pwd):/${{ env.APPLICATION}} \ | |
golang:${{ env.GOLANG_BUILDER_VERSION }} \ | |
/bin/bash -c "git config --global --add safe.directory . ; make" | |
- name: Build ${{ inputs.perform_release && 'and push' || 'without pushing' }} a docker image for ${{ matrix.arch }} platform | |
id: docker_build | |
if: ${{ matrix.build_docker_image }} | |
uses: docker/build-push-action@16ebe778df0e7752d2cfcbd924afdbbd89c1a755 ## v6.6.1 | |
env: | |
LOCAL_DOCKERHUB_REPOSITORY: ${{ inputs.perform_release && env.DOCKERHUB_REPOSITORY_PRD || env.DOCKERHUB_REPOSITORY_DEV }} | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: ${{ matrix.arch }} | |
build-args: | | |
BUILD_DST=build/bin | |
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=${{ needs.init.outputs.my_short_commit_id }} | |
VCS_REF_LONG=${{ github.sha }} | |
VERSION=${{ inputs.release_version }} | |
## push when perform_release==true only: | |
outputs: type=image,name=${{ env.LOCAL_DOCKERHUB_REPOSITORY }},push-by-digest=true,name-canonical=true,${{ inputs.perform_release && 'push=true' || 'push=false' }} | |
- name: Compress Artifact for the platform ${{ matrix.arch }} | |
id: archiving | |
env: | |
LOCAL_VERSION: ${{ inputs.release_version && inputs.release_version || format('SNAPSHOT-{0}',steps.GetShortCommitId.outputs.short_commit_id) }} | |
LOCAL_APP: ${{ env.APPLICATION }} | |
LOCAL_ARCH: ${{ matrix.id }} | |
run: | | |
echo "Compressing archive with name ${LOCAL_APP}-${LOCAL_ARCH}-${LOCAL_VERSION}.tar.gz :" | |
echo "LOCAL_VERSION=${LOCAL_VERSION}" >> "$GITHUB_ENV" | |
echo "LOCAL_APP=${LOCAL_APP}" >> "$GITHUB_ENV" | |
echo "LOCAL_ARCH=${LOCAL_ARCH}" >> "$GITHUB_ENV" | |
tar czvf ./${LOCAL_APP}_${LOCAL_VERSION}_${LOCAL_ARCH}.tar.gz --transform "s,^,${LOCAL_APP}_${LOCAL_VERSION}_${LOCAL_ARCH}/," -C src/ main | |
- name: Upload Artifact | |
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a ## v4.3.6 | |
with: | |
name: ${{ github.run_id }}_${{ env.LOCAL_APP }}_${{ env.LOCAL_VERSION }}_${{ env.LOCAL_ARCH }}.tar.gz | |
path: ./${{ env.LOCAL_APP }}_${{ env.LOCAL_VERSION }}_${{ env.LOCAL_ARCH }}.tar.gz | |
retention-days: 1 | |
compression-level: 0 | |
if-no-files-found: error | |
- name: Debug 2 | |
run: | | |
pwd | |
find . -ls | |
- name: Export digest | |
if: ${{ matrix.build_docker_image }} | |
run: | | |
mkdir -p /tmp/digests | |
digest="${{ steps.docker_build.outputs.digest }}" | |
touch "/tmp/digests/${digest#sha256:}" | |
- name: Upload digest | |
if: ${{ matrix.build_docker_image }} | |
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a ## v4.3.6 | |
with: | |
name: digests-${{ matrix.id }} | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
publish-artifacts: | |
needs: [ init, build ] | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 30 | |
name: Publish artifacts | |
steps: | |
- name: Checkout github repo | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 ## 4.1.7 release | |
with: | |
repository: ${{ env.APP_REPO }} | |
fetch-depth: 1 | |
ref: ${{ needs.init.outputs.my_git_ref_id }} | |
- name: Download tar.gz artifacts | |
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 ## v4.1.8 | |
with: | |
path: . | |
pattern: "${{ github.run_id }}_*" | |
merge-multiple: true | |
- name: Download docker digests | |
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 ## v4.1.8 | |
with: | |
path: /tmp/digests | |
pattern: digests-* | |
merge-multiple: true | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db ## v3.6.1 | |
#- name: Get version from Github tag | |
# id: GetVersion | |
# run: echo ver=$( echo ${{ github.ref_name }} | sed -e 's,.*\/,,g' ) >> $GITHUB_OUTPUT | |
- name: Docker meta (configure specific tag for each use-case) | |
id: meta | |
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 ## v5.5.1 | |
with: | |
images: ${{ inputs.perform_release && env.DOCKERHUB_REPOSITORY_PRD || env.DOCKERHUB_REPOSITORY_DEV }} | |
flavor: | | |
latest=false | |
tags: | | |
type=sha,priority=100,prefix=sha-,suffix=,format=short,enable=${{ inputs.perform_release && 'false' || 'true' }} | |
type=semver,priority=100,pattern={{raw}},value=${{ inputs.release_version }},enable=${{ inputs.perform_release && 'true' || 'false' }} | |
- name: Login to Docker Hub | |
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 ## v3.3.0 | |
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 }} | |
env: | |
LOCAL_DOCKERHUB_REPOSITORY: ${{ inputs.perform_release && env.DOCKERHUB_REPOSITORY_PRD || env.DOCKERHUB_REPOSITORY_DEV }} | |
run: | | |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
$(printf '${{ env.LOCAL_DOCKERHUB_REPOSITORY }}@sha256:%s ' *) | |
- name: Generate checksum file | |
env: | |
LOCAL_VERSION: ${{ inputs.release_version && inputs.release_version || format('SNAPSHOT-{0}',needs.init.outputs.my_short_commit_id) }} | |
LOCAL_APP: ${{ env.APPLICATION }} | |
run: | | |
sha256sum *.tar.gz > ${LOCAL_APP}_${LOCAL_VERSION}_checksums.txt | |
echo "DEBUG: content of the file ${LOCAL_APP}_${LOCAL_VERSION}_checksums.txt :" | |
cat ${LOCAL_APP}_${LOCAL_VERSION}_checksums.txt | |
echo "DEBUG: end of content" | |
ls -lao | |
## temporary removed -- see tmp file | |
- name: Publish draft of the Release notes with assets | |
if: ${{ inputs.perform_release }} | |
env: | |
GH_TOKEN: ${{ github.token }} | |
GH_REPO: ${{ github.repository }} | |
DOCKER_META_TAGS: ${{ join(fromJSON(steps.meta.outputs.json).tags, ' ') }} | |
GITHUB_RELEASE_TARGET: ${{ needs.init.outputs.my_git_ref_id }} | |
LOCAL_VERSION: ${{ inputs.release_version && inputs.release_version || format('SNAPSHOT-{0}',needs.init.outputs.my_short_commit_id) }} | |
run: | | |
gh release create ${LOCAL_VERSION} *.tar.gz *_checksums.txt \ | |
--generate-notes \ | |
--verify-tag \ | |
--target ${GITHUB_RELEASE_TARGET} \ | |
--draft=true \ | |
--title "${{ inputs.release_version }}" \ | |
--notes "**Improvements:**<br>- ...coming soon <br><br>**Bugfixes:**<br><br>- ...coming soon<br><br>**Docker images:**<br><br>Docker image released:<br> ${{ env.DOCKER_META_TAGS }}<br><br>... coming soon<br>" | |