Skip to content

Commit 0b49a22

Browse files
changes for self-hosted runner (#64)
* self-hosted changes * remove venv * remove venv * test main branch * reset workflow branch * add venv, change workflow branch * activate venv before pw:run * remove venv for test * add venv, add pip update * activate pip cache * add pip upgrade to venv * activate venv in cyspress tests * remove venv * test different activation of venv * test without venv * remove condition from setup python * remove venv * install addtional req * remove comp tests * clean up * clean up * clean up * remove "disable_cache" input * fix line change, add cypress_spec, remove pg_ready check * Rename deduplication-id to deduplication_id * use vdelev_selfhosted as main branch and add enable_cache flags * Revert back to main --------- Co-authored-by: Michael Pühringer <[email protected]> Co-authored-by: Michael Puehringer <[email protected]>
1 parent 77f57c2 commit 0b49a22

File tree

3 files changed

+76
-15
lines changed

3 files changed

+76
-15
lines changed

.github/actions/build-node/action.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ inputs:
1515
description: "npm registry"
1616
default: "https://registry.npmjs.org/"
1717
required: true
18+
enable_cache:
19+
description: "enables the yarn cache download and upload"
20+
required: false
21+
default: true
1822
download_yarn_lock:
1923
description: "downloads the node-yarn-lock artifact (only available when build-node was called before)"
2024
required: false
@@ -47,6 +51,10 @@ runs:
4751
- name: Git config
4852
if: inputs.github_ro_token != ''
4953
run: |
54+
if [ -f ~/.gitconfig ]; then
55+
rm ~/.gitconfig
56+
touch ~/.gitconfig
57+
fi
5058
git config --global --replace-all url."https://[email protected]/".insteadOf ssh://[email protected]/
5159
git config --add --global url."https://[email protected]/".insteadOf [email protected]:
5260
env:
@@ -60,6 +68,7 @@ runs:
6068
# Enable yarn download cache, @see https://github.com/actions/cache/tree/main/save#always-save-cache and https://github.com/actions/setup-node/issues/325
6169
- name: Restore yarn cache
6270
uses: actions/cache/restore@v3
71+
if: inputs.enable_cache == 'true'
6372
with:
6473
# This path is the global yarn cache, because for some reason the local .yarn/cache is not used. Maybe we need to set the cacheFolder, enableGlobalCache, ... options differently? @see https://yarnpkg.com/configuration/yarnrc#cacheFolder
6574
path: ~/.yarn/berry/cache/
@@ -72,7 +81,7 @@ runs:
7281
shell: bash
7382
- name: Save yarn cache
7483
uses: actions/cache/save@v3
75-
if: steps.install.outcome == 'success'
84+
if: steps.install.outcome == 'success' && inputs.enable_cache == 'true'
7685
with:
7786
# This path is the global yarn cache, because for some reason the local .yarn/cache is not used. Maybe we need to set the cacheFolder, enableGlobalCache, ... options differently? @see https://yarnpkg.com/configuration/yarnrc#cacheFolder
7887
path: ~/.yarn/berry/cache/

.github/actions/build-python/action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ inputs:
1111
description: "github read-only token"
1212
default: "admin"
1313
required: true
14+
enable_cache:
15+
description: "enables the pip cache download and upload"
16+
required: false
17+
default: true
1418
run_lint:
1519
default: true
1620
required: false
@@ -25,10 +29,10 @@ runs:
2529
using: "composite"
2630
steps:
2731
- name: Set up python
28-
uses: actions/setup-python@v3
32+
uses: actions/setup-python@v5
2933
with:
3034
python-version: ${{ inputs.python_version }}
31-
cache: 'pip'
35+
cache: ${{ inputs.enable_cache == 'true' && 'pip' || null }}
3236
# needs wheel for make
3337
- name: install additional requirements
3438
run: |

.github/workflows/build-node-python.yml

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ on:
6666
type: string
6767
required: false
6868
default: "ubuntu-22.04-large"
69+
deduplication_id:
70+
type: string
71+
required: false
72+
description: Unique id per workflow run. Must be set to unique value if dispatched multiple times for a single workflow.
73+
default: ""
6974
chromatic_enable:
7075
description: 'Enable Chromatic Tests'
7176
required: false
@@ -92,6 +97,7 @@ env:
9297
PYPI_USERNAME: "datavisyn"
9398
PYTHON_VERSION: "3.10"
9499
WORKFLOW_BRANCH: "main"
100+
POSTGRES_HOSTNAME: postgres_${{ github.job }}_${{ inputs.deduplication_id }}_${{ github.run_id }}_${{ github.run_attempt }}
95101

96102
permissions:
97103
contents: write
@@ -112,13 +118,13 @@ jobs:
112118
runs-on: ${{ inputs.runs_on }}
113119
steps:
114120
- name: Checkout source repository
115-
uses: actions/checkout@v3
121+
uses: actions/checkout@v4
116122
with:
117123
ref: ${{ inputs.branch }}
118124
token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
119125
fetch-depth: ${{ inputs.chromatic_enable && '0' || '1' }}
120126
- name: Checkout github-workflows
121-
uses: actions/checkout@v3
127+
uses: actions/checkout@v4
122128
with:
123129
repository: datavisyn/github-workflows
124130
ref: ${{ env.WORKFLOW_BRANCH }}
@@ -130,6 +136,7 @@ jobs:
130136
npm_registry: ${{ env.NPM_REGISTRY }}
131137
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
132138
run_webpack: ${{ inputs.node_run_webpack }}
139+
enable_cache: ${{ inputs.runs_on != 'self-hosted' }}
133140
- name: Run Chromatic
134141
if: ${{ inputs.chromatic_enable }}
135142
uses: chromaui/[email protected]
@@ -145,12 +152,12 @@ jobs:
145152
runs-on: ${{ inputs.runs_on }}
146153
steps:
147154
- name: Checkout source repository
148-
uses: actions/checkout@v3
155+
uses: actions/checkout@v4
149156
with:
150157
ref: ${{ inputs.branch }}
151158
token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
152159
- name: Checkout github-workflows
153-
uses: actions/checkout@v3
160+
uses: actions/checkout@v4
154161
with:
155162
repository: datavisyn/github-workflows
156163
ref: ${{ env.WORKFLOW_BRANCH }}
@@ -160,6 +167,7 @@ jobs:
160167
with:
161168
python_version: ${{ secrets.PYTHON_VERSION || env.PYTHON_VERSION }}
162169
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
170+
enable_cache: ${{ inputs.runs_on != 'self-hosted' }}
163171

164172
# If cypress is used, build node and python sequentially as it is avoiding the duplicate install overhead
165173
build-node-python-cypress:
@@ -185,17 +193,34 @@ jobs:
185193
--health-interval 10s
186194
--health-timeout 5s
187195
--health-retries 5
196+
--name postgres_${{ github.job }}_${{ inputs.deduplication_id }}_${{ github.run_id }}_${{ github.run_attempt }}
188197
ports:
189-
- 5432:5432
198+
# will assign a random free host port
199+
- 5432/tcp
190200

191201
steps:
202+
- name: Set self-hosted env variable to github env
203+
run: echo "GH_ACTIONS_SELF_HOSTED_NETWORK_NAME=${GH_ACTIONS_SELF_HOSTED_NETWORK_NAME}" >> "$GITHUB_ENV"
204+
- name: Set github token, hostname, port and docker network for self-hosted runner
205+
if: env.GH_ACTIONS_SELF_HOSTED_NETWORK_NAME != ''
206+
run: |
207+
{
208+
echo "POSTGRES_HOSTNAME=postgres_${{ github.job }}_${{ inputs.deduplication_id }}_${{ github.run_id }}_${{ github.run_attempt }}"
209+
echo "POSTGRES_PORT=5432"
210+
} >> "$GITHUB_ENV"
211+
docker network connect ${{ env.GH_ACTIONS_SELF_HOSTED_NETWORK_NAME }} "postgres_${{ github.job }}_${{ inputs.deduplication_id }}_${{ github.run_id }}_${{ github.run_attempt }}"
212+
- name: Set postgres connection details to hosted runner
213+
if: env.GH_ACTIONS_SELF_HOSTED_NETWORK_NAME == ''
214+
run: |
215+
echo "POSTGRES_HOSTNAME=localhost" >> "$GITHUB_ENV"
216+
echo "POSTGRES_PORT=${{ job.services.postgres.ports['5432'] }}" >> "$GITHUB_ENV"
192217
- name: Checkout source repository
193-
uses: actions/checkout@v3
218+
uses: actions/checkout@v4
194219
with:
195220
ref: ${{ inputs.branch }}
196221
token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
197222
- name: Checkout github-workflows
198-
uses: actions/checkout@v3
223+
uses: actions/checkout@v4
199224
with:
200225
repository: datavisyn/github-workflows
201226
ref: ${{ env.WORKFLOW_BRANCH }}
@@ -207,11 +232,13 @@ jobs:
207232
npm_registry: ${{ env.NPM_REGISTRY }}
208233
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
209234
run_webpack: false # Disable the build here and call afterwards, as otherwise the yarn run env:decrypt will fail due to a missing yarn install
235+
enable_cache: ${{ inputs.cypress_runs_on != 'self-hosted' && inputs.runs_on != 'self-hosted' }}
210236
- name: Build python
211237
uses: ./tmp/github-workflows/.github/actions/build-python
212238
with:
213239
python_version: ${{ secrets.PYTHON_VERSION || env.PYTHON_VERSION }}
214240
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
241+
enable_cache: ${{ inputs.cypress_runs_on != 'self-hosted' && inputs.runs_on != 'self-hosted' }}
215242
- name: Decrypt .env.enc and <app>/.env.enc
216243
run: |
217244
yarn run env:decrypt -pass env:ENV_PASSWORD || true
@@ -233,8 +260,10 @@ jobs:
233260
yarn start dev_server_only=true
234261
make start
235262
wait-on: "http://localhost:8080, http://localhost:9000/health"
236-
env: ${{ secrets.CYPRESS_ENV }}
237263
spec: ${{ inputs.cypress_spec_param }}
264+
env:
265+
POSTGRES_HOSTNAME: ${{ env.POSTGRES_HOSTNAME }}
266+
POSTGRES_PORT: ${{ env.POSTGRES_PORT }}
238267
# rspack currently does not support Cypress component tests
239268
# - name: Run cypress component tests
240269
# uses: cypress-io/github-action@v6
@@ -247,7 +276,7 @@ jobs:
247276
# # TODO: Do component tests need the frontend/backend?
248277
# env: ${{ secrets.CYPRESS_ENV }}
249278
- name: Upload cypress screenshots
250-
uses: actions/upload-artifact@v4
279+
uses: actions/upload-artifact@v3
251280
if: failure()
252281
with:
253282
name: cypress-screenshots
@@ -283,17 +312,34 @@ jobs:
283312
--health-interval 10s
284313
--health-timeout 5s
285314
--health-retries 5
315+
--name postgres_${{ github.job }}_${{ inputs.deduplication_id }}_${{ github.run_id }}_${{ github.run_attempt }}
286316
ports:
287-
- 5432:5432
317+
# will assign a random free host port
318+
- 5432/tcp
288319

289320
steps:
321+
- name: Set system env variable to github env
322+
run: echo "GH_ACTIONS_SELF_HOSTED_NETWORK_NAME=${GH_ACTIONS_SELF_HOSTED_NETWORK_NAME}" >> "$GITHUB_ENV"
323+
- name: Set github token, hostname, port and docker network for self-hosted runner
324+
if: env.GH_ACTIONS_SELF_HOSTED_NETWORK_NAME != ''
325+
run: |
326+
{
327+
echo "POSTGRES_HOSTNAME=postgres_${{ github.job }}_${{ inputs.deduplication_id }}_${{ github.run_id }}_${{ github.run_attempt }}"
328+
echo "POSTGRES_PORT=5432"
329+
} >> "$GITHUB_ENV"
330+
docker network connect ${{ env.GH_ACTIONS_SELF_HOSTED_NETWORK_NAME }} ${{ env.POSTGRES_HOSTNAME }}
331+
- name: Set postgres connection details to hosted runner
332+
if: env.GH_ACTIONS_SELF_HOSTED_NETWORK_NAME == ''
333+
run: |
334+
echo "POSTGRES_HOSTNAME=localhost" >> "$GITHUB_ENV"
335+
echo "POSTGRES_PORT=${{ job.services.postgres.ports['5432'] }}" >> "$GITHUB_ENV"
290336
- name: Checkout source repository
291-
uses: actions/checkout@v3
337+
uses: actions/checkout@v4
292338
with:
293339
ref: ${{ inputs.branch }}
294340
token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
295341
- name: Checkout github-workflows
296-
uses: actions/checkout@v3
342+
uses: actions/checkout@v4
297343
with:
298344
repository: datavisyn/github-workflows
299345
ref: ${{ env.WORKFLOW_BRANCH }}
@@ -305,11 +351,13 @@ jobs:
305351
npm_registry: ${{ env.NPM_REGISTRY }}
306352
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
307353
run_webpack: false # Disable the build here and call afterwards, as otherwise the yarn run env:decrypt will fail due to a missing yarn install
354+
enable_cache: ${{ inputs.playwright_runs_on != 'self-hosted' && inputs.runs_on != 'self-hosted' }}
308355
- name: Build python
309356
uses: ./tmp/github-workflows/.github/actions/build-python
310357
with:
311358
python_version: ${{ secrets.PYTHON_VERSION || env.PYTHON_VERSION }}
312359
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
360+
enable_cache: ${{ inputs.playwright_runs_on != 'self-hosted' && inputs.runs_on != 'self-hosted' }}
313361
- name: Decrypt .env.enc and <app>/.env.enc
314362
run: |
315363
yarn run env:decrypt -pass env:ENV_PASSWORD || true

0 commit comments

Comments
 (0)