From 495d2ed6fe5a44e0b761ddc00027b9392027397a Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 6 Jun 2024 11:40:18 +0300 Subject: [PATCH] update: build workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 64 +++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 38bca4c0c..082c9a78d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,9 @@ defaults: permissions: contents: read +env: + CG_EXEC: export R_UID=$(id -u); CGROUP_LOGLEVEL=DEBUG cgexec -g cpu,memory:user.slice/user-${R_UID}.slice/user@${R_UID}.service/e2e-${{ github.run_id }} --sticky ionice -c 2 -n 2 nice -n 19 + jobs: build: name: Build using Node ${{ matrix.node }} @@ -44,7 +47,7 @@ jobs: version: 3.35.1 - name: Install PNPM - uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3.0.0 + uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 with: version: 8.15.4 @@ -65,6 +68,47 @@ jobs: node: [ "16" ] steps: + - name: Setup Control Groups + run: | + echo "::group::Get System Configuration" + USR_ID="$(id -un)" + GRP_ID="$(id -gn)" + E2E_MEM_LIMIT="30064771072" + AGENT_MEM_LIMIT="2147483648" + USER_SLICE="user.slice/user-$(id -u).slice" + USER_SERVICE="${USER_SLICE}/user@$(id -u).service" + E2E_GROUP_NAME="${USER_SERVICE}/e2e-${{ github.run_id }}" + AGENT_GROUP_NAME="${USER_SERVICE}/agent-${{ github.run_id }}" + echo "::endgroup::" + + echo "::group::Install Control Group Tools" + if ! command -v cgcreate >/dev/null 2>&1; then + sudo apt-get update + sudo apt-get install -y cgroup-tools + fi + echo "::endgroup::" + + echo "::group::Create Control Groups" + sudo cgcreate -g cpu,memory:${USER_SLICE} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID} + sudo cgcreate -g cpu,memory:${USER_SERVICE} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID} + sudo cgcreate -g cpu,memory:${E2E_GROUP_NAME} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID} + sudo cgcreate -g cpu,memory:${AGENT_GROUP_NAME} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID} + echo "::endgroup::" + + echo "::group::Set Control Group Limits" + cgset -r cpu.weight=768 ${E2E_GROUP_NAME} + cgset -r cpu.weight=500 ${AGENT_GROUP_NAME} + cgset -r memory.max=${E2E_MEM_LIMIT} ${E2E_GROUP_NAME} + cgset -r memory.max=${AGENT_MEM_LIMIT} ${AGENT_GROUP_NAME} + cgset -r memory.swap.max=${E2E_MEM_LIMIT} ${E2E_GROUP_NAME} + cgset -r memory.swap.max=${AGENT_MEM_LIMIT} ${AGENT_GROUP_NAME} + echo "::endgroup::" + + echo "::group::Move Runner Processes to Control Groups" + sudo cgclassify --sticky -g cpu,memory:${AGENT_GROUP_NAME} $(pgrep 'Runner.Listener' | tr '\n' ' ') + sudo cgclassify -g cpu,memory:${AGENT_GROUP_NAME} $(pgrep 'Runner.Worker' | tr '\n' ' ') + echo "::endgroup::" + - name: Harden Runner uses: step-security/harden-runner@f086349bfa2bd1361f7909c78558e816508cdc10 # v2.8.0 with: @@ -89,7 +133,7 @@ jobs: cat .env - name: Install PNPM - uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3.0.0 + uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 with: version: 8.15.4 @@ -112,38 +156,38 @@ jobs: id: start-local-node if: ${{ steps.build-sdk.conclusion == 'success' && !cancelled() && always() }} run: | - npx @hashgraph/hedera-local start -d --network-tag=0.49.7 --balance=100000 + ${{ env.CG_EXEC }} npx @hashgraph/hedera-local start -d --network-tag=0.49.7 --balance=100000 # Wait for the network to fully start sleep 30 - name: Run Hedera SDK Integration Tests Codecov if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:integration:codecov + run: ${{ env.CG_EXEC }} task test:integration:codecov - name: Build @hashgraph/cryptography working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task build + run: ${{ env.CG_EXEC }} task build - name: Unit Test @hashgraph/cryptography working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit + run: ${{ env.CG_EXEC }} task test:unit - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov + run: ${{ env.CG_EXEC }} task test:unit:codecov - name: Unit Test @hashgraph/sdk if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit + run: ${{ env.CG_EXEC }} task test:unit - name: Codecov @hashgraph/sdk if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov + run: ${{ env.CG_EXEC }} task test:unit:codecov - name: Stop the local node id: stop-local-node if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: npx @hashgraph/hedera-local stop \ No newline at end of file + run: ${{ env.CG_EXEC }} npx @hashgraph/hedera-local stop \ No newline at end of file