From 529d0bce30e03a1e911b1ffecf2fdd0ab3362463 Mon Sep 17 00:00:00 2001 From: Semyon Bezrukov Date: Thu, 15 Sep 2022 18:18:22 +0300 Subject: [PATCH] Refactoring testing build action --- .github/workflows/4testing-build.yml | 162 ++++++++++++++++----------- 1 file changed, 99 insertions(+), 63 deletions(-) diff --git a/.github/workflows/4testing-build.yml b/.github/workflows/4testing-build.yml index 3d70142..1e13f6b 100644 --- a/.github/workflows/4testing-build.yml +++ b/.github/workflows/4testing-build.yml @@ -2,23 +2,78 @@ name: 4testing multiarch-build on: - push: - tags: - - "v*" + workflow_dispatch: + inputs: + 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: COMPANY_NAME: "onlyoffice" PRODUCT_NAME: "documentserver" jobs: - build: - name: "Build image: DocumentServer${{ matrix.edition }}" + prepare: 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: fail-fast: false matrix: - images: ["documentserver"] - edition: ["", "-ee", "-de"] + image: ["documentserver"] + edition: ${{ fromJSON(needs.prepare.outputs.editions) }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -36,68 +91,49 @@ jobs: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - name: Get Tag Name - run: | - echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - name: Build 4testing run: | + set -eux + ### ==>> 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. ### - for ARCH in ${NODE_PLATFORMS}; do - REPO_URL=${{ secrets.REPO_URL }} - if [[ ${{ env.RELEASE_VERSION }} == v99.* ]]; then - REPO_URL=${{ secrets.UNSTABLE_REPO_URL }} - DEVELOP_BUILD=true - fi - PACKAGE_URL_CHECK=${REPO_URL}${{ matrix.edition }}_"$PACKAGE_VERSION"_${ARCH}.deb - STATUS=$(curl -s -o /dev/null -w "%{http_code}\n" "${PACKAGE_URL_CHECK}") - if [[ "$STATUS" = "200" ]]; then - echo "✔ ${ARCH} is avalivable >> set like one of build platforms" - 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" ) + case ${{ matrix.edition }} in + community) + PRODUCT_EDITION="" + ;; + enterprise) + PRODUCT_EDITION="-ee" + ;; + developer) + PRODUCT_EDITION="-de" + ;; + esac - ### ==>> At this step if there is no access to any platform and platform list is empty, build will exit with 1. ### - if [[ -z ${BUILD_PLATFORMS} ]]; then - echo "Have no access to any platform >> exit with 1" - exit 1 + [ ${{ github.event.inputs.amd64 }} = true ] && PLATFORMS+=("amd64") + [ ${{ github.event.inputs.arm64 }} = true ] && PLATFORMS+=("arm64") + PLATFORM=$(echo ${PLATFORMS[*]/#/linux/} | tr ' ' ',') + + BRANCH_NAME=${GITHUB_REF#refs/heads/} + if [ $BRANCH_NAME = develop ]; then + RELEASE_BRANCH=unstable + PRODUCT_VERSION=99.99.99 + elif [[ $BRANCH_NAME =~ hotfix || $BRANCH_NAME =~ release ]]; then + RELEASE_BRANCH=testing + PRODUCT_VERSION=${BRANCH_NAME#*/v} fi - echo "DONE: Check passed >> Build for platforms: ${BUILD_PLATFORMS}" - echo "Build is starting ... >>" + BUILD_NUMBER=${{ github.event.inputs.build }} - ### == >> Set exit code for action - if [ ${BUILD_PLATFORMS} == ${EXPECTED_PLATFORMS} ]; then - EXIT_CODE=0 - echo "OK: Build platforms is expected" - else - EXIT_CODE=1 - echo "WARNING: Build platforms is unexpected action is gonna be marked as Failed" - fi + 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 ### - PRODUCT_EDITION=${{ matrix.edition }} \ - PACKAGE_URL=$PACKAGE_URL_BUILD \ - PRODUCT_NAME=${{ env.PRODUCT_NAME }} \ - 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} + ### ==>> Build and push images at this step ### + + docker buildx bake -f docker-bake.hcl ${{ matrix.image }} --push + echo "DONE: Build success" shell: bash