branch-created.yml 5.8 KB

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