snuyanzin commented on code in PR #28098:
URL: https://github.com/apache/flink/pull/28098#discussion_r3180071218


##########
.github/actions/job_init/action.yml:
##########
@@ -74,13 +74,37 @@ runs:
         echo "JAVA_HOME=$JAVA_HOME_${{ inputs.jdk_version }}_X64" >> 
"${GITHUB_ENV}"
         echo "PATH=$JAVA_HOME_${{ inputs.jdk_version }}_X64/bin:$PATH" >> 
"${GITHUB_ENV}"
 
+    - name: "Determine cache namespace (PR base | branch | tag)"
+      id: cache-ns
+      shell: bash
+      run: |
+        # For PR runs use the target branch so PRs share a cache pool with the 
branch they merge into.
+        # For push / workflow_dispatch / tag pushes, use the ref name itself.
+        if [ "${{ github.event_name }}" = "pull_request" ] || [ "${{ 
github.event_name }}" = "pull_request_target" ]; then
+          ns="${{ github.base_ref }}"
+        else
+          ns="${{ github.ref_name }}"
+        fi
+        # Map release tags (release-X.Y.Z, release-X.Y.Z-rcN) back to their 
parent branch
+        # (release-X.Y) so tag builds reuse the branch's warm cache.
+        case "${ns}" in
+          release-[0-9]*.[0-9]*.[0-9]*) ns="$(printf '%s' "${ns}" | sed 
's/^\(release-[0-9][0-9]*\.[0-9][0-9]*\)\..*/\1/')" ;;
+        esac
+        # Sanitize for use in a cache key (no slashes, spaces, etc.).
+        ns="$(printf '%s' "${ns}" | tr -c '[:alnum:]._-' '-')"

Review Comment:
   I tried locally this bash script
   ```bash
   for s in 'master' 'release-1.20' 'dev/foo' 'feature/JIRA-123' 'a b c'; do
        printf '%-25s -> [%s]\n' "$s" "$(printf '%s' "$s" | tr -c 
'[:alnum:]._-' '-')"
   done
   ```
   and output is
   ```
   master                    -> [master]
   release-1.20              -> [release-1.20]
   dev/foo                   -> [dev-foo]
   feature/JIRA-123          -> [feature-JIRA-123]
   a b c                     -> [a-b-c]
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to