Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring build action #260

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 8 additions & 50 deletions .github/workflows/cron-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,11 @@ on:
- cron: '0 20 * * *'

jobs:

select-branches:
runs-on: ubuntu-latest

steps:
- name: Check out the code
uses: actions/checkout@v2

- name: List Branches
id: list-branches
run: |
all_branches=$(git ls-remote -hq | sed -n 's/^[0-9a-f]\{40\}\s\+refs\/heads\//''/p')
matching_branches=""

for branch in $all_branches; do
if [[ $branch =~ ^release/v[0-9]+ || $branch =~ ^hotfix/v[0-9]+ || $branch == "develop" ]]; then
matching_branches="${matching_branches},\"${branch}\""
fi
done

matching_branches=${matching_branches#,}
echo "json_output=[${matching_branches}]" >> $GITHUB_OUTPUT

last_branch=$(echo ${matching_branches} | awk -F, '{print $NF}' | sed 's/"//g')
echo "last_branch=${last_branch}" >> $GITHUB_OUTPUT

- name: Dispatch Action
run: |
echo "${{ steps.list-branches.outputs.json_output }}"

curl \
-X POST \
-u "${{ secrets.USERNAME}}:${{secrets.TOKEN}}" \
"https://api.github.com/repos/ONLYOFFICE/DocSpace-buildtools/dispatches" \
-H "Accept: application/vnd.github.everest-preview+json" \
--data '{"event_type": "cron-trigger-action", "client_payload": { "branches": ${{ steps.list-branches.outputs.json_output }}}}'

curl \
-X POST \
-u "${{ secrets.USERNAME}}:${{secrets.TOKEN}}" \
https://api.github.com/repos/ONLYOFFICE/DocSpace/actions/workflows/59268961/dispatches \
-H "Accept: application/vnd.github.everest-preview+json" \
--data '{
"ref": "${{ steps.list-branches.outputs.last_branch }}",
"inputs": {
"branch-buildtools": "${{ steps.list-branches.outputs.last_branch }}",
"branch-client": "${{ steps.list-branches.outputs.last_branch }}",
"branch-server": "${{ steps.list-branches.outputs.last_branch }}"
}
}'
call-cron-build:
uses: ONLYOFFICE/DocSpace-buildtools/.github/workflows/reusable-cron.yml@master
with:
organization: 'ONLYOFFICE'
repository: 'DocSpace-buildtools'
secrets:
git-user: ${{ secrets.USERNAME }}
git-token: ${{ secrets.TOKEN }}
95 changes: 20 additions & 75 deletions .github/workflows/main-build.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,35 @@
name: 4testing multiarch-build

on:
workflow_dispatch:
inputs:
zap:
description: 'Run ZAP scanning after build?'
type: boolean

repository_dispatch:
types:
- cron-trigger-action
- config-trigger-action
- client-trigger-action
- server-trigger-action

env:
DOCKER_PATH: "/install/docker"
REPO: "onlyoffice"
DOCKER_IMAGE_PREFIX: "4testing-docspace"
DOCKERFILE: "Dockerfile.app"

jobs:

build:
prepare-branches:
runs-on: ubuntu-latest
strategy:
matrix:
platform: [linux/amd64]
branch: ${{ github.event.client_payload.branches }}
outputs:
branches: ${{ steps.prepare.outputs.branches }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ matrix.branch }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Free Disk Space
run: |
sudo rm -rf /usr/local/lib/android /opt/ghc
sudo docker image prune --all --force

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build 4testing
id: build
run: |
cd .${DOCKER_PATH}
if [ "${{ matrix.branch }}" = "develop" ]; then
PRODUCT_VERSION="develop"
DOCKER_TAG=${PRODUCT_VERSION}.${{ github.run_number }}
else
PRODUCT_VERSION=$(echo "${{ matrix.branch }}" | sed '/^release\b\|^hotfix\b\|^feature\b/s/release.*\/\|hotfix.*\/\|feature.*\///; s/-git-action$//; s/^v//')
DOCKER_TAG=${PRODUCT_VERSION}.${{github.run_number}}
fi
export DOCKER_TAG
docker buildx bake -f build.yml \
--set *.args.GIT_BRANCH=${{ matrix.branch }} \
--set *.args.PRODUCT_VERSION=${PRODUCT_VERSION} \
--set *.args.BUILD_NUMBER=${BUILD_NUMBER} \
--set *.platform=linux/amd64 \
--set *.args.PRODUCT_VERSION=${PRODUCT_VERSION} \
--set *.args.BUILD_NUMBER=${{github.run_number}} \
--push

