Skip to content

Commit ecc0b00

Browse files
committed
feat(ci): ddd env_vars input to _spm.yml workflow
1 parent 9d5f030 commit ecc0b00

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

.github/workflows/_spm.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ on:
5858
required: false
5959
default: false
6060

61+
# Custom environment variables to inject into the jobs.
62+
# Expected to be a JSON-formatted string.
63+
# Example: '{"FIREBASE_APP_CHECK_BRANCH": "nc/target-split"}'
64+
env_vars:
65+
type: string
66+
required: false
67+
default: "{}"
68+
6169
outputs:
6270
cache_key:
6371
description: "The cache key for the Swift package resolution."
@@ -72,6 +80,24 @@ jobs:
7280
cache_key: ${{ steps.generate_cache_key.outputs.cache_key }}
7381
steps:
7482
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
83+
- name: Set Custom Environment Variables
84+
run: |
85+
python3 -c '
86+
import os, json
87+
try:
88+
env_vars = json.loads(os.environ.get("CUSTOM_ENV_VARS", "{}"))
89+
if not isinstance(env_vars, dict):
90+
raise ValueError("env_vars must be a JSON object")
91+
with open(os.environ["GITHUB_ENV"], "a") as f:
92+
for k, v in env_vars.items():
93+
f.write(f"{k}={v}\n")
94+
except json.JSONDecodeError:
95+
print("Warning: env_vars is not valid JSON. Skipping.")
96+
except Exception as e:
97+
print(f"Error setting env vars: {e}")
98+
'
99+
env:
100+
CUSTOM_ENV_VARS: ${{ inputs.env_vars }}
75101
- name: Xcode
76102
run: sudo xcode-select -s /Applications/Xcode_26.4.app/Contents/Developer
77103
- name: Generate Swift Package.resolved
@@ -110,6 +136,24 @@ jobs:
110136
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
111137
with:
112138
persist-credentials: false
139+
- name: Set Custom Environment Variables
140+
run: |
141+
python3 -c '
142+
import os, json
143+
try:
144+
env_vars = json.loads(os.environ.get("CUSTOM_ENV_VARS", "{}"))
145+
if not isinstance(env_vars, dict):
146+
raise ValueError("env_vars must be a JSON object")
147+
with open(os.environ["GITHUB_ENV"], "a") as f:
148+
for k, v in env_vars.items():
149+
f.write(f"{k}={v}\n")
150+
except json.JSONDecodeError:
151+
print("Warning: env_vars is not valid JSON. Skipping.")
152+
except Exception as e:
153+
print(f"Error setting env vars: {e}")
154+
'
155+
env:
156+
CUSTOM_ENV_VARS: ${{ inputs.env_vars }}
113157
- uses: actions/cache/restore@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
114158
with:
115159
path: .build

0 commit comments

Comments
 (0)