edit-dependabot-pr.yml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # This workflow is an adaptation from https://github.com/spring-projects/spring-integration/blob/main/.github/workflows/merge-dependabot-pr.yml
  2. # and https://github.com/spring-io/spring-github-workflows/blob/main/.github/workflows/spring-merge-dependabot-pr.yml
  3. name: Edit Dependabot PR
  4. on:
  5. pull_request:
  6. run-name: Edit Dependabot PR ${{ github.ref_name }}
  7. env:
  8. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  9. jobs:
  10. edit-dependabot-pr:
  11. runs-on: ubuntu-latest
  12. if: github.actor == 'dependabot[bot]'
  13. steps:
  14. - uses: actions/checkout@v4
  15. with:
  16. show-progress: false
  17. - uses: actions/setup-java@v4
  18. with:
  19. distribution: temurin
  20. java-version: 17
  21. - name: Dependabot metadata
  22. id: metadata
  23. uses: dependabot/fetch-metadata@v1
  24. with:
  25. github-token: ${{ env.GH_TOKEN }}
  26. - name: Set Milestone to Dependabot pull request
  27. id: set-milestone
  28. run: |
  29. if test -f pom.xml
  30. then
  31. CURRENT_VERSION=$(mvn help:evaluate -Dexpression="project.version" -q -DforceStdout)
  32. else
  33. CURRENT_VERSION=$(cat gradle.properties | sed -n '/^version=/ { s/^version=//;p }')
  34. fi
  35. export CANDIDATE_VERSION=${CURRENT_VERSION/-SNAPSHOT}
  36. MILESTONE=$(gh api repos/$GITHUB_REPOSITORY/milestones --jq 'map(select(.due_on != null and (.title | startswith(env.CANDIDATE_VERSION)))) | .[0] | .title')
  37. if [ -z $MILESTONE ]
  38. then
  39. gh run cancel ${{ github.run_id }}
  40. echo "::warning title=Cannot merge::No scheduled milestone for $CURRENT_VERSION version"
  41. else
  42. gh pr edit ${{ github.event.pull_request.number }} --milestone $MILESTONE
  43. echo mergeEnabled=true >> $GITHUB_OUTPUT
  44. fi