Skip to content

datastore: UNION ALL for mysql list entries query #33

datastore: UNION ALL for mysql list entries query

datastore: UNION ALL for mysql list entries query #33

name: Dependabot Milestone
on:
pull_request_target:
types: [opened, reopened]
permissions:
contents: read
issues: write
jobs:
assign-milestone:
name: assign-milestone
runs-on: ubuntu-22.04
# Only act on PRs opened by Dependabot. pull_request_target runs in
# the base branch context, so GITHUB_TOKEN can write to issues and
# pull requests, and the PR branch code never executes here.
if: github.event.pull_request.user.login == 'dependabot[bot]'
steps:
- name: Assign milestone
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail
# Read the base version from source to find the correct milestone.
BASE_VERSION=$(gh api "repos/${REPO}/contents/pkg/common/version/version.go" \
--jq '.content' | base64 -d | grep -oP 'Base = "\K[^"]+')
echo "Base version: ${BASE_VERSION}"
# Determine whether to use >= or > BASE_VERSION when searching for
# the target milestone. The release process creates the branch
# release/v{BASE_VERSION} one week before the actual release, at the
# moment the release candidate commit is picked. Once that branch
# exists, commits on main are destined for the next release, so we
# skip the BASE_VERSION milestone and target the one after it.
RELEASE_BRANCH="release/v${BASE_VERSION}"
if gh api "repos/${REPO}/branches/${RELEASE_BRANCH}" > /dev/null 2>&1; then
echo "Release branch ${RELEASE_BRANCH} exists: targeting milestone > ${BASE_VERSION}"
REQUIRE_GT=true
else
echo "Release branch ${RELEASE_BRANCH} does not exist: targeting milestone >= ${BASE_VERSION}"
REQUIRE_GT=false
fi
# Fetch all open milestones. Milestone titles may have an optional
# "v" prefix (e.g. "v1.15.0"); strip it before comparing so version
# sort works correctly.
MILESTONES=$(gh api "repos/${REPO}/milestones?state=open&per_page=100" \
--jq '[.[] | {number: .number, title: .title, version: (.title | ltrimstr("v"))}]')
MILESTONE_NUMBER=""
MILESTONE_TITLE=""
# Sort candidates by version ascending and pick the first eligible one.
while IFS= read -r entry; do
number=$(echo "$entry" | jq -r '.number')
title=$(echo "$entry" | jq -r '.title')
version=$(echo "$entry" | jq -r '.version')
min=$(printf '%s\n' "${BASE_VERSION}" "${version}" | sort -V | head -1)
if [ "${min}" = "${BASE_VERSION}" ]; then
if [ "${REQUIRE_GT}" = "true" ] && [ "${version}" = "${BASE_VERSION}" ]; then
continue # Skip exact match when a release branch exists.
fi
MILESTONE_NUMBER="$number"
MILESTONE_TITLE="$title"
break
fi
done < <(echo "$MILESTONES" | jq -c 'sort_by(.version | split(".") | map(tonumber)) | .[]')
if [ -z "$MILESTONE_NUMBER" ]; then
echo "Error: no eligible open milestone found"
exit 1
fi
echo "Assigning milestone '${MILESTONE_TITLE}' to PR #${PR_NUMBER}"
gh api --method PATCH "repos/${REPO}/issues/${PR_NUMBER}" \
--field "milestone=${MILESTONE_NUMBER}"