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
89101 contents : read
90102 id-token : write
91103 outputs :
104+ build-env : ${{ steps.build-variables.outputs.env }}
92105 build-commands : ${{ steps.build-variables.outputs.commands }}
93106 build-artifact : ${{ steps.build-variables.outputs.artifact }}
94107 steps :
@@ -122,6 +135,7 @@ jobs:
122135 const buildInput = `${{ inputs.build }}`.trim();
123136
124137 let commands = [];
138+ let env = {};
125139
126140 // Build input can be json or string
127141 try {
@@ -130,6 +144,7 @@ jobs:
130144 commands = build;
131145 } else {
132146 commands = build.commands ?? ["build"];
147+ env = build.env ?? {};
133148
134149 if (build.artifact) {
135150 if(typeof build.artifact === 'string') {
@@ -159,6 +174,7 @@ jobs:
159174 }
160175
161176 core.setOutput('commands', sanitizedCommands.join('\n'));
177+ core.setOutput('env', JSON.stringify(env));
162178
163179 lint :
164180 name : 👕 Lint
@@ -238,6 +254,39 @@ jobs:
238254 gatsby
239255 storybook
240256
257+ - if : needs.setup.outputs.build-commands
258+ uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
259+ env :
260+ BUILD_ENV : ${{ needs.setup.outputs.build-env }}
261+ BUILD_SECRETS : ${{ secrets.build-secrets }}
262+ with :
263+ script : |
264+ const envInput = process.env.BUILD_ENV || '{}';
265+
266+ let buildEnv = {};
267+
268+ try {
269+ buildEnv = JSON.parse(envInput);
270+ } catch (e) {
271+ core.setFailed(`Invalid build env JSON: ${e.message}`);
272+ }
273+
274+ for (const [key, value] of Object.entries(buildEnv)) {
275+ core.exportVariable(key, value);
276+ }
277+
278+ const secretsInput = process.env.BUILD_SECRETS || '';
279+ let buildSecrets = {};
280+
281+ try {
282+ buildSecrets = JSON.parse(secretsInput);
283+ } catch (e) {
284+ core.setFailed(`Invalid build secrets JSON: ${e.message}`);
285+ }
286+
287+ for (const [key, value] of Object.entries(buildSecrets)) {
288+ core.exportVariable(key, value);
289+ }
241290 - if : needs.setup.outputs.build-commands
242291 working-directory : ${{ inputs.working-directory }}
243292 run : |
0 commit comments