echo "version=${DOCKER_TAG}" >> "$GITHUB_OUTPUT"
shell: bash

- name: Run zap action if needed
if: ${{ github.event.action == 'cron-trigger-action' || github.event_name == 'workflow_dispatch' }}
- name: prepare branches
id: prepare
env:
RUN_ZAP: ${{ github.event.inputs.zap || 'true' }}
GITHUB_TOKEN: ${{ secrets.TOKEN }}
VERSION: ${{ steps.build.outputs.version }}
shell: bash
branches: ${{ join(github.event.client_payload.branches) }}
run: |
if [[ ${{ matrix.branch }} =~ release || ${{ matrix.branch }} =~ hotfix && ${RUN_ZAP} == true ]]; then
gh workflow run zap-scan.yaml \
--repo ONLYOFFICE/DocSpace \
-f branch=${{ matrix.branch }} \
-f version=${VERSION}
fi
echo "branches=$(echo ${branches} | sed 's!,! !g')" >> "$GITHUB_OUTPUT"

call-reusable-build:
needs: 'prepare-branches'
uses: ONLYOFFICE/DocSpace-buildtools/.github/workflows/reusable-build.yml@master
secrets:
docker-username: ${{ secrets.DOCKERHUB_USERNAME }}
docker-usertoken: ${{ secrets.DOCKERHUB_TOKEN }}
git-token: ${{ secrets.TOKEN }}
with:
payload-branches: "${{ needs.prepare-branches.outputs.branches }}"
dispatch-type: "${{ github.event.action }}"
dockerhub-repo: "onlyoffice"

127 changes: 127 additions & 0 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: "<reusable> DocSpace build action"

on:
workflow_call:
inputs:
payload-branches:
description: "Branches for build in json format"
required: true
type: string
dispatch-type:
description: "Dispatch-type, that trigger workflow"
required: true
type: string
custom-build-commands:
description: "Add custom commands for RUN in Dockerfile"
required: false
type: string
default: "echo placeholder"
dockerhub-repo:
description: "Set hub.docker repo owner that will be used for push images"
required: true
type: string
default: onlyoffice
secrets:
docker-username:
required: true
description: "hub.docker username"
docker-usertoken:
description: "hub.docker user token"
required: true
git-token:
description: "git token for zap scanner"
required: false

env:
DOCKER_PATH: "install/docker"
REPO: "${{ inputs.dockerhub-repo }}"
DOCKER_IMAGE_PREFIX: "4testing-docspace"
DOCKERFILE: "Dockerfile.app"

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
branches: ${{ steps.prepare.outputs.branches }}
steps:
- name: prepare branches
id: prepare
run: |
branches_array=(${{ inputs.payload-branches }})
echo "branches=$(jq -c -n '$ARGS.positional' --args "${branches_array[@]}")" >> "$GITHUB_OUTPUT"

build:
needs: 'prepare'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform: [linux/amd64]
branch: ${{ fromJSON(needs.prepare.outputs.branches) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
repository: 'ONLYOFFICE/DocSpace-buildtools'

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Free Disk Space
run: |
sudo rm -rf /usr/local/lib/android /opt/ghc
sudo docker image prune --all --force

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.docker-username }}
password: ${{ secrets.docker-usertoken }}

