mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
test workflow
This commit is contained in:
56
.github/workflows/xahau-sh-build-in-docker.yml
vendored
56
.github/workflows/xahau-sh-build-in-docker.yml
vendored
@@ -14,40 +14,45 @@ env:
|
|||||||
DEBUG_BUILD_CONTAINERS_AFTER_CLEANUP: 1
|
DEBUG_BUILD_CONTAINERS_AFTER_CLEANUP: 1
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
checkout:
|
build-and-test:
|
||||||
runs-on: [self-hosted, vanity]
|
runs-on: [self-hosted, vanity]
|
||||||
outputs:
|
|
||||||
checkout_path: ${{ steps.vars.outputs.checkout_path }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Prepare checkout path
|
- name: Clean up any leftover containers from previous runs
|
||||||
id: vars
|
run: |
|
||||||
|
BUILD_CONTAINERS=$(docker ps -q --filter "name=xahaud_cached_builder") || true
|
||||||
|
if [[ -n "$BUILD_CONTAINERS" ]]; then
|
||||||
|
echo "Found leftover containers from previous runs, stopping them"
|
||||||
|
docker stop $BUILD_CONTAINERS || echo "Failed to stop some containers"
|
||||||
|
docker rm -f $BUILD_CONTAINERS || echo "Failed to remove some containers"
|
||||||
|
else
|
||||||
|
echo "No leftover containers found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Prepare workspace
|
||||||
run: |
|
run: |
|
||||||
SAFE_BRANCH=$(echo "${{ github.ref_name }}" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
|
SAFE_BRANCH=$(echo "${{ github.ref_name }}" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
|
||||||
CHECKOUT_PATH="${SAFE_BRANCH}-${{ github.sha }}"
|
CHECKOUT_PATH="${SAFE_BRANCH}-${{ github.sha }}"
|
||||||
echo "checkout_path=${CHECKOUT_PATH}" >> "$GITHUB_OUTPUT"
|
echo "CHECKOUT_PATH=${CHECKOUT_PATH}" >> $GITHUB_ENV
|
||||||
|
mkdir -p "$CHECKOUT_PATH"
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.vars.outputs.checkout_path }}
|
path: ${{ env.CHECKOUT_PATH }}
|
||||||
clean: true
|
clean: true
|
||||||
fetch-depth: 2 # Only get the last 2 commits, to avoid fetching all history
|
fetch-depth: 2
|
||||||
|
|
||||||
build:
|
|
||||||
runs-on: [self-hosted, vanity]
|
|
||||||
needs: [checkout]
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: ${{ needs.checkout.outputs.checkout_path }}
|
|
||||||
steps:
|
|
||||||
- name: Set Cleanup Script Path
|
- name: Set Cleanup Script Path
|
||||||
run: |
|
run: |
|
||||||
echo "JOB_CLEANUP_SCRIPT=$(mktemp)" >> $GITHUB_ENV
|
echo "JOB_CLEANUP_SCRIPT=$(mktemp)" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Build using Docker
|
- name: Build using Docker
|
||||||
|
working-directory: ${{ env.CHECKOUT_PATH }}
|
||||||
run: /bin/bash release-builder.sh
|
run: /bin/bash release-builder.sh
|
||||||
|
|
||||||
- name: Stop Container (Cleanup)
|
- name: Stop Container (Cleanup after build)
|
||||||
if: always()
|
if: always()
|
||||||
|
working-directory: ${{ env.CHECKOUT_PATH }}
|
||||||
run: |
|
run: |
|
||||||
echo "Running cleanup script: $JOB_CLEANUP_SCRIPT"
|
echo "Running cleanup script: $JOB_CLEANUP_SCRIPT"
|
||||||
/bin/bash -e -x "$JOB_CLEANUP_SCRIPT"
|
/bin/bash -e -x "$JOB_CLEANUP_SCRIPT"
|
||||||
@@ -73,23 +78,12 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tests:
|
- name: Run unit tests
|
||||||
runs-on: [self-hosted, vanity]
|
working-directory: ${{ env.CHECKOUT_PATH }}
|
||||||
needs: [build, checkout]
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: ${{ needs.checkout.outputs.checkout_path }}
|
|
||||||
steps:
|
|
||||||
- name: Unit tests
|
|
||||||
run: /bin/bash docker-unit-tests.sh
|
run: /bin/bash docker-unit-tests.sh
|
||||||
|
|
||||||
cleanup:
|
|
||||||
runs-on: [self-hosted, vanity]
|
|
||||||
needs: [tests, checkout]
|
|
||||||
if: always()
|
|
||||||
steps:
|
|
||||||
- name: Cleanup workspace
|
- name: Cleanup workspace
|
||||||
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
CHECKOUT_PATH="${{ needs.checkout.outputs.checkout_path }}"
|
|
||||||
echo "Cleaning workspace for ${CHECKOUT_PATH}"
|
echo "Cleaning workspace for ${CHECKOUT_PATH}"
|
||||||
rm -rf "${{ github.workspace }}/${CHECKOUT_PATH}"
|
rm -rf "${{ github.workspace }}/${CHECKOUT_PATH}"
|
||||||
|
|||||||
@@ -5,6 +5,42 @@
|
|||||||
# debugging.
|
# debugging.
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
|
# which docker 2> /dev/null 2> /dev/null
|
||||||
|
# if [ "$?" -eq "1" ]
|
||||||
|
# then
|
||||||
|
# echo 'Docker not found. Install it first.'
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# stat .git 2> /dev/null 2> /dev/null
|
||||||
|
# if [ "$?" -eq "1" ]
|
||||||
|
# then
|
||||||
|
# echo 'Run this inside the source directory. (.git dir not found).'
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# Add trap to handle termination
|
||||||
|
cleanup() {
|
||||||
|
echo "Script received termination signal - cleaning up containers"
|
||||||
|
# Get container ID if it exists
|
||||||
|
if [[ -n "${CONTAINER_NAME:-}" ]]; then
|
||||||
|
docker stop "${CONTAINER_NAME}" || echo "Failed to stop container (may not exist)"
|
||||||
|
docker rm -f "${CONTAINER_NAME}" 2>/dev/null || echo "Failed to remove container (may not exist)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Find and stop any other build containers that might be running
|
||||||
|
BUILD_CONTAINERS=$(docker ps -q --filter "name=xahaud_cached_builder")
|
||||||
|
if [[ -n "$BUILD_CONTAINERS" ]]; then
|
||||||
|
echo "Stopping other build containers: $BUILD_CONTAINERS"
|
||||||
|
docker stop $BUILD_CONTAINERS || echo "Failed to stop some containers"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set trap for common termination signals
|
||||||
|
trap cleanup SIGINT SIGTERM INT TERM
|
||||||
|
|
||||||
echo "START BUILDING (HOST)"
|
echo "START BUILDING (HOST)"
|
||||||
|
|
||||||
echo "Cleaning previously built binary"
|
echo "Cleaning previously built binary"
|
||||||
@@ -30,20 +66,6 @@ echo "-- GITHUB_SHA: $GITHUB_SHA"
|
|||||||
echo "-- GITHUB_RUN_NUMBER: $GITHUB_RUN_NUMBER"
|
echo "-- GITHUB_RUN_NUMBER: $GITHUB_RUN_NUMBER"
|
||||||
echo "-- CONTAINER_NAME: $CONTAINER_NAME"
|
echo "-- CONTAINER_NAME: $CONTAINER_NAME"
|
||||||
|
|
||||||
which docker 2> /dev/null 2> /dev/null
|
|
||||||
if [ "$?" -eq "1" ]
|
|
||||||
then
|
|
||||||
echo 'Docker not found. Install it first.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
stat .git 2> /dev/null 2> /dev/null
|
|
||||||
if [ "$?" -eq "1" ]
|
|
||||||
then
|
|
||||||
echo 'Run this inside the source directory. (.git dir not found).'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
STATIC_CONTAINER=$(docker ps -a | grep $CONTAINER_NAME |wc -l)
|
STATIC_CONTAINER=$(docker ps -a | grep $CONTAINER_NAME |wc -l)
|
||||||
|
|
||||||
#if [[ "$STATIC_CONTAINER" -gt "0" && "$GITHUB_REPOSITORY" != "" ]]; then
|
#if [[ "$STATIC_CONTAINER" -gt "0" && "$GITHUB_REPOSITORY" != "" ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user