update_changelog.yml 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. name: Update Changelog
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. type:
  6. description: "Type of when to retreive commits from"
  7. options: ["date", "tag", "commit"]
  8. required: true
  9. type: choice
  10. default: "date"
  11. start:
  12. description: "Date '2021-01-01' or tag 'v1.0.0' or commit 'sha'"
  13. required: true
  14. changelog_path:
  15. description: "The value associated with the type."
  16. required: true
  17. default: "CHANGELOG.md"
  18. prefix:
  19. description: "Prefix for the changelog update"
  20. required: true
  21. default: "changelog-for-"
  22. env:
  23. GH_TOKEN: ${{ secrets.YDBOT_TOKEN }}
  24. jobs:
  25. gather-prs:
  26. runs-on: ubuntu-latest
  27. outputs:
  28. prs: ${{ steps.pr-list.outputs.prs }}
  29. steps:
  30. - name: Check out repository
  31. uses: actions/checkout@v4
  32. - name: Get merged PRs
  33. id: pr-list
  34. run: |
  35. TYPE="${{ github.event.inputs.type }}"
  36. START="${{ github.event.inputs.start }}"
  37. BRANCH="${GITHUB_REF_NAME}"
  38. echo "::notice:: branch = ${GITHUB_REF_NAME}, start = $START"
  39. if [ "$TYPE" == "date" ]; then
  40. echo "Getting PRs since date: $START"
  41. PRS=$(gh pr list --state merged --json number,title,baseRefName,mergedAt --jq ".[] | select(.baseRefName == \"$BRANCH\" and .mergedAt >= \"$START\") | {id: .number}" | jq -c -s ".")
  42. elif [ "$TYPE" == "tag" ]; then
  43. echo "Fetching tags from remote"
  44. git fetch --tags
  45. echo "Getting PRs since tag: $START"
  46. COMMIT=$(git rev-list -n 1 $START)
  47. PRS=$(gh pr list --state merged --json number,title,baseRefName,mergedAt --jq ".[] | select(.baseRefName == \"$BRANCH\" and .mergeCommit.oid >= \"$COMMIT\") | {id: .number}" | jq -c -s ".")
  48. elif [ "$TYPE" == "commit" ]; then
  49. echo "Getting PRs since commit: $START"
  50. PRS=$(gh pr list --state merged --json number,title,baseRefName,mergedAt --jq ".[] | select(.baseRefName == \"$BRANCH\" and .mergeCommit.oid >= \"$START\") | {id: .number}" | jq -c -s ".")
  51. else
  52. echo "::error::Invalid type: $TYPE"
  53. exit 1
  54. fi
  55. if [ -z "$PRS" ]; then
  56. PRS="[]"
  57. fi
  58. echo "$PRS" > prs.json
  59. echo "prs=$PRS" >> "$GITHUB_OUTPUT"
  60. - name: Debug PR list output
  61. run: |
  62. cat prs.json
  63. - name: Upload PRs JSON
  64. uses: actions/upload-artifact@v4
  65. with:
  66. name: prs-json
  67. path: prs.json
  68. update-changelog:
  69. needs: gather-prs
  70. runs-on: ubuntu-latest
  71. steps:
  72. - name: Check out the repository
  73. uses: actions/checkout@v4
  74. - name: Update Changelog
  75. uses: ./.github/actions/update_changelog
  76. env:
  77. YDBOT_TOKEN: ${{ secrets.YDBOT_TOKEN }}
  78. with:
  79. pr_data: "${{ needs.gather-prs.outputs.prs }}"
  80. changelog_path: "${{ github.event.inputs.changelog_path }}"
  81. base_branch: "${GITHUB_REF_NAME}"
  82. suffix: "${{ github.event.inputs.start }}"