Skip to content

Commit 191ff72

Browse files
ci: make ECR login and Docker-dependent jobs conditional on secret availability
- Make aws_ecr_login action tolerate missing inputs and skip gracefully - Add check-secrets job to tests.yml that gates Docker image builds - Skip dashmate E2E, test-suite, and functional tests when ECR is unavailable - Make ECR login conditional in consumer workflows as defense-in-depth - Cache protoc Docker image via actions/cache to avoid Docker Hub rate limits - Make CodeQL DockerHub login conditional Fork PRs now get: Rust tests, JS tests, linting, formatting, security audits Fork PRs skip: Docker builds, E2E tests, test-suite, functional tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5da1314 commit 191ff72

7 files changed

Lines changed: 65 additions & 11 deletions

File tree

‎.github/actions/aws_ecr_login/action.yaml‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,53 @@
11
---
22
# Login to AWS ECR
33
name: "aws_ecr_login"
4-
description: "Login to AWS ECR to store Docker containers"
4+
description: "Login to AWS ECR to store Docker containers. Skips gracefully when credentials are not provided."
55
inputs:
66
aws_account_id:
77
description: AWS account ID (AWS_ACCOUNT_ID)
8-
required: true
8+
required: false
99
aws_access_key_id:
1010
description: Access key ID (AWS_ACCESS_KEY_ID)
11-
required: true
11+
required: false
1212
aws_secret_access_key:
1313
description: Secret access key (AWS_SECRET_ACCESS_KEY)
14-
required: true
14+
required: false
1515
aws_region:
1616
description: AWS region to use (AWS_REGION)
17-
required: true
17+
required: false
1818

1919
runs:
2020
using: composite
2121
steps:
22+
- name: Check ECR credentials
23+
id: check
24+
shell: bash
25+
run: |
26+
if [[ -z "${{ inputs.aws_region }}" || -z "${{ inputs.aws_access_key_id }}" || -z "${{ inputs.aws_secret_access_key }}" || -z "${{ inputs.aws_account_id }}" ]]; then
27+
echo "skip=true" >> "$GITHUB_OUTPUT"
28+
echo "::warning::ECR login skipped — credentials not available (expected for fork PRs)"
29+
else
30+
echo "skip=false" >> "$GITHUB_OUTPUT"
31+
fi
32+
2233
- name: Configure AWS credentials and bucket region
34+
if: steps.check.outputs.skip != 'true'
2335
uses: aws-actions/configure-aws-credentials@v4
2436
with:
2537
aws-access-key-id: ${{ inputs.aws_access_key_id }}
2638
aws-secret-access-key: ${{ inputs.aws_secret_access_key }}
2739
aws-region: ${{ inputs.aws_region }}
2840

2941
- name: Login to ECR
42+
if: steps.check.outputs.skip != 'true'
3043
run: |
3144
aws ecr get-login-password \
3245
--region ${{ inputs.aws_region }} | docker login --username AWS --password-stdin ${{ inputs.aws_account_id }}.dkr.ecr.${{ inputs.aws_region }}.amazonaws.com
3346
shell: bash
3447

3548
# Unset AWS credentials to avoid conflicts, as we prefer credentials from ~/.aws/credentials to authenticate
3649
- name: Unset AWS credentials to avoid conflicts
50+
if: steps.check.outputs.skip != 'true'
3751
shell: bash
3852
run: |
3953
echo AWS_DEFAULT_REGION='' >> $GITHUB_ENV

‎.github/workflows/tests-build-js.yml‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,24 @@ jobs:
2525
password: ${{ secrets.DOCKERHUB_TOKEN }}
2626
if: ${{ steps.check-artifact.outputs.exists != 'true' && secrets.DOCKERHUB_USERNAME != '' }}
2727

28-
- name: Pre-pull protoc Docker image for gRPC codegen
29-
run: docker pull rvolosatovs/protoc:4.0.0
28+
- name: Cache protoc Docker image
29+
id: cache-protoc
30+
uses: actions/cache@v4
31+
with:
32+
path: /tmp/protoc-image.tar
33+
key: docker-rvolosatovs-protoc-4.0.0
3034
if: ${{ steps.check-artifact.outputs.exists != 'true' }}
3135

36+
- name: Load protoc image from cache
37+
run: docker load -i /tmp/protoc-image.tar
38+
if: ${{ steps.check-artifact.outputs.exists != 'true' && steps.cache-protoc.outputs.cache-hit == 'true' }}
39+
40+
- name: Pull and cache protoc Docker image
41+
run: |
42+
docker pull rvolosatovs/protoc:4.0.0
43+
docker save rvolosatovs/protoc:4.0.0 -o /tmp/protoc-image.tar
44+
if: ${{ steps.check-artifact.outputs.exists != 'true' && steps.cache-protoc.outputs.cache-hit != 'true' }}
45+
3246
- name: Setup Node.JS
3347
uses: ./.github/actions/nodejs
3448
if: ${{ steps.check-artifact.outputs.exists != 'true' }}

