5050 type : string
5151 required : false
5252 default : " ."
53+ secrets :
54+ build-secrets :
55+ description : |
56+ Secrets to be used during the build step.
57+ Must be a JSON object where keys are environment variable names and values are secret references.
58+ Example:
59+ ```json
60+ {
61+ "SECRET_EXAMPLE": "$\{{ secrets.SECRET_EXAMPLE }}"
62+ }
63+ ```
64+ required : false
5365
5466permissions :
5567 contents : read
@@ -122,6 +134,7 @@ jobs:
122134 const buildInput = `${{ inputs.build }}`.trim();
123135
124136 let commands = [];
137+ let env = {};
125138
126139 // Build input can be json or string
127140 try {
@@ -130,6 +143,7 @@ jobs:
130143 commands = build;
131144 } else {
132145 commands = build.commands ?? ["build"];
146+ env = build.env ?? {};
133147
134148 if (build.artifact) {
135149 if(typeof build.artifact === 'string') {
@@ -159,6 +173,7 @@ jobs:
159173 }
160174
161175 core.setOutput('commands', sanitizedCommands.join('\n'));
176+ core.setOutput('env', JSON.stringify(env));
162177
163178 lint :
164179 name : 👕 Lint
@@ -238,6 +253,39 @@ jobs:
238253 gatsby
239254 storybook
240255
256+ - if : needs.setup.outputs.build-commands
257+ uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
258+ env :
259+ BUILD_ENV : ${{ needs.setup.outputs.build-env }}
260+ BUILD_SECRETS : ${{ secrets.build-secrets }}
261+ with :
262+ script : |
263+ const envInput = process.env.BUILD_ENV || '{}';
264+
265+ let buildEnv = {};
266+
267+ try {
268+ buildEnv = JSON.parse(envInput);
269+ } catch (e) {
270+ core.setFailed(`Invalid build env JSON: ${e.message}`);
271+ }
272+
273+ for (const [key, value] of Object.entries(buildEnv)) {
274+ core.exportVariable(key, value);
275+ }
276+
277+ const secretsInput = process.env.BUILD_SECRETS || '';
278+ let buildSecrets = {};
279+
280+ try {
281+ buildSecrets = JSON.parse(secretsInput);
282+ } catch (e) {
283+ core.setFailed(`Invalid build secrets JSON: ${e.message}`);
284+ }
285+
286+ for (const [key, value] of Object.entries(buildSecrets)) {
287+ core.exportVariable(key, value);
288+ }
241289 - if : needs.setup.outputs.build-commands
242290 working-directory : ${{ inputs.working-directory }}
243291 run : |
0 commit comments