branch-created.yml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. name: Branch Created
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. branch-name:
  6. description: Branch name (e.g. `29-x-y`)
  7. required: true
  8. type: string
  9. create:
  10. permissions: {}
  11. jobs:
  12. release-branch-created:
  13. name: Release Branch Created
  14. if: ${{ github.event_name == 'workflow_dispatch' || (github.event.ref_type == 'branch' && endsWith(github.event.ref, '-x-y') && !startsWith(github.event.ref, 'roller')) }}
  15. permissions:
  16. contents: read
  17. pull-requests: write
  18. repository-projects: write # Required for labels
  19. runs-on: ubuntu-latest
  20. steps:
  21. - name: Determine Major Version
  22. id: check-major-version
  23. env:
  24. BRANCH_NAME: ${{ github.event.inputs.branch-name || github.event.ref }}
  25. run: |
  26. if [[ "$BRANCH_NAME" =~ ^([0-9]+)-x-y$ ]]; then
  27. echo "MAJOR=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
  28. else
  29. echo "Not a release branch: $BRANCH_NAME"
  30. fi
  31. - name: New Release Branch Tasks
  32. if: ${{ steps.check-major-version.outputs.MAJOR }}
  33. env:
  34. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  35. GH_REPO: electron/electron
  36. MAJOR: ${{ steps.check-major-version.outputs.MAJOR }}
  37. NUM_SUPPORTED_VERSIONS: 3
  38. run: |
  39. PREVIOUS_MAJOR=$((MAJOR - 1))
  40. UNSUPPORTED_MAJOR=$((MAJOR - NUM_SUPPORTED_VERSIONS - 1))
  41. # Create new labels
  42. gh label create $MAJOR-x-y --color 8d9ee8 || true
  43. gh label create target/$MAJOR-x-y --color ad244f --description "PR should also be added to the \"${MAJOR}-x-y\" branch." || true
  44. gh label create merged/$MAJOR-x-y --color 61a3c6 --description "PR was merged to the \"${MAJOR}-x-y\" branch." || true
  45. gh label create in-flight/$MAJOR-x-y --color db69a6 || true
  46. gh label create needs-manual-bp/$MAJOR-x-y --color 8b5dba || true
  47. # Change color of old labels
  48. gh label edit $UNSUPPORTED_MAJOR-x-y --color ededed || true
  49. gh label edit target/$UNSUPPORTED_MAJOR-x-y --color ededed || true
  50. gh label edit merged/$UNSUPPORTED_MAJOR-x-y --color ededed || true
  51. gh label edit in-flight/$UNSUPPORTED_MAJOR-x-y --color ededed || true
  52. gh label edit needs-manual-bp/$UNSUPPORTED_MAJOR-x-y --color ededed || true
  53. # Add the new target label to any PRs which:
  54. # * target the previous major
  55. # * are in-flight for the previous major
  56. # * need manual backport for the previous major
  57. for PREVIOUS_MAJOR_LABEL in target/$PREVIOUS_MAJOR-x-y in-flight/$PREVIOUS_MAJOR-x-y needs-manual-bp/$PREVIOUS_MAJOR-x-y; do
  58. PULL_REQUESTS=$(gh pr list --label $PREVIOUS_MAJOR_LABEL --jq .[].number --json number --limit 500)
  59. if [[ $PULL_REQUESTS ]]; then
  60. echo $PULL_REQUESTS | xargs -n 1 gh pr edit --add-label target/$MAJOR-x-y || true
  61. fi
  62. done
  63. - name: Generate GitHub App token
  64. if: ${{ steps.check-major-version.outputs.MAJOR }}
  65. uses: electron/github-app-auth-action@384fd19694fe7b6dcc9a684746c6976ad78228ae # v1.1.1
  66. id: generate-token
  67. with:
  68. creds: ${{ secrets.RELEASE_BOARD_GH_APP_CREDS }}
  69. org: electron
  70. - name: Generate Release Project Board Metadata
  71. if: ${{ steps.check-major-version.outputs.MAJOR }}
  72. uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
  73. id: generate-project-metadata
  74. with:
  75. script: |
  76. const major = ${{ steps.check-major-version.outputs.MAJOR }}
  77. const nextMajor = major + 1
  78. const prevMajor = major - 1
  79. core.setOutput("major", major)
  80. core.setOutput("next-major", nextMajor)
  81. core.setOutput("prev-major", prevMajor)
  82. core.setOutput("prev-prev-major", prevMajor - 1)
  83. core.setOutput("template-view", JSON.stringify({
  84. major,
  85. "next-major": nextMajor,
  86. "prev-major": prevMajor,
  87. }))
  88. - name: Create Release Project Board
  89. if: ${{ steps.check-major-version.outputs.MAJOR }}
  90. uses: dsanders11/project-actions/copy-project@438b25e007c2f4efec324497fadc6402e7cc61a6 # v1.4.0
  91. id: create-release-board
  92. with:
  93. drafts: true
  94. project-number: 64
  95. # TODO - Set to public once GitHub fixes their GraphQL bug
  96. # public: true
  97. # TODO - Enable once GitHub doesn't require overly broad, read
  98. # and write permission for repo "Contents" to link
  99. # link-to-repository: electron/electron
  100. template-view: ${{ steps.generate-project-metadata.outputs.template-view }}
  101. title: ${{ steps.generate-project-metadata.outputs.major }}-x-y
  102. token: ${{ steps.generate-token.outputs.token }}
  103. - name: Dump Release Project Board Contents
  104. if: ${{ steps.check-major-version.outputs.MAJOR }}
  105. run: gh project item-list ${{ steps.create-release-board.outputs.number }} --owner electron --format json | jq
  106. env:
  107. GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
  108. - name: Find Previous Release Project Board
  109. if: ${{ steps.check-major-version.outputs.MAJOR }}
  110. uses: dsanders11/project-actions/find-project@438b25e007c2f4efec324497fadc6402e7cc61a6 # v1.4.0
  111. id: find-prev-release-board
  112. with:
  113. title: ${{ steps.generate-project-metadata.outputs.prev-prev-major }}-x-y
  114. token: ${{ steps.generate-token.outputs.token }}
  115. - name: Close Previous Release Project Board
  116. if: ${{ steps.check-major-version.outputs.MAJOR }}
  117. uses: dsanders11/project-actions/close-project@438b25e007c2f4efec324497fadc6402e7cc61a6 # v1.4.0
  118. with:
  119. project-number: ${{ steps.find-prev-release-board.outputs.number }}
  120. token: ${{ steps.generate-token.outputs.token }}