Reuse ports during tests #1123
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: | |
| - "main" | |
| - "release-branch/*" | |
| paths-ignore: | |
| - "docs/**" | |
| - "ui/**" | |
| merge_group: | |
| branches: | |
| - "main" | |
| workflow_call: | |
| inputs: | |
| enable_kubernetes_tests: | |
| description: "Run Kubernetes tests regardless of changed files" | |
| required: false | |
| default: false | |
| type: boolean | |
| secrets: | |
| CL_INFOCLACE_SSH: | |
| required: false | |
| CL_GITHUB_SECRET: | |
| required: false | |
| TEST_PAT: | |
| required: false | |
| CODECOV_TOKEN: | |
| required: false | |
| permissions: | |
| contents: read | |
| concurrency: | |
| # For PRs, later CI runs preempt previous ones. e.g. a force push on a PR | |
| # cancels running CI jobs and starts all new ones. | |
| # | |
| # For non-PR pushes, concurrency.group needs to be unique for every distinct | |
| # CI run we want to have happen. Use run_id, which in practice means all | |
| # non-PR CI runs will be allowed to run without preempting each other. | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| runs-on: self-hosted | |
| strategy: | |
| matrix: | |
| go-version: ["1.26.5"] | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| persist-credentials: false | |
| - name: Setup Go | |
| uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| - name: Install dependencies | |
| run: go mod download | |
| - name: Unit and Integration test | |
| env: | |
| CL_INFOCLACE_SSH: ${{ secrets.CL_INFOCLACE_SSH }} | |
| CL_GITHUB_SECRET: ${{ secrets.CL_GITHUB_SECRET }} | |
| TEST_PAT: ${{ secrets.TEST_PAT }} | |
| run: | | |
| export OPENRUN_HOME=`pwd` | |
| rm -rf internal/server/appspecs && cd internal/server | |
| git clone --single-branch --depth 1 https://github.com/openrundev/appspecs.git | |
| rm -rf appspecs/.git | |
| cd $OPENRUN_HOME | |
| go install github.com/commander-cli/commander/v2/cmd/commander@v2.5.0 | |
| # Using a self-hosted runner, use Docker for container tests | |
| MAKE_TEST_ARGS=(CONTAINER_COMMANDS=docker POSTGRES=1 MYSQL=1) | |
| RUN_KUBERNETES_TESTS=false | |
| if [[ "${{ inputs.enable_kubernetes_tests }}" == "true" ]]; then | |
| RUN_KUBERNETES_TESTS=true | |
| elif [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| BASE="${{ github.event.pull_request.base.sha }}" | |
| HEAD="${{ github.event.pull_request.head.sha }}" | |
| if git diff --name-only "$BASE" "$HEAD" | grep -q '^internal/container/'; then | |
| RUN_KUBERNETES_TESTS=true | |
| fi | |
| elif [[ "${{ github.event_name }}" != "workflow_call" ]]; then | |
| BASE="${{ github.event.before }}" | |
| HEAD="${{ github.sha }}" | |
| if git diff --name-only "$BASE" "$HEAD" | grep -q '^internal/container/'; then | |
| RUN_KUBERNETES_TESTS=true | |
| fi | |
| fi | |
| if [[ "$RUN_KUBERNETES_TESTS" == "true" ]]; then | |
| # Container package changed, run Kubernetes tests | |
| sudo systemctl restart k3s | |
| kubectl delete namespace openrun --ignore-not-found=true --wait=true | |
| kubectl create namespace openrun | |
| kubectl delete namespace openrun-apps --ignore-not-found=true --wait=true | |
| kubectl create namespace openrun-apps | |
| echo "----------Kubernetes tests enabled------------" | |
| MAKE_TEST_ARGS+=(KUBE_REGISTRY=registry.registry.svc.cluster.local:5000) | |
| else | |
| echo "**********Kubernetes tests skipped************" | |
| fi | |
| docker system prune -f | |
| gmake covtest "${MAKE_TEST_ARGS[@]}" | |
| if [[ -n "$(docker ps -a -q)" ]]; then | |
| docker stop -t 1 $(docker ps -a -q) | |
| fi | |
| docker system prune -f | |
| - name: Upload Go test results | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | |
| with: | |
| name: Go-results-${{ matrix.go-version }} | |
| path: TestResults-${{ matrix.go-version }}.json | |
| - name: Upload results to Codecov | |
| uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} |