Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test-build-number.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
echo -e "::error title=test-build-number-reuse::Build number '${BUILD_NUMBER}' does not match the previous job build number" \
"'${{ needs.test-build-number-generation.outputs.BUILD_NUMBER }}' despite it is the same workflow run.\n" \
"Prefer using the output from SonarSource/ci-github-actions/get-build-number instead of calling it from distinct jobs."
# exit 1 # flaky test
exit 1
fi

test-build-number-reuse-from-cache-windows:
Expand All @@ -86,7 +86,7 @@ jobs:
echo -e "::error title=test-build-number-reuse-from-cache-windows::Build number '${BUILD_NUMBER}' does not match the previous" \
"job build number '${{ needs.test-build-number-generation.outputs.BUILD_NUMBER }}' despite it is the same workflow run.\n" \
"Prefer using the output from SonarSource/ci-github-actions/get-build-number instead of calling it from distinct jobs."
# exit 1 # flaky test
exit 1
fi

test-build-number-reuse-from-env:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ and set it as an environment variable named `BUILD_NUMBER`, and as a GitHub Acti
The build number is unique per workflow run ID. It is not incremented on workflow reruns.

During execution the action temporarily writes `.build_number.txt` at the repository root (for
`actions/cache`); the file is removed before the action completes. Do not track a file named
S3 cache via `runs-on/cache`); the file is removed before the action completes. Do not track a file named
`.build_number.txt` in your repository.

### Requirements
Expand Down Expand Up @@ -110,7 +110,9 @@ jobs:

### Inputs

No inputs are required for this action.
| Input | Description | Default |
|---------------------|--------------------------------------------------|---------|
| `host-actions-root` | Path to the actions folder on the host (used when called from another local action) | (empty) |

### Outputs

Expand Down
31 changes: 27 additions & 4 deletions get-build-number/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,28 @@ runs:
echo "${BUILD_NUMBER}" > "$BUILD_NUMBER_FILE"
echo "skip=true" >> $GITHUB_OUTPUT

- name: Setup S3 cache credentials
if: steps.from-env.outputs.skip != 'true'
id: aws-auth
uses: SonarSource/gh-action_cache/credential-setup@a7d13cdd1c9f097a5f8382ccec463be2831e3dbc # v1.6.0

# Reuse current build number in case of rerun
- name: Get cached build number
if: steps.from-env.outputs.skip != 'true'
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
uses: runs-on/cache/restore@88d90644011a3a9957fd141a106f5a94f9794203 # v5.0.7
id: current-build-number
env:
RUNS_ON_S3_BUCKET_CACHE: sonarsource-s3-cache-prod-bucket
AWS_DEFAULT_REGION: eu-central-1
AWS_REGION: eu-central-1
AWS_ACCESS_KEY_ID: ${{ steps.aws-auth.outputs.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ steps.aws-auth.outputs.AWS_SECRET_ACCESS_KEY }}
AWS_SESSION_TOKEN: ${{ steps.aws-auth.outputs.AWS_SESSION_TOKEN }}
AWS_PROFILE: ''
AWS_DEFAULT_PROFILE: ''
Comment on lines +55 to +63

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Quality: Duplicated AWS credential env across restore/save steps

The full AWS credential/config env block (RUNS_ON_S3_BUCKET_CACHE, AWS_DEFAULT_REGION, AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AWS_PROFILE, AWS_DEFAULT_PROFILE) is copy-pasted verbatim into both the Get cached build number (restore) step and the Save build number to cache step in get-build-number/action.yml. Any future change (bucket name, region) must be edited in two places, creating a drift risk where restore and save could end up pointing at different buckets/regions and silently miss the cache. Composite actions don't support job-level env, but you can reduce duplication by setting the static values once via $GITHUB_ENV in the existing Set local action paths step (e.g. RUNS_ON_S3_BUCKET_CACHE, AWS_*_REGION) and only repeating the per-step credential outputs, or by factoring the cache logic out. At minimum, keep the two blocks identical to avoid restore/save mismatches.

Was this helpful? React with 👍 / 👎

with:
path: ${{ env.BUILD_NUMBER_FILE }}
key: build-number-${{ github.run_id }}
key: ${{ format('{0}/build-number-{1}', github.head_ref || github.ref, github.run_id) }}
enableCrossOsArchive: true

# Otherwise, increment the build number
Expand All @@ -76,11 +90,20 @@ runs:
echo "BUILD_NUMBER=${BUILD_NUMBER}" >> "$GITHUB_OUTPUT"

- name: Save build number to cache
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
uses: runs-on/cache/save@88d90644011a3a9957fd141a106f5a94f9794203 # v5.0.7
if: steps.from-env.outputs.skip != 'true' && steps.current-build-number.outputs.cache-hit != 'true'
env:
RUNS_ON_S3_BUCKET_CACHE: sonarsource-s3-cache-prod-bucket
AWS_DEFAULT_REGION: eu-central-1
AWS_REGION: eu-central-1
AWS_ACCESS_KEY_ID: ${{ steps.aws-auth.outputs.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ steps.aws-auth.outputs.AWS_SECRET_ACCESS_KEY }}
AWS_SESSION_TOKEN: ${{ steps.aws-auth.outputs.AWS_SESSION_TOKEN }}
AWS_PROFILE: ''
AWS_DEFAULT_PROFILE: ''
with:
path: ${{ env.BUILD_NUMBER_FILE }}
key: build-number-${{ github.run_id }}
key: ${{ format('{0}/build-number-{1}', github.head_ref || github.ref, github.run_id) }}
enableCrossOsArchive: true

- name: Remove build number file from workspace
Expand Down
Loading