Skip to content

Commit 0bc2a7a

Browse files
authored
Change gh event to pull_request_target and runner to GCE (#18217)
* Change gh event to pull_request_target * Update sef-hosted runner * Configure GCP auth * Cleanup * gcloud auth activate-service-account * Use generated file * Configure GH PAT * Add cleanup job * doh * Validate the GCP VM was created * Cleanup * Rollback * Change repository * Clone repository * Cleanup * Cleanup * Revert pull_request_target * Fix integration tests * Add missing needs * 1 * CLEANUP
1 parent 66049b3 commit 0bc2a7a

14 files changed

+685
-552
lines changed

.github/workflows/authorization.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
on:
22
pull_request:
33
paths:
4-
- install/installer/pkg/components/spicedb/data/**
5-
- .github/workflows/authorization.yml
4+
- install/installer/pkg/components/spicedb/data/**
5+
- .github/workflows/authorization.yml
6+
67
name: SpiceDB
8+
79
jobs:
810
scan-repo:
911
runs-on: ubuntu-latest
1012
name: Validate schema
1113
steps:
12-
- name: Checkout
13-
uses: actions/checkout@v2
14-
- name: Validate SpiceDB schema
15-
uses: authzed/[email protected]
16-
with:
17-
validationfile: "install/installer/pkg/components/spicedb/data/schema.yaml"
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
- name: Validate SpiceDB schema
17+
uses: authzed/[email protected]
18+
with:
19+
validationfile: "install/installer/pkg/components/spicedb/data/schema.yaml"

.github/workflows/build.yml

Lines changed: 93 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Build
22
on:
33
pull_request:
4-
types: [ opened, edited ]
4+
types: [opened, edited]
55
push:
66
workflow_dispatch:
77
inputs:
@@ -12,9 +12,14 @@ on:
1212
default: "false"
1313

1414
jobs:
15+
create-runner:
16+
uses: ./.github/workflows/create_runner.yml
17+
secrets: inherit
18+
1519
configuration:
1620
name: Configure job parameters
17-
runs-on: [ self-hosted ]
21+
runs-on: ${{ needs.create-runner.outputs.label }}
22+
needs: [create-runner]
1823
concurrency:
1924
# github.head_ref is set by a pull_request event - contains the name of the source branch of the PR
2025
# github.ref_name is set if the event is NOT a pull_request - it contains only the branch name.
@@ -55,17 +60,18 @@ jobs:
5560
id: pr-diff
5661
if: (github.event_name == 'pull_request' && github.event.action == 'edited')
5762
env:
58-
PR_DESC: '${{ steps.pr-details.outputs.pr_body }}'
59-
OLD_BODY: '${{ github.event.changes.body.from }}'
63+
PR_DESC: "${{ steps.pr-details.outputs.pr_body }}"
64+
OLD_BODY: "${{ github.event.changes.body.from }}"
6065
run: |
6166
if ! diff <(echo "$OLD_BODY") <(echo "$PR_DESC") | grep -e '\[x\]' -e '\[X\]'; then
6267
echo "pr_no_diff_skip=true" >> $GITHUB_OUTPUT
6368
fi
6469
- name: "Set outputs"
6570
id: output
6671
env:
67-
PR_DESC: '${{ steps.pr-details.outputs.pr_body }}'
72+
PR_DESC: "${{ steps.pr-details.outputs.pr_body }}"
6873
MAIN_BRANCH: ${{ (github.head_ref || github.ref) == 'refs/heads/main' }}
74+
LEEWAY_WORKSPACE_ROOT: ${{ env.GITHUB_WORKSPACE }}
6975
shell: bash
7076
run: |
7177
{
@@ -80,48 +86,39 @@ jobs:
8086
if: |
8187
(needs.configuration.outputs.pr_no_diff_skip != 'true') &&
8288
(needs.configuration.outputs.preview_enable == 'true')
83-
needs: [ configuration ]
89+
needs: [configuration, create-runner]
8490
concurrency:
8591
group: ${{ github.workflow }}-${{ github.ref }}-build-previewctl
86-
runs-on: [ self-hosted ]
92+
runs-on: ${{ needs.create-runner.outputs.label }}
8793
container:
8894
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:cw-bump-leeway-075-gha.12686
89-
volumes:
90-
- /var/tmp:/var/tmp
91-
- /tmp:/tmp
9295
outputs:
9396
previewctl_hash: ${{ steps.build.outputs.previewctl_hash }}
9497
steps:
9598
- uses: actions/checkout@v3
96-
- name: Configure workspace
97-
run: |
98-
sudo chown -R gitpod:gitpod /__t
99-
# Needed by docker/login-action
100-
sudo chmod goa+rw /var/run/docker.sock
10199
- name: Build previewctl
102100
id: build
103101
shell: bash
104102
env:
105-
HOME: /home/gitpod
106103
PREVIEW_ENV_DEV_SA_KEY: ${{ secrets.GCP_CREDENTIALS }}
107-
LEEWAY_SEGMENT_KEY: '${{ secrets.LEEWAY_SEGMENT_KEY }}'
104+
LEEWAY_SEGMENT_KEY: "${{ secrets.LEEWAY_SEGMENT_KEY }}"
105+
LEEWAY_WORKSPACE_ROOT: ${{ env.GITHUB_WORKSPACE }}
108106
run: |
109107
# Authenticate with GCP so we can use the Leeway cache
110108
export PREVIEW_ENV_DEV_SA_KEY_PATH="$HOME/.config/gcloud/preview-environment-dev-sa.json"
111109
echo "${PREVIEW_ENV_DEV_SA_KEY}" > "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
112110
gcloud auth activate-service-account --key-file "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
113111
114-
export LEEWAY_WORKSPACE_ROOT="$(pwd)"
115112
leeway build dev/preview/previewctl:docker -Dversion="${{needs.configuration.outputs.version}}"
116113
echo "previewctl_hash=$(leeway describe dev/preview/previewctl:docker -Dversion="${{needs.configuration.outputs.version}}" -t '{{ .Metadata.Version }}')" >> $GITHUB_OUTPUT
117114
118115
infrastructure:
119-
needs: [ configuration, build-previewctl ]
116+
needs: [configuration, build-previewctl, create-runner]
120117
if: |
121118
(needs.configuration.outputs.pr_no_diff_skip != 'true') &&
122119
(needs.configuration.outputs.preview_enable == 'true') &&
123120
(needs.configuration.outputs.is_main_branch != 'true')
124-
runs-on: [ self-hosted ]
121+
runs-on: ${{ needs.create-runner.outputs.label }}
125122
concurrency:
126123
group: ${{ github.head_ref || github.ref_name }}-infrastructure
127124
steps:
@@ -139,8 +136,8 @@ jobs:
139136

140137
build-gitpod:
141138
name: Build Gitpod
142-
needs: [ configuration ]
143-
runs-on: [ self-hosted ]
139+
needs: [configuration, create-runner]
140+
runs-on: ${{ needs.create-runner.outputs.label }}
144141
concurrency:
145142
group: ${{ github.head_ref || github.ref_name }}-build-gitpod
146143
# For the main branch we always want the build job to run to completion
@@ -155,22 +152,11 @@ jobs:
155152
- 23306:23306
156153
container:
157154
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:cw-bump-leeway-075-gha.12686
158-
volumes:
159-
- /var/tmp/${{ needs.configuration.outputs.leeway_cache_bucket }}:/var/tmp
160-
- /tmp:/tmp
161155
env:
162156
DB_HOST: "mysql"
163157
DB_PORT: "23306"
164-
LEEWAY_REMOTE_CACHE_BUCKET: '${{ needs.configuration.outputs.leeway_cache_bucket }}'
165158
steps:
166159
- uses: actions/checkout@v3
167-
- name: Configure workspace
168-
run: |
169-
cp -r /__w/gitpod/gitpod /workspace
170-
# Needed by google-github-actions/setup-gcloud
171-
sudo chown -R gitpod:gitpod /__t
172-
# Needed by docker/login-action
173-
sudo chmod goa+rw /var/run/docker.sock
174160
- id: auth
175161
uses: google-github-actions/auth@v1
176162
with:
@@ -185,12 +171,12 @@ jobs:
185171
password: "${{ steps.auth.outputs.access_token }}"
186172
- name: Leeway Vet
187173
shell: bash
188-
working-directory: /workspace/gitpod
189174
run: |
190175
leeway vet --ignore-warnings
176+
env:
177+
LEEWAY_WORKSPACE_ROOT: ${{ env.GITHUB_WORKSPACE }}
191178
- name: Pre-Commit Checks
192179
shell: bash
193-
working-directory: /workspace/gitpod
194180
run: |
195181
RESULT=0
196182
pre-commit run --show-diff-on-failure || RESULT=$?
@@ -200,7 +186,8 @@ jobs:
200186
exit "$RESULT"
201187
- name: Check License Headers
202188
shell: bash
203-
working-directory: /workspace/gitpod
189+
env:
190+
LEEWAY_WORKSPACE_ROOT: ${{ env.GITHUB_WORKSPACE }}
204191
run: |
205192
RESULT=0
206193
LICENCE_HEADER_CHECK_ONLY=true leeway run components:update-license-header || RESULT=$?
@@ -209,8 +196,8 @@ jobs:
209196
fi
210197
exit "$RESULT"
211198
- name: Get Secrets from GCP
212-
id: 'secrets'
213-
uses: 'google-github-actions/get-secretmanager-secrets@v1'
199+
id: "secrets"
200+
uses: "google-github-actions/get-secretmanager-secrets@v1"
214201
with:
215202
secrets: |-
216203
segment-io-token:gitpod-core-dev/segment-io-token
@@ -222,9 +209,9 @@ jobs:
222209
env:
223210
JAVA_HOME: /home/gitpod/.sdkman/candidates/java/current
224211
VERSION: ${{needs.configuration.outputs.version}}
225-
LEEWAY_SEGMENT_KEY: '${{ secrets.LEEWAY_SEGMENT_KEY }}'
212+
LEEWAY_SEGMENT_KEY: "${{ secrets.LEEWAY_SEGMENT_KEY }}"
213+
LEEWAY_WORKSPACE_ROOT: ${{ env.GITHUB_WORKSPACE }}
226214
shell: bash
227-
working-directory: /workspace/gitpod
228215
run: |
229216
RESULT=0
230217
set -x
@@ -249,22 +236,22 @@ jobs:
249236
- name: Leeway Build
250237
id: leeway
251238
shell: bash
252-
working-directory: /workspace/gitpod
253239
env:
254240
DB_HOST: "mysql"
255241
DB_PORT: "23306"
256242
NODE_OPTIONS: "--max_old_space_size=4096"
257243
JAVA_HOME: /home/gitpod/.sdkman/candidates/java/current
258244
VERSION: ${{needs.configuration.outputs.version}}
259-
SEGMENT_IO_TOKEN: '${{ steps.secrets.outputs.segment-io-token }}'
245+
SEGMENT_IO_TOKEN: "${{ steps.secrets.outputs.segment-io-token }}"
260246
PR_NO_CACHE: ${{needs.configuration.outputs.build_no_cache}}
261247
PR_NO_TEST: ${{needs.configuration.outputs.build_no_test}}
262-
NPM_AUTH_TOKEN: '${{ steps.secrets.outputs.npm-auth-token }}'
248+
NPM_AUTH_TOKEN: "${{ steps.secrets.outputs.npm-auth-token }}"
263249
PUBLISH_TO_NPM: ${{ needs.configuration.outputs.publish_to_npm == 'true' || needs.configuration.outputs.is_main_branch == 'true' }}
264-
JB_MARKETPLACE_PUBLISH_TOKEN: '${{ steps.secrets.outputs.jb-marketplace-publish-token }}'
250+
JB_MARKETPLACE_PUBLISH_TOKEN: "${{ steps.secrets.outputs.jb-marketplace-publish-token }}"
265251
PUBLISH_TO_JBPM: ${{ needs.configuration.outputs.publish_to_jbmp == 'true' || needs.configuration.outputs.is_main_branch == 'true' }}
266-
CODECOV_TOKEN: '${{ steps.secrets.outputs.codecov-token }}'
267-
LEEWAY_SEGMENT_KEY: '${{ secrets.LEEWAY_SEGMENT_KEY }}'
252+
CODECOV_TOKEN: "${{ steps.secrets.outputs.codecov-token }}"
253+
LEEWAY_SEGMENT_KEY: "${{ secrets.LEEWAY_SEGMENT_KEY }}"
254+
LEEWAY_WORKSPACE_ROOT: ${{ env.GITHUB_WORKSPACE }}
268255
run: |
269256
[[ "$PR_NO_CACHE" = "true" ]] && CACHE="none" || CACHE="remote"
270257
[[ "$PR_NO_TEST" = "true" ]] && TEST="--dont-test" || TEST=""
@@ -301,8 +288,8 @@ jobs:
301288
test-coverage-report
302289
303290
install-app:
304-
runs-on: ubuntu-latest
305-
needs: [ configuration, build-gitpod ]
291+
runs-on: ${{ needs.create-runner.outputs.label }}
292+
needs: [configuration, build-gitpod, create-runner]
306293
if: ${{ needs.configuration.outputs.is_main_branch == 'true' }}
307294
steps:
308295
- uses: gitpod-io/[email protected]
@@ -328,8 +315,15 @@ jobs:
328315
329316
install:
330317
name: "Install Gitpod"
331-
needs: [ configuration, build-previewctl, build-gitpod, infrastructure ]
332-
runs-on: [ self-hosted ]
318+
needs:
319+
[
320+
configuration,
321+
build-previewctl,
322+
build-gitpod,
323+
infrastructure,
324+
create-runner,
325+
]
326+
runs-on: ${{ needs.create-runner.outputs.label }}
333327
concurrency:
334328
group: ${{ github.workflow }}-${{ github.ref }}-install
335329
steps:
@@ -371,8 +365,8 @@ jobs:
371365
372366
monitoring:
373367
name: "Install Monitoring Satellite"
374-
needs: [ infrastructure, build-previewctl ]
375-
runs-on: [ self-hosted ]
368+
needs: [infrastructure, build-previewctl, create-runner]
369+
runs-on: ${{ needs.create-runner.outputs.label }}
376370
concurrency:
377371
group: ${{ github.workflow }}-${{ github.ref }}-monitoring
378372
steps:
@@ -386,13 +380,18 @@ jobs:
386380

387381
integration-test:
388382
name: "Run integration test"
389-
needs: [ configuration, build-previewctl, build-gitpod, infrastructure, install ]
390-
runs-on: [ self-hosted ]
383+
needs:
384+
[
385+
configuration,
386+
build-previewctl,
387+
build-gitpod,
388+
infrastructure,
389+
install,
390+
create-runner,
391+
]
392+
runs-on: ${{ needs.create-runner.outputs.label }}
391393
container:
392-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:cw-bump-leeway-075-gha.12686
393-
volumes:
394-
- /var/tmp:/var/tmp
395-
- /tmp:/tmp
394+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:cw-bump-leeway-075-gha.12686
396395
if: needs.configuration.outputs.with_integration_tests != ''
397396
concurrency:
398397
group: ${{ github.workflow }}-${{ github.ref }}-integration-test
@@ -401,31 +400,46 @@ jobs:
401400
- name: Run integration test
402401
shell: bash
403402
env:
404-
ROBOQUAT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
405-
INTEGRATION_TEST_USERNAME: ${{ secrets.IDE_INTEGRATION_TEST_USERNAME }}
406-
INTEGRATION_TEST_USER_TOKEN: ${{ secrets.IDE_INTEGRATION_TEST_USER_TOKEN }}
407-
PREVIEW_ENV_DEV_SA_KEY: ${{ secrets.GCP_CREDENTIALS }}
408-
PREVIEW_NAME: ${{ github.head_ref || github.ref_name }}
409-
TEST_SUITS: ${{ needs.configuration.outputs.with_integration_tests }}
410-
TEST_USE_LATEST_VERSION: ${{ needs.configuration.outputs.latest_ide_version }}
411-
TEST_BUILD_ID: ${{ github.run_id }}
412-
TEST_BUILD_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
413-
TEST_BUILD_REF: ${{ github.head_ref || github.ref }}
403+
ROBOQUAT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
404+
INTEGRATION_TEST_USERNAME: ${{ secrets.IDE_INTEGRATION_TEST_USERNAME }}
405+
INTEGRATION_TEST_USER_TOKEN: ${{ secrets.IDE_INTEGRATION_TEST_USER_TOKEN }}
406+
PREVIEW_ENV_DEV_SA_KEY: ${{ secrets.GCP_CREDENTIALS }}
407+
PREVIEW_NAME: ${{ github.head_ref || github.ref_name }}
408+
TEST_SUITS: ${{ needs.configuration.outputs.with_integration_tests }}
409+
TEST_USE_LATEST_VERSION: ${{ needs.configuration.outputs.latest_ide_version }}
410+
TEST_BUILD_ID: ${{ github.run_id }}
411+
TEST_BUILD_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
412+
TEST_BUILD_REF: ${{ github.head_ref || github.ref }}
413+
PREVIEW_ENV_DEV_SA_KEY_PATH: ${{ env.GITHUB_WORKSPACE }}"/.config/gcloud/preview-environment-dev-sa.json"
414+
LEEWAY_WORKSPACE_ROOT: ${{ env.GITHUB_WORKSPACE }}
414415
run: |
415-
set -euo pipefail
416+
set -euo pipefail
416417
417-
export LEEWAY_WORKSPACE_ROOT="$(pwd)"
418-
export HOME="/home/gitpod"
419-
export PREVIEW_ENV_DEV_SA_KEY_PATH="/home/gitpod/.config/gcloud/preview-environment-dev-sa.json"
418+
echo "${PREVIEW_ENV_DEV_SA_KEY}" > "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
419+
gcloud auth activate-service-account --key-file "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
420420
421-
echo "${PREVIEW_ENV_DEV_SA_KEY}" > "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
422-
gcloud auth activate-service-account --key-file "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
421+
leeway run dev/preview/previewctl:install
423422
424-
leeway run dev/preview/previewctl:install
423+
echo "Setting up access to core-dev and harvester"
424+
previewctl get-credentials --gcp-service-account "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
425425
426-
echo "Setting up access to core-dev and harvester"
427-
previewctl get-credentials --gcp-service-account "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
426+
previewctl install-context --branch "${PREVIEW_NAME}" --log-level debug --timeout 1m --gcp-service-account "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
428427
429-
previewctl install-context --branch "${PREVIEW_NAME}" --log-level debug --timeout 1m --gcp-service-account "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
428+
$GITHUB_WORKSPACE/test/run.sh -s ${TEST_SUITS}
430429
431-
$GITHUB_WORKSPACE/test/run.sh -s ${TEST_SUITS}
430+
delete-runner:
431+
if: always()
432+
needs:
433+
- create-runner
434+
- configuration
435+
- build-previewctl
436+
- infrastructure
437+
- build-gitpod
438+
- install-app
439+
- install
440+
- monitoring
441+
- integration-test
442+
uses: ./.github/workflows/remove_runner.yml
443+
secrets: inherit
444+
with:
445+
runner-label: ${{ needs.create-runner.outputs.label }}

0 commit comments

Comments
 (0)