mchades commented on code in PR #13501:
URL: https://github.com/apache/gravitino/pull/13501#discussion_r4091769285


##########
.github/workflows/label-fix-version.yml:
##########
@@ -0,0 +1,149 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Label the issues fixed by a merged PR with the version that the PR's base
+# branch is going to release, e.g. main (2.0.0-SNAPSHOT) -> "2.0.0",
+# branch-1.2 (1.2.2-SNAPSHOT) -> "1.2.2". If a release on the base branch is
+# still in progress (RC tagged but not released), that release is used
+# instead, e.g. branch-1.3 (1.3.2-SNAPSHOT, v1.3.1-rc2 only) -> "1.3.1".
+# Unassigned issues are also assigned to the PR author.
+#
+# Issues are taken only from "[#123]" in the PR title and from the PR's
+# closing keywords (e.g. "Fix: #123"). PRs without an issue are skipped.
+#
+# This uses pull_request_target so that PRs from forks get a token that can
+# write labels. It never checks out PR code, and all PR-controlled values are
+# passed through env to avoid script injection.
+
+name: Label issues with fix version and assign author
+
+on:
+  pull_request_target:
+    types: [closed]
+
+permissions:
+  issues: write
+  pull-requests: read
+  contents: read
+
+jobs:
+  label-fix-version:
+    if: github.event.pull_request.merged == true
+    runs-on: ubuntu-latest
+    steps:
+      - name: Label linked issues
+        env:
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          REPO: ${{ github.repository }}
+          PR_NUMBER: ${{ github.event.pull_request.number }}
+          PR_TITLE: ${{ github.event.pull_request.title }}
+          BASE_REF: ${{ github.event.pull_request.base.ref }}
+          PR_AUTHOR: ${{ github.event.pull_request.user.login }}
+          PR_AUTHOR_TYPE: ${{ github.event.pull_request.user.type }}
+        run: |
+          set -euo pipefail
+
+          # 1. Collect issue numbers from the title and closing keywords. Title
+          #    ids may come as "[#1][#2]", "[#1 ][#2]" or "[#1, #2]"; the 
trailing
+          #    "(#PR)" is not in brackets and is ignored.
+          TITLE_ISSUES=$(printf '%s' "$PR_TITLE" | grep -oE '\[[^]]*\]' | grep 
-oE '#[0-9]+' \
+            | tr -d '#' || true)
+          CLOSING_ISSUES=$(gh api graphql \
+            -F owner="${REPO%/*}" -F name="${REPO#*/}" -F number="$PR_NUMBER" \
+            -f query='
+              query($owner: String!, $name: String!, $number: Int!) {
+                repository(owner: $owner, name: $name) {
+                  pullRequest(number: $number) {
+                    closingIssuesReferences(first: 50) {
+                      nodes { number repository { nameWithOwner } }
+                    }
+                  }
+                }
+              }' \
+            --jq '.data.repository.pullRequest.closingIssuesReferences.nodes[]
+                  | select(.repository.nameWithOwner == env.REPO) | .number' 
|| true)
+          ISSUES=$(printf '%s\n%s\n' "$TITLE_ISSUES" "$CLOSING_ISSUES" | grep 
-E '^[0-9]+$' | sort -un || true)
+
+          if [ -z "$ISSUES" ]; then
+            echo "No linked issue found for PR #$PR_NUMBER, skipping."
+            exit 0
+          fi
+
+          # 2. Resolve the version to be released from the base branch.
+          VERSION=$(gh api 
"repos/$REPO/contents/gradle.properties?ref=$BASE_REF" --jq '.content' \
+            | base64 -d | sed -n 's/^version[[:space:]]*=[[:space:]]*//p' | tr 
-d '[:space:]' \
+            | sed 's/-SNAPSHOT$//')
+          if ! printf '%s' "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; 
then
+            echo "Unexpected version '$VERSION' on $BASE_REF, skipping."
+            exit 0
+          fi
+
+          # The release script bumps to the next SNAPSHOT right after tagging 
an
+          # RC, so while a release is being voted (RC tag exists but the final
+          # tag doesn't), fixes still target that release, e.g. 1.3.2-SNAPSHOT
+          # with v1.3.1-rc2 but no v1.3.1 -> "1.3.1".
+          TAGS=$(gh api --paginate 
"repos/$REPO/git/matching-refs/tags/v${VERSION%.*}." \
+            --jq '.[].ref | sub("^refs/tags/v"; "")')
+          PENDING=$(printf '%s\n' "$TAGS" | sed -n 's/-rc[0-9]*$//p' | sort 
-uV \

Review Comment:
   [P1] An RC tag without a final tag does not establish that this PR is in the 
eventual release. The [final tag is created from a selected RC 
commit](https://github.com/apache/gravitino/blob/9a8a847e403802216919b1f8379e042802768462/dev/release/release-build.sh#L110-L119).
 If this PR lands after the last RC and that RC passes, this adds a fix-version 
label even though the fix is absent. Please verify that the final release tag 
contains the merge commit before labeling it as shipped.



##########
.github/workflows/label-fix-version.yml:
##########
@@ -0,0 +1,149 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Label the issues fixed by a merged PR with the version that the PR's base
+# branch is going to release, e.g. main (2.0.0-SNAPSHOT) -> "2.0.0",
+# branch-1.2 (1.2.2-SNAPSHOT) -> "1.2.2". If a release on the base branch is
+# still in progress (RC tagged but not released), that release is used
+# instead, e.g. branch-1.3 (1.3.2-SNAPSHOT, v1.3.1-rc2 only) -> "1.3.1".
+# Unassigned issues are also assigned to the PR author.
+#
+# Issues are taken only from "[#123]" in the PR title and from the PR's
+# closing keywords (e.g. "Fix: #123"). PRs without an issue are skipped.
+#
+# This uses pull_request_target so that PRs from forks get a token that can
+# write labels. It never checks out PR code, and all PR-controlled values are
+# passed through env to avoid script injection.
+
+name: Label issues with fix version and assign author
+
+on:
+  pull_request_target:
+    types: [closed]
+
+permissions:
+  issues: write
+  pull-requests: read
+  contents: read
+
+jobs:
+  label-fix-version:
+    if: github.event.pull_request.merged == true
+    runs-on: ubuntu-latest
+    steps:
+      - name: Label linked issues
+        env:
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          REPO: ${{ github.repository }}
+          PR_NUMBER: ${{ github.event.pull_request.number }}
+          PR_TITLE: ${{ github.event.pull_request.title }}
+          BASE_REF: ${{ github.event.pull_request.base.ref }}
+          PR_AUTHOR: ${{ github.event.pull_request.user.login }}
+          PR_AUTHOR_TYPE: ${{ github.event.pull_request.user.type }}
+        run: |
+          set -euo pipefail
+
+          # 1. Collect issue numbers from the title and closing keywords. Title
+          #    ids may come as "[#1][#2]", "[#1 ][#2]" or "[#1, #2]"; the 
trailing
+          #    "(#PR)" is not in brackets and is ignored.
+          TITLE_ISSUES=$(printf '%s' "$PR_TITLE" | grep -oE '\[[^]]*\]' | grep 
-oE '#[0-9]+' \
+            | tr -d '#' || true)
+          CLOSING_ISSUES=$(gh api graphql \
+            -F owner="${REPO%/*}" -F name="${REPO#*/}" -F number="$PR_NUMBER" \
+            -f query='
+              query($owner: String!, $name: String!, $number: Int!) {
+                repository(owner: $owner, name: $name) {
+                  pullRequest(number: $number) {
+                    closingIssuesReferences(first: 50) {
+                      nodes { number repository { nameWithOwner } }
+                    }
+                  }
+                }
+              }' \
+            --jq '.data.repository.pullRequest.closingIssuesReferences.nodes[]
+                  | select(.repository.nameWithOwner == env.REPO) | .number' 
|| true)
+          ISSUES=$(printf '%s\n%s\n' "$TITLE_ISSUES" "$CLOSING_ISSUES" | grep 
-E '^[0-9]+$' | sort -un || true)
+
+          if [ -z "$ISSUES" ]; then
+            echo "No linked issue found for PR #$PR_NUMBER, skipping."
+            exit 0
+          fi
+
+          # 2. Resolve the version to be released from the base branch.
+          VERSION=$(gh api 
"repos/$REPO/contents/gradle.properties?ref=$BASE_REF" --jq '.content' \

Review Comment:
   [P2] This reads the moving branch ref, while the RC check uses current tags. 
After v1.3.1 is finalized, rerunning a branch-1.3 PR that originally got 1.3.1 
will also add 1.3.2: the branch is at 1.3.2-SNAPSHOT and the pending RC is 
gone. Please make version resolution stable for a given merge event.



##########
.github/workflows/label-fix-version.yml:
##########
@@ -0,0 +1,149 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Label the issues fixed by a merged PR with the version that the PR's base
+# branch is going to release, e.g. main (2.0.0-SNAPSHOT) -> "2.0.0",
+# branch-1.2 (1.2.2-SNAPSHOT) -> "1.2.2". If a release on the base branch is
+# still in progress (RC tagged but not released), that release is used
+# instead, e.g. branch-1.3 (1.3.2-SNAPSHOT, v1.3.1-rc2 only) -> "1.3.1".
+# Unassigned issues are also assigned to the PR author.
+#
+# Issues are taken only from "[#123]" in the PR title and from the PR's
+# closing keywords (e.g. "Fix: #123"). PRs without an issue are skipped.
+#
+# This uses pull_request_target so that PRs from forks get a token that can
+# write labels. It never checks out PR code, and all PR-controlled values are
+# passed through env to avoid script injection.
+
+name: Label issues with fix version and assign author
+
+on:
+  pull_request_target:
+    types: [closed]
+
+permissions:
+  issues: write
+  pull-requests: read
+  contents: read
+
+jobs:
+  label-fix-version:
+    if: github.event.pull_request.merged == true
+    runs-on: ubuntu-latest
+    steps:
+      - name: Label linked issues
+        env:
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          REPO: ${{ github.repository }}
+          PR_NUMBER: ${{ github.event.pull_request.number }}
+          PR_TITLE: ${{ github.event.pull_request.title }}
+          BASE_REF: ${{ github.event.pull_request.base.ref }}
+          PR_AUTHOR: ${{ github.event.pull_request.user.login }}
+          PR_AUTHOR_TYPE: ${{ github.event.pull_request.user.type }}
+        run: |
+          set -euo pipefail
+
+          # 1. Collect issue numbers from the title and closing keywords. Title
+          #    ids may come as "[#1][#2]", "[#1 ][#2]" or "[#1, #2]"; the 
trailing
+          #    "(#PR)" is not in brackets and is ignored.
+          TITLE_ISSUES=$(printf '%s' "$PR_TITLE" | grep -oE '\[[^]]*\]' | grep 
-oE '#[0-9]+' \
+            | tr -d '#' || true)
+          CLOSING_ISSUES=$(gh api graphql \
+            -F owner="${REPO%/*}" -F name="${REPO#*/}" -F number="$PR_NUMBER" \
+            -f query='
+              query($owner: String!, $name: String!, $number: Int!) {
+                repository(owner: $owner, name: $name) {
+                  pullRequest(number: $number) {
+                    closingIssuesReferences(first: 50) {

Review Comment:
   [P2] [GitHub ignores closing keywords when a PR targets a non-default 
branch](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue).
 For a branch-1.3 PR without a bracketed issue ID in its title but with Fixes 
#N in its body, this field is empty and the workflow exits without labeling the 
issue. Please parse the body for release branches or require the title format.



-- 
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