Skip to content

Commit 58b3d60

Browse files
authored
[tests] Move workspace integration tests to Github Actions (#16872)
* [tests] move Workspace Tests to Github Actions * [tests] convert secrets to core dev Example: https://github.com/gitpod-io/gitpod/blob/85cf0750086a0b7fa4836254864391304a0198d2/.github/workflows/build.yml#L204-L212 Source of truth for secrets: https://console.cloud.google.com/security/secret-manager?project=gitpod-core-dev
1 parent 44ecb14 commit 58b3d60

File tree

1 file changed

+181
-0
lines changed

1 file changed

+181
-0
lines changed
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
name: "Workspace integration tests"
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
name:
6+
required: true
7+
description: "The name of the preview environment"
8+
version:
9+
required: true
10+
description: "The version of Gitpod to install"
11+
skip_deploy:
12+
required: false
13+
type: boolean
14+
description: "Skip deploy preview environment (debug only)"
15+
skip_delete:
16+
required: false
17+
type: boolean
18+
description: "Skip delete preview environment (debug only)"
19+
schedule:
20+
- cron: "0 3 * * *"
21+
jobs:
22+
configuration:
23+
name: Configuration
24+
runs-on: [self-hosted]
25+
container:
26+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:kylos101-kubecdl-home.1
27+
outputs:
28+
name: ${{ steps.configuration.outputs.name }}
29+
version: ${{ steps.configuration.outputs.version }}
30+
steps:
31+
- name: "Set outputs"
32+
id: configuration
33+
shell: bash
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
run: |
37+
if [[ '${{ github.event.inputs.name }}' != '' && '${{ github.event.inputs.name }}' != 'latest' ]]; then
38+
# The workflow was triggered by workflow_dispatch
39+
{
40+
echo "version=${{ github.event.inputs.version }}"
41+
echo "name=${{ github.event.inputs.name }}"
42+
} >> $GITHUB_OUTPUT
43+
else
44+
# others
45+
RUNID=$(gh run list -R gitpod-io/gitpod -b main -w Build --limit 1 --json databaseId --jq .[0].databaseId)
46+
if ! gh run watch "$RUNID" --exit-status -R gitpod-io/gitpod >/dev/null 2>&1; then
47+
echo main branch build is failed, see https://github.com/gitpod-io/gitpod/actions/runs/"$RUNID" for detail | tee -a $GITHUB_STEP_SUMMARY
48+
exit 1
49+
fi
50+
51+
{
52+
echo "version=$(gh run view "$RUNID" --log -R gitpod-io/gitpod | grep 'main-gha.[0-9]*' -o | head -n 1)"
53+
echo "name=workspace-integration-test-${{ github.run_id }}-${{ github.run_attempt }}"
54+
} >> $GITHUB_OUTPUT
55+
fi
56+
- name: Get Secrets from GCP
57+
id: 'secrets'
58+
uses: 'google-github-actions/get-secretmanager-secrets@v1'
59+
with:
60+
secrets: |-
61+
WORKSPACE_SLACK_WEBHOOK:gitpod-core-dev/workspace-slack-webhook
62+
- name: Slack Notification
63+
uses: rtCamp/action-slack-notify@v2
64+
if: failure()
65+
env:
66+
SLACK_WEBHOOK: ${{ steps.secrets.outputs.WORKSPACE_SLACK_WEBHOOK }}
67+
SLACK_COLOR: ${{ job.status }}
68+
SLACK_MESSAGE: main branch build failed
69+
check:
70+
name: Check for regressions
71+
needs: [configuration]
72+
runs-on: [self-hosted]
73+
container:
74+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:kylos101-kubecdl-home.1
75+
steps:
76+
- uses: actions/checkout@v3
77+
- name: Create preview environment infrastructure
78+
uses: ./.github/actions/preview-create
79+
with:
80+
name: ${{ needs.configuration.outputs.name }}
81+
infrastructure_provider: harvester
82+
large_vm: true
83+
sa_key: ${{ secrets.GCP_CREDENTIALS }}
84+
- name: Deploy Gitpod to the preview environment
85+
if: github.event.inputs.skip_deploy != 'true'
86+
id: deploy-gitpod
87+
uses: ./.github/actions/deploy-gitpod
88+
with:
89+
name: ${{ needs.configuration.outputs.name }}
90+
sa_key: ${{ secrets.GCP_CREDENTIALS }}
91+
version: ${{ needs.configuration.outputs.version}}
92+
- name: Get Secrets from GCP
93+
id: 'secrets'
94+
uses: 'google-github-actions/get-secretmanager-secrets@v1'
95+
with:
96+
secrets: |-
97+
WORKSPACE_SLACK_WEBHOOK:gitpod-core-dev/workspace-slack-webhook
98+
WORKSPACE_INTEGRATION_TEST_USERNAME:gitpod-core-dev/workspace-integration-test-username
99+
WORKSPACE_INTEGRATION_TEST_USER_TOKEN:gitpod-core-dev/workspace-integration-test-user-token
100+
- name: Integration Test
101+
shell: bash
102+
env:
103+
ROBOQUAT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104+
USERNAME: ${{ steps.secrets.outputs.WORKSPACE_INTEGRATION_TEST_USERNAME }}
105+
USER_TOKEN: ${{ steps.secrets.outputs.WORKSPACE_INTEGRATION_TEST_USER_TOKEN }}
106+
PREVIEW_ENV_DEV_SA_KEY: ${{ secrets.GCP_CREDENTIALS }}
107+
PREVIEW_NAME: ${{ needs.configuration.outputs.name }}
108+
run: |
109+
set -euo pipefail
110+
111+
export LEEWAY_WORKSPACE_ROOT="$(pwd)"
112+
export HOME="/home/gitpod"
113+
export PREVIEW_ENV_DEV_SA_KEY_PATH="/home/gitpod/.config/gcloud/preview-environment-dev-sa.json"
114+
115+
echo "${PREVIEW_ENV_DEV_SA_KEY}" > "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
116+
gcloud auth activate-service-account --key-file "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
117+
118+
leeway run dev/preview/previewctl:install
119+
120+
echo "Setting up access to core-dev and harvester"
121+
previewctl get-credentials --gcp-service-account "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
122+
123+
previewctl install-context --branch "${PREVIEW_NAME}" --log-level debug --timeout 1m --gcp-service-account "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
124+
125+
# start integration test
126+
args=()
127+
args+=( "-kubeconfig=/home/gitpod/.kube/config" )
128+
args+=( "-namespace=default" )
129+
[[ "$USERNAME" != "" ]] && args+=( "-username=$USERNAME" )
130+
args+=( "-timeout=60m" )
131+
132+
BASE_TESTS_DIR="$GITHUB_WORKSPACE/test/tests"
133+
CONTENT_SERVICE_TESTS="$BASE_TESTS_DIR/components/content-service"
134+
IMAGE_BUILDER_TESTS="$BASE_TESTS_DIR/components/image-builder"
135+
DATABASE_TESTS="$BASE_TESTS_DIR/components/database"
136+
SERVER_TESTS="$BASE_TESTS_DIR/components/server"
137+
WS_DAEMON_TESTS="$BASE_TESTS_DIR/components/ws-daemon"
138+
WS_MANAGER_TESTS="$BASE_TESTS_DIR/components/ws-manager"
139+
WORKSPACE_TESTS="$BASE_TESTS_DIR/components/workspace"
140+
141+
go install github.com/jstemmer/go-junit-report/v2@latest
142+
143+
FAILURE_COUNT=0
144+
145+
WORKSPACE_TEST_LIST=("$CONTENT_SERVICE_TESTS" "$IMAGE_BUILDER_TESTS" "$DATABASE_TESTS" "$SERVER_TESTS" "$WS_DAEMON_TESTS" "$WS_MANAGER_TESTS" "$WORKSPACE_TESTS")
146+
for TEST_PATH in "${WORKSPACE_TEST_LIST[@]}"
147+
do
148+
TEST_NAME=$(basename "${TEST_PATH}")
149+
echo "running integration for ${TEST_NAME}"
150+
151+
cd "${TEST_PATH}"
152+
set +e
153+
go test -v ./... "${args[@]}" 2>&1 | go-junit-report -subtest-mode=exclude-parents -set-exit-code -out "TEST-${TEST_NAME}.xml" -iocopy
154+
RC=${PIPESTATUS[0]}
155+
set -e
156+
157+
if [ "${RC}" -ne "0" ]; then
158+
FAILURE_COUNT=$((FAILURE_COUNT+1))
159+
fi
160+
done
161+
162+
exit $FAILURE_COUNT
163+
- name: Test Summary
164+
id: test_summary
165+
uses: test-summary/action@v2
166+
with:
167+
paths: "test/tests/**/TEST-*.xml"
168+
if: always()
169+
- name: Slack Notification
170+
uses: rtCamp/action-slack-notify@v2
171+
if: success() || failure()
172+
env:
173+
SLACK_WEBHOOK: ${{ steps.secrets.outputs.WORKSPACE_SLACK_WEBHOOK }}
174+
SLACK_COLOR: ${{ job.status }}
175+
SLACK_MESSAGE: ${{ steps.test_summary.outputs.passed }}/${{ steps.test_summary.outputs.total }} tests passed
176+
- name: Delete preview environment
177+
if: github.event.inputs.skip_delete != 'true' && (success() || failure())
178+
uses: ./.github/actions/delete-preview
179+
with:
180+
name: ${{ needs.configuration.outputs.name }}
181+
sa_key: ${{ secrets.GCP_CREDENTIALS }}

0 commit comments

Comments
 (0)