edit-dependabot-pr.yml 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. permissions: write-all
  14. steps:
  15. - uses: actions/checkout@v4
  16. with:
  17. show-progress: false
  18. - uses: actions/setup-java@v4
  19. with:
  20. distribution: temurin
  21. java-version: 17
  22. - name: Dependabot metadata
  23. id: metadata
  24. uses: dependabot/fetch-metadata@v1
  25. with:
  26. github-token: ${{ env.GH_TOKEN }}
  27. - name: Set Milestone to Dependabot pull request
  28. id: set-milestone
  29. run: |
  30. if test -f pom.xml
  31. then
  32. CURRENT_VERSION=$(mvn help:evaluate -Dexpression="project.version" -q -DforceStdout)
  33. else
  34. CURRENT_VERSION=$(cat gradle.properties | sed -n '/^version=/ { s/^version=//;p }')
  35. fi
  36. export CANDIDATE_VERSION=${CURRENT_VERSION/-SNAPSHOT}
  37. MILESTONE=$(gh api repos/$GITHUB_REPOSITORY/milestones --jq 'map(select(.due_on != null and (.title | startswith(env.CANDIDATE_VERSION)))) | .[0] | .title')
  38. if [ -z $MILESTONE ]
  39. then
  40. gh run cancel ${{ github.run_id }}
  41. echo "::warning title=Cannot merge::No scheduled milestone for $CURRENT_VERSION version"
  42. else
  43. gh pr edit ${{ github.event.pull_request.number }} --milestone $MILESTONE
  44. echo mergeEnabled=true >> $GITHUB_OUTPUT
  45. fi