- name: Build 4testing
id: build
working-directory: ${{ env.DOCKER_PATH }}
env:
BUILD_NUMBER: ${{ github.run_number }}
PLATFORM: ${{ matrix.platform }}
BRANCH: ${{ matrix.branch }}
run: |
if [ "${{ matrix.branch }}" = "develop" ]; then
PRODUCT_VERSION="develop"
DOCKER_TAG=${PRODUCT_VERSION}.${BUILD_NUMBER}
else
PRODUCT_VERSION=$(echo "${{ matrix.branch }}" | sed '/^release\b\|^hotfix\b\|^feature\b/s/release.*\/\|hotfix.*\/\|feature.*\///; s/-git-action$//; s/^v//')
DOCKER_TAG=${PRODUCT_VERSION}.${BUILD_NUMBER}
fi
export DOCKER_TAG
docker buildx bake -f build.yml \
--set *.args.CUSTOM_BUILD_COMMANDS='${{ inputs.custom-build-commands }}' \
--set *.args.GIT_BRANCH=${BRANCH} \
--set *.args.PRODUCT_VERSION=${PRODUCT_VERSION} \
--set *.args.BUILD_NUMBER=${BUILD_NUMBER} \
--set *.platform=${PLATFORM} \
--push

echo "version=${DOCKER_TAG}" >> "$GITHUB_OUTPUT"
shell: bash

- name: Run zap action if needed
if: >
inputs.dispatch-type == 'cron-trigger-action' &&
github.repository == 'ONLYOFFICE/DocSpace-buildtools'
env:
GITHUB_TOKEN: ${{ secrets.git-token }}
VERSION: ${{ steps.build.outputs.version }}
shell: bash
run: |
if [[ ${{ matrix.branch }} =~ release || ${{ matrix.branch }} =~ hotfix ]]; then
gh workflow run zap-scan.yaml \
--repo ONLYOFFICE/DocSpace \
-f branch=${{ matrix.branch }} \
-f version=${VERSION}
fi
79 changes: 79 additions & 0 deletions .github/workflows/reusable-cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: "<reusable> DocSpace cron trigger"

on:
workflow_call:
inputs:
organization:
description: "Organization name"
required: false
type: string
default: 'ONLYOFFICE'
repository:
description: "Repo where reusable cron is stored"
required: false
type: string
default: 'DocSpace-buildtools'
secrets:
git-user:
required: true
description: "User that will trigger job from curl"
git-token:
description: "User token"
required: true

jobs:

select-branches:
runs-on: ubuntu-latest

steps:
- name: Check out the code
uses: actions/checkout@v4
with:
repository: 'ONLYOFFICE/DocSpace-buildtools'

- name: List Branches
id: list-branches
run: |
all_branches=$(git ls-remote -hq | sed -n 's/^[0-9a-f]\{40\}\s\+refs\/heads\//''/p')
matching_branches=""

for branch in $all_branches; do
if [[ $branch =~ ^release/v[0-9]+ || $branch =~ ^hotfix/v[0-9]+ || $branch == "develop" ]]; then
matching_branches="${matching_branches},\"${branch}\""
fi
done

matching_branches=${matching_branches#,}
echo "json_output=[${matching_branches}]" >> $GITHUB_OUTPUT

last_branch=$(echo ${matching_branches} | awk -F, '{print $NF}' | sed 's/"//g')
echo "last_branch=${last_branch}" >> $GITHUB_OUTPUT

- name: Dispatch Action
run: |
echo "${{ steps.list-branches.outputs.json_output }}"

curl \
-X POST \
-u "${{ secrets.git-user }}:${{ secrets.git-token }}" \
"https://api.github.com/repos/${{ inputs.organization }}/${{ inputs.repository }}/dispatches" \
-H "Accept: application/vnd.github.everest-preview+json" \
--data '{"event_type": "cron-trigger-action", "client_payload": { "branches": ${{ steps.list-branches.outputs.json_output }}}}'

- name: Dispatch package build
if: github.repository == 'ONLYOFFICE/DocSpace-buildtools'
run: |
curl \
-X POST \
-u "${{ secrets.git-user }}:${{ secrets.git-token }}" \
https://api.github.com/repos/ONLYOFFICE/DocSpace/actions/workflows/59268961/dispatches \
-H "Accept: application/vnd.github.everest-preview+json" \
--data '{
"ref": "${{ steps.list-branches.outputs.last_branch }}",
"inputs": {
"branch-buildtools": "${{ steps.list-branches.outputs.last_branch }}",
"branch-client": "${{ steps.list-branches.outputs.last_branch }}",
"branch-server": "${{ steps.list-branches.outputs.last_branch }}"
}
}'