‎.github/workflows/tests-codeql.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
with:
2121
username: ${{ secrets.DOCKERHUB_USERNAME }}
2222
password: ${{ secrets.DOCKERHUB_TOKEN }}
23+
if: ${{ secrets.DOCKERHUB_USERNAME != '' }}
2324

2425
- name: Setup Node.JS
2526
uses: ./.github/actions/nodejs

‎.github/workflows/tests-dashmate.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
4040
aws_region: ${{ vars.AWS_REGION }}
4141
aws_account_id: ${{ secrets.AWS_ACCOUNT_ID }}
42+
if: ${{ secrets.AWS_ACCESS_KEY_ID != '' }}
4243

4344
- name: Setup Node.JS
4445
uses: ./.github/actions/nodejs

‎.github/workflows/tests-packges-functional.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
2929
aws_region: ${{ vars.AWS_REGION }}
3030
aws_account_id: ${{ secrets.AWS_ACCOUNT_ID }}
31+
if: ${{ secrets.AWS_ACCESS_KEY_ID != '' }}
3132

3233
- name: Start local network
3334
uses: ./.github/actions/local-network

‎.github/workflows/tests-test-suite.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
4747
aws_region: ${{ vars.AWS_REGION }}
4848
aws_account_id: ${{ secrets.AWS_ACCOUNT_ID }}
49+
if: ${{ secrets.AWS_ACCESS_KEY_ID != '' }}
4950

5051
- name: Start local network
5152
uses: ./.github/actions/local-network

‎.github/workflows/tests.yml‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ concurrency:
1919
cancel-in-progress: true
2020

2121
jobs:
22+
check-secrets:
23+
name: Check secret availability
24+
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || !github.event.pull_request.draft }}
25+
runs-on: ubuntu-24.04
26+
outputs:
27+
has_ecr: ${{ steps.check.outputs.has_ecr }}
28+
steps:
29+
- name: Check if ECR credentials are available
30+
id: check
31+
run: |
32+
if [[ -n "${{ secrets.AWS_ACCESS_KEY_ID }}" && -n "${{ secrets.AWS_ACCOUNT_ID }}" ]]; then
33+
echo "has_ecr=true" >> "$GITHUB_OUTPUT"
34+
else
35+
echo "has_ecr=false" >> "$GITHUB_OUTPUT"
36+
echo "::notice::ECR credentials not available — Docker image builds and dependent tests will be skipped (expected for fork PRs)"
37+
fi
38+
2239
changes:
2340
name: Determine changed packages
2441
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || !github.event.pull_request.draft }}
@@ -69,7 +86,9 @@ jobs:
6986

7087
build-images:
7188
name: Build Docker images
72-
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || !github.event.pull_request.draft }}
89+
needs:
90+
- check-secrets
91+
if: ${{ needs.check-secrets.outputs.has_ecr == 'true' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || !github.event.pull_request.draft) }}
7392
secrets: inherit
7493
strategy:
7594
fail-fast: false
@@ -193,6 +212,7 @@ jobs:
193212
- changes
194213
- build-js
195214
- build-images
215+
- check-secrets
196216
strategy:
197217
fail-fast: false
198218
matrix:
@@ -211,16 +231,17 @@ jobs:
211231
name: ${{ matrix.name }}
212232
test-pattern: ${{ matrix.test-pattern }}
213233
restore_local_network_data: ${{ matrix.restore_local_network_data }}
214-
if: contains(needs.changes.outputs.js-packages, 'dashmate')
234+
if: ${{ needs.check-secrets.outputs.has_ecr == 'true' && contains(needs.changes.outputs.js-packages, 'dashmate') }}
215235

216236
test-suite:
217237
name: Test Suite
218238
needs:
219239
- build-js
220240
- build-images
221241
- changes
242+
- check-secrets
222243
secrets: inherit
223-
if: needs.changes.outputs.test-suite == 'true'
244+
if: ${{ needs.check-secrets.outputs.has_ecr == 'true' && needs.changes.outputs.test-suite == 'true' }}
224245
strategy:
225246
fail-fast: false
226247
matrix:
@@ -250,6 +271,7 @@ jobs:
250271
- build-js
251272
- build-images
252273
- changes
274+
- check-secrets
253275
secrets: inherit
254-
if: needs.changes.outputs.test-suite == 'true'
276+
if: ${{ needs.check-secrets.outputs.has_ecr == 'true' && needs.changes.outputs.test-suite == 'true' }}
255277
uses: ./.github/workflows/tests-packges-functional.yml

0 commit comments

Comments
 (0)