Skip to content

Commit 84604a2

Browse files
committed
Adjust access to env variables for GH workflows
1 parent 3d03ebd commit 84604a2

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

.github/workflows/release.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
name: Create Release
1+
name: Test and Create Release
22

33
on:
44
push:
5-
tags:
6-
- 'v*'
7-
# Allows you to run this workflow manually from the Actions tab
85
workflow_dispatch:
96

107
env:
11-
DATA_DIR: cypress/yaml
8+
DATA_DIR: 'cypress/yaml'
129
CYPRESS_BASE_URL: "http://localhost:8181"
1310

1411
jobs:
@@ -25,6 +22,14 @@ jobs:
2522
node-version: 23
2623
- run: npm ci
2724
- run: npm run build --if-present
25+
- name: PHP env check
26+
run: |
27+
php -r '
28+
$edd = $_ENV["DATA_DIR"] ?? "--nonexistent--";
29+
$gdd = getenv("DATA_DIR") ?? "--nonexistent--";
30+
echo "S_ENV variable DATA_DIR is: " . $edd . "\n";
31+
echo "getenv variable DATA_DIR is:" . $gdd . "\n";
32+
'
2833
- name: Cypress run
2934
uses: cypress-io/github-action@v6
3035
with:

app/settings.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
}
1616

1717
// finally merge from environment
18-
if (!empty($_ENV['DATA_DIR'])) {
19-
$settings['settings']['dataDir'] = $_ENV['DATA_DIR'];
18+
// dotenv loads .env files and env variables - in that order
19+
// using getenv() since $_ENV is not available in (at least some) GitHub runners
20+
if (!empty(getenv('DATA_DIR'))) {
21+
$settings['settings']['dataDir'] = getenv('DATA_DIR');
2022
}
2123

2224
$containerBuilder->addDefinitions($settings);

public/index.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
$containerBuilder->enableCompilation(ROOT_DIR . 'var/cache');
1919
}
2020

21-
// Load .env file
22-
$dotenv = Dotenv\Dotenv::createImmutable(ROOT_DIR);
21+
// Load .env file and env variables
22+
// unsafe because we need getenv(), $_ENV is not available in Github runners
23+
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(ROOT_DIR);
2324
$dotenv->safeLoad();
2425

2526
// Set up settings

0 commit comments

Comments
 (0)