-
Notifications
You must be signed in to change notification settings - Fork 32
145 lines (132 loc) · 5.27 KB
/
Copy pathtest.yml
File metadata and controls
145 lines (132 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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
enable_dr_tests:
description: "Also run the docker and kubernetes disaster recovery scenarios"
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:
- name: Prepare workspace
# Containerized test steps can leave root-owned files in the workspace.
# actions/checkout cannot delete those when it recreates the workspace,
# and the resulting half-deleted directory breaks every later run
# ("fatal: --local can only be used inside a git repository").
run: |
sudo chown -R "$(id -u):$(id -g)" "$GITHUB_WORKSPACE"
if [ ! -e "$GITHUB_WORKSPACE/.git/HEAD" ]; then
find "$GITHUB_WORKSPACE" -mindepth 1 -delete
fi
- 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 REDIS=1 SEAWEEDFS=1)
if [[ "${{ inputs.enable_dr_tests }}" == "true" ]]; then
# Run the docker and kubernetes disaster recovery scenarios too
# (the kubernetes one needs enable_kubernetes_tests as well)
MAKE_TEST_ARGS+=(DR=1)
fi
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 }}