Skip to content

Commit

Permalink
chore: enhance auto-labeling in the repo (#2237)
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed AbouZaid <[email protected]>
  • Loading branch information
aabouzaid authored Aug 19, 2024
1 parent b795cfe commit 0a77030
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 35 deletions.
16 changes: 0 additions & 16 deletions .github/PULL_REQUEST_TEMPLATE/release_template.md

This file was deleted.

14 changes: 14 additions & 0 deletions .github/config/issue-labeler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
support:
- 'SUPPORT-\d+'

platform/aws:
- '/Platform:.*(AWS|EKS).*/i'

platform/gcp:
- '/Platform:.*(GCP|GKE).*/i'

platform/openshift:
- '/Platform:.*OpenShift.*/i'

platform/local:
- '/Platform:.*(KIND|K3d|Local).*/i'
83 changes: 83 additions & 0 deletions .github/config/pr-labeler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#
# Components.

component/connectors:
- changed-files:
- any-glob-to-any-file:
- 'charts/camunda-platform-*/templates/connectors/**'

component/console:
- changed-files:
- any-glob-to-any-file:
- 'charts/camunda-platform-*/templates/console/**'

component/identity:
- changed-files:
- any-glob-to-any-file:
- 'charts/camunda-platform-*/templates/identity/**'
- 'charts/camunda-platform-*/charts/identity/**'

component/operate:
- changed-files:
- any-glob-to-any-file:
- 'charts/camunda-platform-*/templates/operate/**'
- 'charts/camunda-platform-*/charts/operate/**'

component/optimize:
- changed-files:
- any-glob-to-any-file:
- 'charts/camunda-platform-*/templates/optimize/**'
- 'charts/camunda-platform-*/charts/optimize/**'

component/monitoring:
- changed-files:
- any-glob-to-any-file:
- 'charts/camunda-platform-*/templates/service-monitor/**'

component/tasklist:
- changed-files:
- any-glob-to-any-file:
- 'charts/camunda-platform-*/templates/tasklist/**'
- 'charts/camunda-platform-*/charts/tasklist/**'

component/web-modeler:
- changed-files:
- any-glob-to-any-file:
- 'charts/camunda-platform-*/templates/web-modeler/**'

component/zeebe:
- changed-files:
- any-glob-to-any-file:
- 'charts/camunda-platform-*/templates/zeebe/**'
- 'charts/camunda-platform-*/charts/zeebe/**'
- 'charts/camunda-platform-*/templates/zeebe-gateway/**'
- 'charts/camunda-platform-*/charts/zeebe-gateway/**'
#
# Tools.

tool/github-actions:
- changed-files:
- any-glob-to-any-file:
- '.github/actions/**'
- '.github/workflows/**'

tool/release-please:
- changed-files:
- any-glob-to-any-file:
- '.github/config/release-please/**'

tool/renovatebot:
- changed-files:
- any-glob-to-any-file:
- '.github/renovate.json5'

tool/asdf:
- changed-files:
- any-glob-to-any-file:
- '.tool-versions'

tool/script:
- changed-files:
- any-glob-to-any-file:
- 'Makefile'
- 'scripts/**'
3 changes: 3 additions & 0 deletions .github/workflows/chart-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ jobs:
timeout_minutes: 5
retry_wait_seconds: 10
command: make release.verify-components-version
- name: Label PRs with app and chart version
run: |
make release.set-prs-version-label
- name: Generate version matrix
run: |
make helm.repos-add
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/chart-validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
workflow_dispatch:
pull_request:
paths:
- '.github/**'
- '.tool-versions'
- 'charts/camunda-platform*/**'

Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/repo-issue-labeler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Repo - Issue Labels

on:
issues:
types:
- opened
- edited

permissions:
issues: write
contents: read

jobs:
issue-labeler:
runs-on: ubuntu-latest
steps:
- name: Run Issue Labeler
uses: github/issue-labeler@c1b0f9f52a63158c4adc09425e858e87b32e9685 # v3.4
with:
configuration-path: .github/config/issue-labeler.yaml
enable-versioned-regex: 0
repo-token: "${{ github.token }}"
16 changes: 16 additions & 0 deletions .github/workflows/repo-pr-labeler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Repo - Pull Request Labels

on:
pull_request_target:

jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Run Labeler
uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5
with:
configuration-path: .github/config/pr-labeler.yaml
22 changes: 4 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,6 @@ release.generate-and-commit: release.generate-notes
git add $(chartPath);\
git commit -m "chore: add generated files for camunda-platform $(chartVersion)"

.PHONY: release.generate-pr-url
release.generate-pr-url:
@echo "\n\n###################################\n"
@echo "Open the release PR using this URL:"
@echo "https://github.com/camunda/camunda-platform-helm/compare/main...release?expand=1&template=release_template.md&title=Release%20Camunda%20Platform%20Helm%20Chart%20v$(chartVersion)&labels=camunda-platform,chore"
@echo "\n###################################\n\n"

.PHONY: release.chores
release.chores:
git checkout main
git pull --tags
git switch -C release
@$(MAKE) release.bump-chart-version-and-commit
@$(MAKE) release.generate-and-commit
git push -fu origin release
@$(MAKE) release.generate-pr-url
git checkout main

.PHONY: release.verify-components-version
release.verify-components-version:
@bash scripts/verify-components-version.sh
Expand All @@ -226,3 +208,7 @@ release.generate-version-matrix-released:
release.generate-version-matrix-unreleased:
@bash scripts/generate-version-matrix.sh --init
@bash scripts/generate-version-matrix.sh --unreleased

.PHONY: release.set-prs-version-label
release.set-prs-version-label:
@bash scripts/set-prs-version-label.sh
77 changes: 77 additions & 0 deletions scripts/set-prs-version-label.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# A script to label PRs based on the app and chart version.
# It meant to run in the post-release workflow and before merging the release PR.

#!/bin/bash
set -euo pipefail

# Init.
# Check dependencies.
dep_names="ct gh git git-cliff grep jq yq"
for dep_name in ${dep_names}; do
test -n "$(which ${dep_name})" || (
echo "Missing dependency: ${dep_name}";
echo "Dependencies list: ${dep_names}";
exit 1
)
done
# Ensure that the main branch is there.
test "$(git branch --show-current)" != "main" &&
git fetch origin main:main --no-tags

# Vars.
release_please_config=".github/config/release-please/release-please-config.json"
latest_release_commit="$(git show main:${release_please_config} | jq -r '."bootstrap-sha"')"
cliff_config_file=".github/config/cliff.toml"

# Get PRs from commits in a certain chart dir.
get_prs_per_chart_dir () {
chart_dir="${1}"
git-cliff --context \
--config "${cliff_config_file}" \
--include-path "${chart_dir}/**" \
${latest_release_commit}.. |
jq '.[].commits[].message' | grep -Po '(?<=#)\d+'
}

# Get the issues fixed by a PR.
# Note: GH CLI doesn't support this so we use the API call directly.
# https://github.com/cli/cli/discussions/7097#discussioncomment-5229031
get_issues_per_pr () {
pr_nubmer="${1}"
gh api graphql -F owner='camunda' -F repo='camunda-platform-helm' -F pr="${pr_nubmer}" -f query='
query ($owner: String!, $repo: String!, $pr: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr) {
closingIssuesReferences(first: 100) {
nodes {
number
}
}
}
}
}' --jq '.data.repository.pullRequest.closingIssuesReferences.nodes[].number'
}

# Run.
# Label PRs with the app and chart version only if there is a change in the chart.
ct list-changed | while read chart_dir; do
app_version="$(yq '.appVersion | sub("\..$", "")' ${chart_dir}/Chart.yaml)"
chart_version="$(yq '.version' ${chart_dir}/Chart.yaml)"
app_version_label="version/${app_version}"
# The "version:x.y.z" label format is used by the support team,
# it must not changed without checking with the support team.
chart_version_label="version:${chart_version}"

echo -e "\nChart dir: ${chart_dir}"
echo "Apps version: ${app_version}"
echo "Chart version: ${chart_version}"
get_prs_per_chart_dir "${chart_dir}" | while read pr_nubmer; do
# Label PR.
gh pr edit "${pr_nubmer}" --add-label "${app_version_label},${chart_version_label}"
# Label the PR's corresponding issue.
# TODO: Update the logic to work with multi issues (usually we don't have that).
issue_nubmer="$(get_issues_per_pr ${pr_nubmer})"
test -n "${issue_nubmer}" &&
gh issue edit "${issue_nubmer}" --add-label "${app_version_label},${chart_version_label}"
done
done

0 comments on commit 0a77030

Please sign in to comment.