Refactoring testing build action

This commit is contained in:
Semyon Bezrukov 2022-09-15 18:18:22 +03:00
parent 2598cb8f70
commit 529d0bce30

View file

@ -2,23 +2,78 @@
name: 4testing multiarch-build name: 4testing multiarch-build
on: on:
push: workflow_dispatch:
tags: inputs:
- "v*" build:
description: 'Build number (ex. 45)'
type: string
required: true
amd64:
type: boolean
description: 'Build AMD64'
default: true
arm64:
type: boolean
description: 'Build ARM64'
default: true
community:
type: boolean
description: 'Build Community Edition'
default: true
enterprise:
type: boolean
description: 'Build Enterprise Edition'
default: true
developer:
type: boolean
description: 'Build Developer Edition'
default: true
env: env:
COMPANY_NAME: "onlyoffice" COMPANY_NAME: "onlyoffice"
PRODUCT_NAME: "documentserver" PRODUCT_NAME: "documentserver"
jobs: jobs:
build: prepare:
name: "Build image: DocumentServer${{ matrix.edition }}"
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps:
- id: matrix
run: |
set -ex
BRANCH_NAME=${GITHUB_REF#refs/heads/}
if ! [[ $BRANCH_NAME == develop || $BRANCH_NAME =~ hotfix || $BRANCH_NAME =~ release ]]; then
echo "Wrong branch."
exit 1
fi
[ ${{ github.event.inputs.amd64 }} = true ] && PLATFORMS+=("amd64")
[ ${{ github.event.inputs.arm64 }} = true ] && PLATFORMS+=("arm64")
if [ -z ${PLATFORMS} ]; then
echo "None of the platforms are selected."
exit 1
fi
[ ${{ github.event.inputs.community }} = true ] && EDITIONS+=("community")
[ ${{ github.event.inputs.enterprise }} = true ] && EDITIONS+=("enterprise")
[ ${{ github.event.inputs.developer }} = true ] && EDITIONS+=("developer")
if [ -z ${EDITIONS} ]; then
echo "None of the editions are selected."
exit 1
fi
echo "::set-output name=editions::$(jq -n -c --arg s "${EDITIONS[*]}" '($s|split(" "))')"
outputs:
editions: ${{ steps.matrix.outputs.editions }}
build:
name: "Build ${{ matrix.image }}-${{ matrix.edition }}"
runs-on: ubuntu-latest
needs: prepare
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
images: ["documentserver"] image: ["documentserver"]
edition: ["", "-ee", "-de"] edition: ${{ fromJSON(needs.prepare.outputs.editions) }}
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
@ -36,68 +91,49 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USERNAME }} username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Get Tag Name
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Build 4testing - name: Build 4testing
run: | run: |
set -eux
### ==>> At this step build variable declaration ### ### ==>> At this step build variable declaration ###
DOCKER_TAG=$( echo ${{ env.RELEASE_VERSION }} | sed 's/^.//' )
PACKAGE_VERSION=$( echo $DOCKER_TAG | sed -E 's/(.*)\./\1-/' )
NODE_PLATFORMS=$( echo ${{ steps.buildx.outputs.platforms }} | sed 's/linux\///g' | sed 's/,/ /g' )
EXPECTED_PLATFORMS="linux/amd64,linux/arm64"
echo "Start check avalivable build platforms >>"
### ==>> In this loop we will check all avalivable documentserver architectures. After that all accessed arch will be added to build-platforms list. ### case ${{ matrix.edition }} in
for ARCH in ${NODE_PLATFORMS}; do community)
REPO_URL=${{ secrets.REPO_URL }} PRODUCT_EDITION=""
if [[ ${{ env.RELEASE_VERSION }} == v99.* ]]; then ;;
REPO_URL=${{ secrets.UNSTABLE_REPO_URL }} enterprise)
DEVELOP_BUILD=true PRODUCT_EDITION="-ee"
fi ;;
PACKAGE_URL_CHECK=${REPO_URL}${{ matrix.edition }}_"$PACKAGE_VERSION"_${ARCH}.deb developer)
STATUS=$(curl -s -o /dev/null -w "%{http_code}\n" "${PACKAGE_URL_CHECK}") PRODUCT_EDITION="-de"
if [[ "$STATUS" = "200" ]]; then ;;
echo "✔ ${ARCH} is avalivable >> set like one of build platforms" esac
PLATFORMS+=(linux/${ARCH},)
BUILD_PLATFORMS=$( echo ${PLATFORMS[@]} | sed 's/ //g' | sed 's/\(.*\),/\1/' )
else
echo "Х ${ARCH} in not avalivable"
fi
done
PACKAGE_URL_BUILD=$( echo ${PACKAGE_URL_CHECK} | sed -e "s/${PACKAGE_VERSION}_.*.deb/${PACKAGE_VERSION}_TARGETARCH.deb/g" )
### ==>> At this step if there is no access to any platform and platform list is empty, build will exit with 1. ### [ ${{ github.event.inputs.amd64 }} = true ] && PLATFORMS+=("amd64")
if [[ -z ${BUILD_PLATFORMS} ]]; then [ ${{ github.event.inputs.arm64 }} = true ] && PLATFORMS+=("arm64")
echo "Have no access to any platform >> exit with 1" PLATFORM=$(echo ${PLATFORMS[*]/#/linux/} | tr ' ' ',')
exit 1
fi
echo "DONE: Check passed >> Build for platforms: ${BUILD_PLATFORMS}"
echo "Build is starting ... >>"
### == >> Set exit code for action BRANCH_NAME=${GITHUB_REF#refs/heads/}
if [ ${BUILD_PLATFORMS} == ${EXPECTED_PLATFORMS} ]; then if [ $BRANCH_NAME = develop ]; then
EXIT_CODE=0 RELEASE_BRANCH=unstable
echo "OK: Build platforms is expected" PRODUCT_VERSION=99.99.99
else elif [[ $BRANCH_NAME =~ hotfix || $BRANCH_NAME =~ release ]]; then
EXIT_CODE=1 RELEASE_BRANCH=testing
echo "WARNING: Build platforms is unexpected action is gonna be marked as Failed" PRODUCT_VERSION=${BRANCH_NAME#*/v}
fi fi
BUILD_NUMBER=${{ github.event.inputs.build }}
export PRODUCT_EDITION
export PACKAGE_VERSION=${PRODUCT_VERSION}-${BUILD_NUMBER}
export PACKAGE_BASEURL=http://repo-doc-onlyoffice-com.s3.amazonaws.com/${COMPANY_NAME}/${RELEASE_BRANCH}/ubuntu
export RELEASE_BRANCH
export PLATFORM
export DOCKERFILE=Dockerfile
export PREFIX_NAME=4testing-
export TAG=${PRODUCT_VERSION}.${BUILD_NUMBER}
### ==>> Build and push images at this step ### ### ==>> Build and push images at this step ###
PRODUCT_EDITION=${{ matrix.edition }} \
PACKAGE_URL=$PACKAGE_URL_BUILD \ docker buildx bake -f docker-bake.hcl ${{ matrix.image }} --push
PRODUCT_NAME=${{ env.PRODUCT_NAME }} \ echo "DONE: Build success"
DOCKERFILE=Dockerfile \
PREFIX_NAME=4testing- \
TAG=$DOCKER_TAG \
PLATFORM=$BUILD_PLATFORMS \
COMPANY_NAME=${{ env.COMPANY_NAME }} \
DEVELOP_BUILD=$DEVELOP_BUILD \
docker buildx bake \
-f docker-bake.hcl ${{ matrix.images }} \
--push
echo "DONE: Build success >> exit with ${EXIT_CODE}"
exit ${EXIT_CODE}
shell: bash shell: bash