@@ -15,181 +15,30 @@ inputs:
1515 description : The chunk size used to split up large files during upload, in bytes
1616 enableCrossOsArchive :
1717 description : When enabled, allows to save or restore caches that can be restored or saved respectively on other platforms
18- default : false
18+ default : ' false'
1919 fail-on-cache-miss :
2020 description : Fail the workflow if cache entry is not found
21- default : false
21+ default : ' false'
2222 lookup-only :
2323 description : Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache
24- default : false
24+ default : ' false'
2525 environment :
26- description : Environment to use ('dev' or 'prod', 's3' backend only).
26+ description : Environment to use ('dev' or 'prod', 's3' backend only)
2727 default : prod
2828 fallback-branch :
29- description : Optional maintenance branch for fallback restore keys (pattern 'branch-*', 's3' backend only). If not set, the repository
30- default branch is used.
29+ description : Optional maintenance branch for fallback restore keys (pattern 'branch-*', 's3' backend only). If not set, the repository default branch is used.
3130 backend :
3231 description : Force cache backend ('github' or 's3'). If not set, automatically determined based on repository visibility.
3332
3433outputs :
3534 cache-hit :
3635 description : A boolean value to indicate an exact match was found for the primary key
37- value : ${{ steps.github-cache.outputs.cache-hit || steps.s3-cache.outputs.cache-hit }}
3836
3937runs :
40- using : composite
41- steps :
42- - name : Determine cache backend
43- id : cache-backend
44- shell : bash
45- env :
46- GITHUB_TOKEN : ${{ github.token }}
47- REPO_VISIBILITY : ${{ github.event.repository.visibility }}
48- FORCED_BACKEND : ${{ inputs.backend }}
49- run : |
50- if [[ "$FORCED_BACKEND" == "github" || "$FORCED_BACKEND" == "s3" ]]; then
51- CACHE_BACKEND="$FORCED_BACKEND"
52- echo "Using forced backend: $CACHE_BACKEND"
53- else
54- # If visibility is not available in the event, try to get it from the API
55- if [[ -z "$REPO_VISIBILITY" || "$REPO_VISIBILITY" = "null" ]]; then
56- REPO_VISIBILITY=$(curl -s -H "Authorization: token ${{ github.token }}" \
57- "https://api.github.com/repos/${{ github.repository }}" | \
58- jq -r '.visibility // "private"')
59- fi
60- echo "Repository visibility: $REPO_VISIBILITY"
61-
62- if [[ "$REPO_VISIBILITY" == "public" ]]; then
63- CACHE_BACKEND="github"
64- echo "Using GitHub cache for public repository"
65- else
66- CACHE_BACKEND="s3"
67- echo "Using S3 cache for private/internal repository"
68- fi
69- fi
70-
71- echo "cache-backend=$CACHE_BACKEND" >> "$GITHUB_OUTPUT"
72-
73- - name : Cache with GitHub Actions (public repos)
74- if : steps.cache-backend.outputs.cache-backend == 'github'
75- uses : actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
76- id : github-cache
77- with :
78- path : ${{ inputs.path }}
79- key : ${{ inputs.key }}
80- restore-keys : ${{ inputs.restore-keys }}
81- upload-chunk-size : ${{ inputs.upload-chunk-size }}
82- enableCrossOsArchive : ${{ inputs.enableCrossOsArchive }}
83- fail-on-cache-miss : ${{ inputs.fail-on-cache-miss }}
84- lookup-only : ${{ inputs.lookup-only }}
85-
86- # Cache with S3 (private/internal repos)
87- - name : Authenticate to AWS
88- if : steps.cache-backend.outputs.cache-backend == 's3'
89- id : aws-auth
90- shell : bash
91- env :
92- POOL_ID : ${{ inputs.environment == 'prod' && 'eu-central-1:511fe374-ae4f-46d0-adb7-9246e570c7f4' || 'eu-central-1:3221c6ea-3f67-4fd8-a7ff-7426f96add89' }}
93- AWS_ACCOUNT_ID : ${{ inputs.environment == 'prod' && '275878209202' || '460386131003' }}
94- IDENTITY_PROVIDER_NAME : token.actions.githubusercontent.com
95- AUDIENCE : cognito-identity.amazonaws.com
96- AWS_REGION : eu-central-1
97- GITHUB_RUN_ID : ${{ github.run_id }}
98- run : |
99- # Get GitHub Actions ID token using script
100- ACCESS_TOKEN=$("$GITHUB_ACTION_PATH/scripts/get-github-token.sh")
101- echo "::add-mask::$ACCESS_TOKEN"
102-
103- # Get Identity ID
104- identityId=$(aws cognito-identity get-id \
105- --identity-pool-id "$POOL_ID" \
106- --account-id "$AWS_ACCOUNT_ID" \
107- --logins '{"'"$IDENTITY_PROVIDER_NAME"'":"'"$ACCESS_TOKEN"'"}' \
108- --query 'IdentityId' --output text)
109-
110- # Validate Identity ID was obtained
111- if [[ "$identityId" == "null" || -z "$identityId" ]]; then
112- echo "::error::Failed to obtain Identity ID from Cognito Identity Pool"
113- echo "::error::Check identity pool configuration and IAM roles"
114- exit 1
115- fi
116-
117- # Get and validate AWS credentials
118- awsCredentials=$(aws cognito-identity get-credentials-for-identity \
119- --identity-id "$identityId" \
120- --logins '{"'"$IDENTITY_PROVIDER_NAME"'":"'"$ACCESS_TOKEN"'"}')
121-
122- AWS_ACCESS_KEY_ID=$(echo "$awsCredentials" | jq -r ".Credentials.AccessKeyId")
123- AWS_SECRET_ACCESS_KEY=$(echo "$awsCredentials" | jq -r ".Credentials.SecretKey")
124- AWS_SESSION_TOKEN=$(echo "$awsCredentials" | jq -r ".Credentials.SessionToken")
125- if [[ "$AWS_ACCESS_KEY_ID" == "null" || -z "$AWS_ACCESS_KEY_ID" ]]; then
126- echo "::error::Failed to obtain AWS Access Key ID"
127- exit 1
128- fi
129- if [[ "$AWS_SECRET_ACCESS_KEY" == "null" || -z "$AWS_SECRET_ACCESS_KEY" ]]; then
130- echo "::error::Failed to obtain AWS Secret Access Key"
131- exit 1
132- fi
133- if [[ "$AWS_SESSION_TOKEN" == "null" || -z "$AWS_SESSION_TOKEN" ]]; then
134- echo "::error::Failed to obtain AWS Session Token"
135- exit 1
136- fi
137- echo "::add-mask::$AWS_ACCESS_KEY_ID"
138- echo "::add-mask::$AWS_SECRET_ACCESS_KEY"
139- echo "::add-mask::$AWS_SESSION_TOKEN"
140-
141- # Create a unique AWS profile to isolate credentials from user-configured AWS credentials
142- # This prevents credential override when users call aws-actions/configure-aws-credentials
143- # between the cache restore (main step) and cache save (post step)
144- PROFILE_NAME="gh-action-cache-${GITHUB_RUN_ID}"
145-
146- mkdir -p ~/.aws
147- chmod 700 ~/.aws
148-
149- # Write credentials to a dedicated profile using AWS CLI (handles file format and permissions correctly)
150- aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID" --profile "$PROFILE_NAME"
151- aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY" --profile "$PROFILE_NAME"
152- aws configure set aws_session_token "$AWS_SESSION_TOKEN" --profile "$PROFILE_NAME"
153- aws configure set region eu-central-1 --profile "$PROFILE_NAME"
154- echo "Created AWS profile: $PROFILE_NAME"
155- echo "AWS_PROFILE=$PROFILE_NAME" >> "$GITHUB_OUTPUT"
156- # Export to GITHUB_ENV so the profile persists to post steps (cache save)
157- # This is necessary because step-level env vars don't persist to post steps
158- echo "AWS_PROFILE=$PROFILE_NAME" >> "$GITHUB_ENV"
159- echo "AWS_DEFAULT_PROFILE=$PROFILE_NAME" >> "$GITHUB_ENV"
160-
161- - name : Prepare cache keys
162- if : steps.cache-backend.outputs.cache-backend == 's3'
163- shell : bash
164- id : prepare-keys
165- env :
166- INPUT_KEY : ${{ inputs.key }}
167- INPUT_RESTORE_KEYS : ${{ inputs.restore-keys }}
168- INPUT_FALLBACK_BRANCH : ${{ inputs.fallback-branch }}
169- GITHUB_TOKEN : ${{ github.token }}
170- GITHUB_REPOSITORY : ${{ github.repository }}
171- run : $GITHUB_ACTION_PATH/scripts/prepare-keys.sh
172-
173- - name : Cache on S3
174- if : steps.cache-backend.outputs.cache-backend == 's3'
175- uses : runs-on/cache@50350ad4242587b6c8c2baa2e740b1bc11285ff4 # v4.3.0
176- id : s3-cache
177- env :
178- RUNS_ON_S3_BUCKET_CACHE : sonarsource-s3-cache-${{ inputs.environment }}-bucket
179- AWS_DEFAULT_REGION : eu-central-1
180- AWS_REGION : eu-central-1
181- # Use AWS profile instead of direct credentials to prevent override issues
182- # When users configure their own AWS credentials mid-job, the profile remains isolated
183- AWS_PROFILE : ${{ steps.aws-auth.outputs.AWS_PROFILE }}
184- AWS_DEFAULT_PROFILE : ${{ steps.aws-auth.outputs.AWS_PROFILE }}
185- with :
186- path : ${{ inputs.path }}
187- key : ${{ steps.prepare-keys.outputs.branch-key }}
188- restore-keys : ${{ steps.prepare-keys.outputs.branch-restore-keys }}
189- upload-chunk-size : ${{ inputs.upload-chunk-size }}
190- enableCrossOsArchive : ${{ inputs.enableCrossOsArchive }}
191- fail-on-cache-miss : ${{ inputs.fail-on-cache-miss }}
192- lookup-only : ${{ inputs.lookup-only }}
38+ using : ' node20'
39+ main : ' dist/main/index.js'
40+ post : ' dist/post/index.js'
41+ post-if : success()
19342
19443branding :
19544 icon : upload-cloud
0 commit comments