Skip to content

Commit 57296e8

Browse files
BUILD-10503 Sanitize workflow name in npm/maven
1 parent 829a4d8 commit 57296e8

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

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+
key: >-
185+
maven-${{ runner.os }}-${{ steps.sanitize_workflow.outputs.workflow_name
186+
}}-${{ hashFiles(format('{0}/**/pom.xml', inputs.working-directory)) }}
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

0 commit comments

Comments
 (0)