2023-12-04 07:41:09 +00:00
|
|
|
name: Labeller
|
2023-11-28 07:47:35 +00:00
|
|
|
on:
|
|
|
|
pull_request_target:
|
|
|
|
types: closed
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
label:
|
|
|
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
issues: write
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
with:
|
|
|
|
sparse-checkout: .github/scripts
|
|
|
|
- name: Add release labels on merge
|
|
|
|
run: |
|
|
|
|
PR_NUMBER="${{ github.event.pull_request.number }}"
|
|
|
|
|
|
|
|
echo "Base REF: $GITHUB_BASE_REF"
|
2023-12-01 07:10:54 +00:00
|
|
|
echo "**Branch:** [$GITHUB_BASE_REF](https://github.com/$GITHUB_REPOSITORY/tree/$GITHUB_BASE_REF)" >> $GITHUB_STEP_SUMMARY
|
2023-11-28 07:47:35 +00:00
|
|
|
echo "PR: https://github.com/$GITHUB_REPOSITORY/pull/$PR_NUMBER"
|
2023-12-01 07:10:54 +00:00
|
|
|
echo "**PR:** [$PR_NUMBER](https://github.com/$GITHUB_REPOSITORY/pull/$PR_NUMBER)" >> $GITHUB_STEP_SUMMARY
|
2023-11-28 07:47:35 +00:00
|
|
|
|
|
|
|
if [ "$GITHUB_BASE_REF" == "main" ]; then
|
2024-10-08 07:00:59 +00:00
|
|
|
LAST_RELEASE="$(gh api /repos/$GITHUB_REPOSITORY/branches --paginate --jq .[].name | grep '^release/' | cut -d '/' -f 2 | sort -n -r | head -n 1)"
|
|
|
|
LAST_MINOR=$(echo $LAST_MINOR | cut -d '.' -f 2)
|
|
|
|
NEXT_MAJOR=$(echo $LAST_RELEASE | cut -d '.' -f 1)
|
|
|
|
NEXT_MINOR="$(($LAST_MINOR + 1))"
|
|
|
|
LABEL="release/$NEXT_MAJOR.$NEXT_MINOR.0"
|
2023-11-28 07:47:35 +00:00
|
|
|
BACKPORT_LABEL="backport/main"
|
|
|
|
elif [[ "$GITHUB_BASE_REF" = release/* ]]; then
|
|
|
|
MAJOR_MINOR="$(echo $GITHUB_BASE_REF | cut -d '/' -f 2)"
|
2024-05-21 05:46:10 +00:00
|
|
|
LAST_MICRO="$(gh api /repos/$GITHUB_REPOSITORY/tags --jq .[].name | sort -V -r | grep $MAJOR_MINOR | head -n 1 | cut -d '.' -f 3)"
|
2023-11-28 07:47:35 +00:00
|
|
|
NEXT_MICRO="$(($LAST_MICRO + 1))"
|
|
|
|
LABEL="release/$MAJOR_MINOR.$NEXT_MICRO"
|
|
|
|
BACKPORT_LABEL="backport/$MAJOR_MINOR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Label: $LABEL"
|
2023-12-01 07:10:54 +00:00
|
|
|
echo "**Label:** [$LABEL](https://github.com/$GITHUB_REPOSITORY/labels/$(echo $LABEL | sed 's|/|%2F|g'))" >> $GITHUB_STEP_SUMMARY
|
2023-11-28 07:47:35 +00:00
|
|
|
|
|
|
|
gh api "repos/$GITHUB_REPOSITORY/labels/$(echo $LABEL | sed 's|/|%2F|g')" --silent 2>/dev/null || gh label create -R "$GITHUB_REPOSITORY" "$LABEL" -c "0E8A16"
|
|
|
|
|
|
|
|
echo ""
|
2023-12-01 07:10:54 +00:00
|
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
2023-11-28 07:47:35 +00:00
|
|
|
echo "Updating issues:"
|
2023-12-01 07:10:54 +00:00
|
|
|
echo "**Updating issues:**" >> $GITHUB_STEP_SUMMARY
|
|
|
|
|
2023-11-28 07:47:35 +00:00
|
|
|
ISSUES=$(.github/scripts/pr-find-issues.sh "$PR_NUMBER" "$GITHUB_REPOSITORY")
|
|
|
|
for ISSUE in $ISSUES; do
|
|
|
|
gh issue edit "$ISSUE" -R "$GITHUB_REPOSITORY" --add-label "$LABEL" --remove-label "$BACKPORT_LABEL"
|
2023-12-01 07:10:54 +00:00
|
|
|
echo "* [$ISSUE](https://github.com/$GITHUB_REPOSITORY/issues/$ISSUE)" >> $GITHUB_STEP_SUMMARY
|
2023-11-28 07:47:35 +00:00
|
|
|
done
|
|
|
|
if: github.repository == 'keycloak/keycloak' && github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.merged == true
|
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|