121121 DOCKERHUB_TOKEN :
122122 required : false
123123 description : Docker Hub access token (or password) for DOCKERHUB_USERNAME
124+ BUILD_SECRETS :
125+ required : false
126+ description : >-
127+ Secrets for the build as BuildKit secrets (`id=value`, one per line; the format of build-push-action's
128+ `secrets` input), e.g. `sentry_auth_token=<token>`. Read in the Dockerfile with
129+ `RUN --mount=type=secret,id=sentry_auth_token ...`. Masked in the logs; unset or empty passes no secret.
124130 outputs :
125131 digest :
126132 description : Digest of the built image (the multi-platform index if more than one platform was built)
@@ -141,6 +147,18 @@ jobs:
141147 digest : ${{ steps.build.outputs.digest }}
142148 tags : ${{ steps.meta.outputs.tags }}
143149 steps :
150+ - &mask-build-secrets
151+ name : Mask build secrets
152+ env :
153+ BUILD_SECRETS : ${{ secrets.BUILD_SECRETS }}
154+ run : |
155+ # Every value is masked in the logs, also if the caller composed BUILD_SECRETS (`format(...)`) from
156+ # a secret and GitHub does not know the composed value as a secret. Nothing is printed.
157+ while IFS= read -r line; do
158+ value="${line#*=}"
159+ [ -z "$value" ] || echo "::add-mask::$value"
160+ done <<< "$BUILD_SECRETS"
161+
144162 - &checkout
145163 name : Checkout repository
146164 uses : actions/checkout@v7
@@ -346,6 +364,7 @@ jobs:
346364 push : ${{ inputs.push }}
347365 tags : ${{ steps.meta.outputs.tags }}
348366 labels : ${{ steps.meta.outputs.labels }}
367+ secrets : ${{ secrets.BUILD_SECRETS }}
349368 cache-from : type=gha,scope=${{ steps.config.outputs.cache-scope }}
350369 cache-to : type=gha,mode=min,scope=${{ steps.config.outputs.cache-scope }},ignore-error=true
351370
@@ -549,6 +568,7 @@ jobs:
549568 contents : read
550569 packages : write # push to ghcr.io
551570 steps :
571+ - *mask-build-secrets
552572 - *checkout
553573 - *download-artifact
554574 - *prepare
@@ -567,6 +587,7 @@ jobs:
567587 platforms : ${{ matrix.platform }}
568588 build-args : ${{ inputs.build-args }}
569589 labels : ${{ steps.meta.outputs.labels }}
590+ secrets : ${{ secrets.BUILD_SECRETS }}
570591 outputs : ${{ inputs.push && format('type=image,"name={0}",push-by-digest=true,name-canonical=true,push=true', steps.config.outputs.image-names) || 'type=cacheonly' }}
571592 cache-from : type=gha,scope=${{ steps.config.outputs.cache-scope }}-${{ matrix.platform == 'linux/arm64' && 'arm64' || 'amd64' }}
572593 cache-to : type=gha,mode=min,scope=${{ steps.config.outputs.cache-scope }}-${{ matrix.platform == 'linux/arm64' && 'arm64' || 'amd64' }},ignore-error=true
0 commit comments