kou commented on code in PR #55484: URL: https://github.com/apache/arrow/pull/55484#discussion_r4652097459
########## .github/workflows/dev_pr_merged.yml: ########## @@ -0,0 +1,110 @@ +# 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. + +name: Dev PR merged + +on: + push: + branches: + - main + +permissions: + contents: read + issues: write + +jobs: + update: + name: Update issue + if: github.repository == 'apache/arrow' + runs-on: ubuntu-latest + env: + GH_REPO: ${{ github.repository }} + GH_TOKEN: ${{ github.token }} + steps: + # GitHub closes the issue of a "GH-XXX: ..." pull request on merge + # because of "* GitHub Issue: Closes #XXX" in the pull request + # description. The following steps set what GitHub doesn't set: + # the assignee and the milestone of the issue. + - name: Get issue + id: issue + env: + MESSAGE: ${{ github.event.head_commit.message }} + run: | + set -euo pipefail + + title=${MESSAGE%%$'\n'*} + if [[ ! "${title}" =~ ^GH-([0-9]+) ]]; then + echo "No GitHub issue in the commit title: ${title}" + exit 0 + fi + issue_number=${BASH_REMATCH[1]} + issue=$(gh api "repos/${GH_REPO}/issues/${issue_number}") + if [ "$(jq 'has("pull_request")' <<< "${issue}")" = "true" ]; then + echo "#${issue_number} is a pull request, not an issue." + exit 0 + fi + # The issue is open if the pull request description didn't + # have "Closes #XXX", for example for a partial fix. + if [ "$(jq -r .state <<< "${issue}")" != "closed" ]; then + echo "::notice::#${issue_number} is still open. It isn't updated." + exit 0 + fi + + # The following steps don't run without these outputs. + { + echo "number=${issue_number}" + echo "n_assignees=$(jq '.assignees | length' <<< "${issue}")" + echo "has_milestone=$(jq '.milestone != null' <<< "${issue}")" + } | tee -a "${GITHUB_OUTPUT}" + # Assign the issue to the commit author, who is the pull request + # author for a squash merge, if it isn't assigned to anyone. + # GitHub ignores this silently if the author can't be assigned. + - name: Assign issue + if: >- + steps.issue.outputs.n_assignees == '0' && + github.event.head_commit.author.username + env: + AUTHOR: ${{ github.event.head_commit.author.username }} + ISSUE_NUMBER: ${{ steps.issue.outputs.number }} + run: | + gh api "repos/${GH_REPO}/issues/${ISSUE_NUMBER}/assignees" \ + -f "assignees[]=${AUTHOR}" > /dev/null Review Comment: I think that we don't need issue assignees. We don't use them and we can compute them by PR author. ########## .github/pull_request_template.md: ########## @@ -34,4 +34,10 @@ In accordance to the [AI generation guidelines](https://arrow.apache.org/docs/de - [ ] AI - [ ] Not reviewed +<!-- +The line below is filled in automatically from the PR title. For a PR to main +it says "Closes #XXX" and GitHub closes the issue when the PR is merged. If +your PR fixes only a part of the issue, change "Closes" to "Refs" so that the +issue stays open. +--> * GitHub Issue: (filled in automatically from the PR title) Review Comment: Can we use the `(...)` part instead of the `<!-- ... -->` part for this note? I think that most contributors will not remove the `<!-- ... -->` part and most merged messages will include the `<!-- ... -->` part... ########## .github/workflows/dev_pr_merged.yml: ########## @@ -0,0 +1,110 @@ +# 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. + +name: Dev PR merged + +on: + push: + branches: + - main + +permissions: + contents: read + issues: write + +jobs: + update: + name: Update issue + if: github.repository == 'apache/arrow' + runs-on: ubuntu-latest + env: + GH_REPO: ${{ github.repository }} + GH_TOKEN: ${{ github.token }} + steps: + # GitHub closes the issue of a "GH-XXX: ..." pull request on merge + # because of "* GitHub Issue: Closes #XXX" in the pull request + # description. The following steps set what GitHub doesn't set: + # the assignee and the milestone of the issue. + - name: Get issue + id: issue + env: + MESSAGE: ${{ github.event.head_commit.message }} + run: | + set -euo pipefail + + title=${MESSAGE%%$'\n'*} + if [[ ! "${title}" =~ ^GH-([0-9]+) ]]; then + echo "No GitHub issue in the commit title: ${title}" + exit 0 + fi + issue_number=${BASH_REMATCH[1]} + issue=$(gh api "repos/${GH_REPO}/issues/${issue_number}") + if [ "$(jq 'has("pull_request")' <<< "${issue}")" = "true" ]; then + echo "#${issue_number} is a pull request, not an issue." + exit 0 + fi + # The issue is open if the pull request description didn't + # have "Closes #XXX", for example for a partial fix. + if [ "$(jq -r .state <<< "${issue}")" != "closed" ]; then + echo "::notice::#${issue_number} is still open. It isn't updated." + exit 0 + fi + + # The following steps don't run without these outputs. + { + echo "number=${issue_number}" + echo "n_assignees=$(jq '.assignees | length' <<< "${issue}")" + echo "has_milestone=$(jq '.milestone != null' <<< "${issue}")" + } | tee -a "${GITHUB_OUTPUT}" + # Assign the issue to the commit author, who is the pull request + # author for a squash merge, if it isn't assigned to anyone. + # GitHub ignores this silently if the author can't be assigned. + - name: Assign issue + if: >- + steps.issue.outputs.n_assignees == '0' && + github.event.head_commit.author.username + env: + AUTHOR: ${{ github.event.head_commit.author.username }} + ISSUE_NUMBER: ${{ steps.issue.outputs.number }} + run: | + gh api "repos/${GH_REPO}/issues/${ISSUE_NUMBER}/assignees" \ + -f "assignees[]=${AUTHOR}" > /dev/null + # Keep the milestone of the issue. If the issue doesn't have a + # milestone, use the next major release that doesn't have a + # maintenance branch yet like dev/merge_arrow_pr.py does. + - name: Set milestone + if: steps.issue.outputs.has_milestone == 'false' + env: + ISSUE_NUMBER: ${{ steps.issue.outputs.number }} + run: | + set -euo pipefail + + maintenance_versions=$( + gh api --paginate "repos/${GH_REPO}/git/matching-refs/heads/maint-" \ + --jq '.[].ref | ltrimstr("refs/heads/maint-")') + major_versions=$( + gh api --paginate "repos/${GH_REPO}/milestones?per_page=100" \ + --jq '.[] | select(.title | test("^[0-9]+\\.0\\.0$")) | "\(.title):\(.number)"' | + sort -V) + for major_version in ${major_versions}; do + if ! grep -qxF "${major_version%:*}" <<< "${maintenance_versions}"; then + echo "Milestone: ${major_version%:*}" + gh api -X PATCH "repos/${GH_REPO}/issues/${ISSUE_NUMBER}" \ + -F "milestone=${major_version#*:}" > /dev/null + break + fi + done Review Comment: How about setting milestones by a scheduled `archery` job instead of the `push` triggered `dev_pr_merged.yml`? For example, we can add `archery release update-milestones` (or `archery release curate --fix`) and run it by `schedule` and `workflow_dispatch`: 1. Collect `GH-XXX` from the commit titles in `apache-arrow-${PREVIOUS_MAJOR_VERSION}..main` 2. Find closed issues without milestone in them 3. Set a milestone based on where the commit is: * If the commit is included in `maint-X.0.x`: `X.0.0` * Otherwise: The next major version that doesn't have its maintenance branch yet Benefits: * We don't need to care about the race between our workflow and GitHub's auto close by `Closes #XXX`. The current workflow skips the issue when it's still open. * We can recover missed cases automatically: merged with `[skip ci]`, Boring Cyborg was down and the issue was closed manually later, merged by the merge script and so on. The job is idempotent. * We can use the commit graph instead of guessing "the next major version" at merge time. If a maintenance branch is created after a merge, the current approach in a scheduled job would choose a wrong version but the commit graph doesn't. * We can implement and test the logic in Python. `archery release curate` already compares commits and milestones. We don't change existing milestones. So if a committer wants to backport a fix, the committer can still set the milestone for the maintenance release before or after merging. The release manager can also run the job manually by `workflow_dispatch` before `archery release curate`/`archery release cherry-pick`. ########## .github/workflows/dev_pr_merged.yml: ########## @@ -0,0 +1,110 @@ +# 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. + +name: Dev PR merged + +on: + push: + branches: + - main + +permissions: + contents: read + issues: write + +jobs: + update: + name: Update issue + if: github.repository == 'apache/arrow' + runs-on: ubuntu-latest + env: + GH_REPO: ${{ github.repository }} + GH_TOKEN: ${{ github.token }} + steps: + # GitHub closes the issue of a "GH-XXX: ..." pull request on merge + # because of "* GitHub Issue: Closes #XXX" in the pull request + # description. The following steps set what GitHub doesn't set: + # the assignee and the milestone of the issue. + - name: Get issue + id: issue + env: + MESSAGE: ${{ github.event.head_commit.message }} + run: | + set -euo pipefail + + title=${MESSAGE%%$'\n'*} + if [[ ! "${title}" =~ ^GH-([0-9]+) ]]; then + echo "No GitHub issue in the commit title: ${title}" + exit 0 + fi + issue_number=${BASH_REMATCH[1]} + issue=$(gh api "repos/${GH_REPO}/issues/${issue_number}") Review Comment: Can we use `gh issue view`? -- 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]
