Skip to content

Commit 4ef2061

Browse files
BUILD-10503 Sanitize workflow name for cache
1 parent 829a4d8 commit 4ef2061

4 files changed

Lines changed: 44 additions & 8 deletions

File tree

config-gradle/action.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,21 @@ runs:
157157
158158
rm -f gradle-md5-sums.txt
159159
160+
- name: Sanitize workflow name for cache key
161+
id: sanitize_workflow
162+
if: steps.config-gradle-completed.outputs.skip != 'true' && inputs.disable-caching == 'false'
163+
shell: bash
164+
env:
165+
WORKFLOW_NAME: ${{ github.workflow }}
166+
run: echo "workflow_name=${WORKFLOW_NAME// /-}" >> "$GITHUB_OUTPUT"
167+
160168
- name: Gradle Cache
161169
uses: SonarSource/gh-action_cache@v1
162170
if: steps.config-gradle-completed.outputs.skip != 'true' && inputs.disable-caching == 'false'
163171
with:
164172
path: ${{ inputs.cache-paths }}
165-
key: gradle-${{ runner.os }}-${{ github.workflow }}-${{ env.GRADLE_CACHE_KEY }}
166-
restore-keys: gradle-${{ runner.os }}-${{ github.workflow }}-
173+
key: gradle-${{ runner.os }}-${{ steps.sanitize_workflow.outputs.workflow_name }}-${{ env.GRADLE_CACHE_KEY }}
174+
restore-keys: gradle-${{ runner.os }}-${{ steps.sanitize_workflow.outputs.workflow_name }}-
167175

168176
# $GRADLE_USER_HOME is typically set to ~/.gradle/ by gradle/actions/setup-gradle
169177
- name: Configure Gradle Authentication

config-maven/action.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,23 @@ runs:
168168
fi
169169
fi
170170
171+
- name: Sanitize workflow name for cache key
172+
id: sanitize_workflow
173+
if: steps.config-maven-completed.outputs.skip != 'true' && inputs.disable-caching == 'false'
174+
shell: bash
175+
env:
176+
WORKFLOW_NAME: ${{ github.workflow }}
177+
run: echo "workflow_name=${WORKFLOW_NAME// /-}" >> "$GITHUB_OUTPUT"
178+
171179
- name: Cache local Maven repository
172180
uses: SonarSource/gh-action_cache@v1
173181
if: steps.config-maven-completed.outputs.skip != 'true' && inputs.disable-caching == 'false'
174182
with:
175183
path: ${{ inputs.cache-paths }}
176-
key: maven-${{ runner.os }}-${{ github.workflow }}-${{ hashFiles(format('{0}/**/pom.xml', inputs.working-directory)) }}
177-
restore-keys: maven-${{ runner.os }}-${{ github.workflow }}-
184+
# yamllint disable rule:line-length
185+
key: maven-${{ runner.os }}-${{ steps.sanitize_workflow.outputs.workflow_name }}-${{ hashFiles(format('{0}/**/pom.xml', inputs.working-directory)) }}
186+
# yamllint enable rule:line-length
187+
restore-keys: maven-${{ runner.os }}-${{ steps.sanitize_workflow.outputs.workflow_name }}-
178188

179189
- name: Update project version and set current-version and project-version variables
180190
id: set-version

config-npm/action.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,21 @@ runs:
9797
rmdir "${{ steps.setup.outputs.MISE_BACKUP }}"
9898
echo "::endgroup::"
9999
100+
- name: Sanitize workflow name for cache key
101+
id: sanitize_workflow
102+
if: ${{ inputs.cache-npm == 'true' }}
103+
shell: bash
104+
env:
105+
WORKFLOW_NAME: ${{ github.workflow }}
106+
run: echo "workflow_name=${WORKFLOW_NAME// /-}" >> "$GITHUB_OUTPUT"
107+
100108
- name: Cache NPM dependencies
101109
uses: SonarSource/gh-action_cache@v1
102110
if: ${{ inputs.cache-npm == 'true' }}
103111
with:
104112
path: ~/.npm
105-
key: npm-${{ runner.os }}-${{ github.workflow }}-${{ hashFiles('**/package-lock.json') }}
106-
restore-keys: npm-${{ runner.os }}-${{ github.workflow }}-
113+
key: npm-${{ runner.os }}-${{ steps.sanitize_workflow.outputs.workflow_name }}-${{ hashFiles('**/package-lock.json') }}
114+
restore-keys: npm-${{ runner.os }}-${{ steps.sanitize_workflow.outputs.workflow_name }}-
107115

108116
- name: Check for package.json
109117
id: check_package_json

config-pip/action.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,22 @@ runs:
9191
ARTIFACTORY_ACCESS_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_ACCESS_TOKEN }}
9292
run: $ACTION_PATH_CONFIG_PIP/config.sh
9393

94+
- name: Sanitize workflow name for cache key
95+
id: sanitize_workflow
96+
if: inputs.disable-caching == 'false'
97+
shell: bash
98+
env:
99+
WORKFLOW_NAME: ${{ github.workflow }}
100+
run: echo "workflow_name=${WORKFLOW_NAME// /-}" >> "$GITHUB_OUTPUT"
101+
94102
- name: Cache pip dependencies
95103
uses: SonarSource/gh-action_cache@v1
96104
if: inputs.disable-caching == 'false'
97105
with:
98106
path: ${{ inputs.cache-paths }}
99-
key: pip-${{ runner.os }}-${{ github.workflow }}-${{ hashFiles(format('{0}/requirements*.txt', inputs.working-directory),
107+
# yamllint disable rule:line-length
108+
key: pip-${{ runner.os }}-${{ steps.sanitize_workflow.outputs.workflow_name }}-${{ hashFiles(format('{0}/requirements*.txt', inputs.working-directory),
100109
format('{0}/Pipfile.lock', inputs.working-directory), format('{0}/poetry.lock', inputs.working-directory),
101110
format('{0}/pyproject.toml', inputs.working-directory)) }}
102-
restore-keys: pip-${{ runner.os }}-${{ github.workflow }}-
111+
# yamllint enable rule:line-length
112+
restore-keys: pip-${{ runner.os }}-${{ steps.sanitize_workflow.outputs.workflow_name }}-

0 commit comments

Comments
 (0)