117117 ssh-deploy-key :
118118 description : SSH key to load in the SSH agent
119119 required : false
120+ npm-token :
121+ description : NPM authentication token for private packages
122+ required : false
120123 outputs :
121124 image-digest :
122125 description : The image digest for this build.
@@ -179,6 +182,35 @@ jobs:
179182 uses : webfactory/ssh-agent@v0.9.1
180183 with :
181184 ssh-private-key : ${{ secrets.ssh-deploy-key }}
185+ - name : Setup NPM secrets and build args
186+ id : npm-setup
187+ run : |
188+ # Check if NPM token is provided
189+ if [[ "${{ secrets.npm-token }}" != "" ]]; then
190+ # Combine user-provided secrets with NPM token secret
191+ if [[ "${{ inputs.secrets }}" != "" ]]; then
192+ echo "combined-secrets<<EOF" >> $GITHUB_OUTPUT
193+ echo "${{ inputs.secrets }}" >> $GITHUB_OUTPUT
194+ echo "npmrc=//registry.npmjs.org/:_authToken=${{ secrets.npm-token }}" >> $GITHUB_OUTPUT
195+ echo "EOF" >> $GITHUB_OUTPUT
196+ else
197+ echo "combined-secrets=npmrc=//registry.npmjs.org/:_authToken=${{ secrets.npm-token }}" >> $GITHUB_OUTPUT
198+ fi
199+
200+ # Combine user-provided build args with NPM token
201+ if [[ "${{ inputs.build-args }}" != "" ]]; then
202+ echo "combined-build-args<<EOF" >> $GITHUB_OUTPUT
203+ echo "${{ inputs.build-args }}" >> $GITHUB_OUTPUT
204+ echo "NPM_TOKEN=${{ secrets.npm-token }}" >> $GITHUB_OUTPUT
205+ echo "EOF" >> $GITHUB_OUTPUT
206+ else
207+ echo "combined-build-args=NPM_TOKEN=${{ secrets.npm-token }}" >> $GITHUB_OUTPUT
208+ fi
209+ else
210+ # No NPM token, just pass through the original inputs
211+ echo "combined-secrets=${{ inputs.secrets }}" >> $GITHUB_OUTPUT
212+ echo "combined-build-args=${{ inputs.build-args }}" >> $GITHUB_OUTPUT
213+ fi
182214 - if : inputs.cache == false && !inputs.ssh-agent
183215 name : Build (no cache)
184216 uses : docker/build-push-action@v6.18.0
@@ -188,8 +220,8 @@ jobs:
188220 push : false
189221 pull : true
190222 tags : ${{ inputs.name }}:${{ steps.setup.outputs.unique-id }}
191- build-args : ${{ inputs. build-args }}
192- secrets : ${{ inputs. secrets }}
223+ build-args : ${{ steps.npm-setup.outputs.combined- build-args }}
224+ secrets : ${{ steps.npm-setup.outputs.combined- secrets }}
193225 outputs : type=docker
194226 - if : inputs.cache == true && !inputs.ssh-agent
195227 name : Build (with cache)
@@ -200,8 +232,8 @@ jobs:
200232 push : false
201233 pull : true
202234 tags : ${{ inputs.name }}:${{ steps.setup.outputs.unique-id }}
203- build-args : ${{ inputs. build-args }}
204- secrets : ${{ inputs. secrets }}
235+ build-args : ${{ steps.npm-setup.outputs.combined- build-args }}
236+ secrets : ${{ steps.npm-setup.outputs.combined- secrets }}
205237 outputs : type=docker
206238 cache-from : type=registry,ref=${{ inputs.registry-url }}/${{ inputs.name }}:${{ inputs.cache-tag }}
207239 cache-to : type=registry,ref=${{ inputs.registry-url }}/${{ inputs.name }}:${{ inputs.cache-tag }},mode=max,ignore-error=true
@@ -214,8 +246,8 @@ jobs:
214246 push : false
215247 pull : true
216248 tags : ${{ inputs.name }}:${{ steps.setup.outputs.unique-id }}
217- build-args : ${{ inputs. build-args }}
218- secrets : ${{ inputs. secrets }}
249+ build-args : ${{ steps.npm-setup.outputs.combined- build-args }}
250+ secrets : ${{ steps.npm-setup.outputs.combined- secrets }}
219251 outputs : type=docker
220252 ssh : |
221253 default=${{ env.SSH_AUTH_SOCK }}
@@ -228,8 +260,8 @@ jobs:
228260 push : false
229261 pull : true
230262 tags : ${{ inputs.name }}:${{ steps.setup.outputs.unique-id }}
231- build-args : ${{ inputs. build-args }}
232- secrets : ${{ inputs. secrets }}
263+ build-args : ${{ steps.npm-setup.outputs.combined- build-args }}
264+ secrets : ${{ steps.npm-setup.outputs.combined- secrets }}
233265 outputs : type=docker
234266 cache-from : type=registry,ref=${{ inputs.registry-url }}/${{ inputs.name }}:${{ inputs.cache-tag }}
235267 cache-to : type=registry,ref=${{ inputs.registry-url }}/${{ inputs.name }}:${{ inputs.cache-tag }},mode=max,ignore-error=true
0 commit comments