branch-created.yml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. name: Branch Created
  2. on:
  3. create:
  4. permissions: {}
  5. jobs:
  6. release-branch-created:
  7. name: Release Branch Created
  8. if: ${{ github.event.ref_type == 'branch' && endsWith(github.event.ref, '-x-y') }}
  9. permissions:
  10. contents: read
  11. pull-requests: write
  12. repository-projects: write # Required for labels
  13. runs-on: ubuntu-latest
  14. steps:
  15. - name: Determine Major Version
  16. id: check-major-version
  17. run: |
  18. if [[ ${{ github.event.ref }} =~ ^([0-9]+)-x-y$ ]]; then
  19. echo "MAJOR=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
  20. else
  21. echo "Not a release branch: ${{ github.event.ref }}"
  22. fi
  23. - name: New Release Branch Tasks
  24. if: ${{ steps.check-major-version.outputs.MAJOR }}
  25. env:
  26. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  27. GH_REPO: electron/electron
  28. MAJOR: ${{ steps.check-major-version.outputs.MAJOR }}
  29. NUM_SUPPORTED_VERSIONS: 3
  30. run: |
  31. PREVIOUS_MAJOR=$((MAJOR - 1))
  32. UNSUPPORTED_MAJOR=$((MAJOR - NUM_SUPPORTED_VERSIONS - 1))
  33. # Create new labels
  34. gh label create $MAJOR-x-y --color 8d9ee8 || true
  35. gh label create target/$MAJOR-x-y --color ad244f --description "PR should also be added to the \"${MAJOR}-x-y\" branch." || true
  36. gh label create merged/$MAJOR-x-y --color 61a3c6 --description "PR was merged to the \"${MAJOR}-x-y\" branch." || true
  37. gh label create in-flight/$MAJOR-x-y --color db69a6 || true
  38. gh label create needs-manual-bp/$MAJOR-x-y --color 8b5dba || true
  39. # Change color of old labels
  40. gh label edit $UNSUPPORTED_MAJOR-x-y --color ededed || true
  41. gh label edit target/$UNSUPPORTED_MAJOR-x-y --color ededed || true
  42. gh label edit merged/$UNSUPPORTED_MAJOR-x-y --color ededed || true
  43. gh label edit in-flight/$UNSUPPORTED_MAJOR-x-y --color ededed || true
  44. gh label edit needs-manual-bp/$UNSUPPORTED_MAJOR-x-y --color ededed || true
  45. # Add the new target label to any PRs which:
  46. # * target the previous major
  47. # * are in-flight for the previous major
  48. # * need manual backport for the previous major
  49. for PREVIOUS_MAJOR_LABEL in target/$PREVIOUS_MAJOR-x-y in-flight/$PREVIOUS_MAJOR-x-y needs-manual-bp/$PREVIOUS_MAJOR-x-y; do
  50. PULL_REQUESTS=$(gh pr list --label $PREVIOUS_MAJOR_LABEL --jq .[].number --json number --limit 500)
  51. if [[ $PULL_REQUESTS ]]; then
  52. echo $PULL_REQUESTS | xargs -n 1 gh pr edit --add-label target/$MAJOR-x-y || true
  53. fi
  54. done
  55. - name: Generate GitHub App token
  56. if: ${{ steps.check-major-version.outputs.MAJOR }}
  57. uses: electron/github-app-auth-action@cc6751b3b5e4edc5b9a4ad0a021ac455653b6dc8 # v1.0.0
  58. id: generate-token
  59. with:
  60. creds: ${{ secrets.RELEASE_BOARD_GH_APP_CREDS }}
  61. org: electron
  62. - name: Create Release Project Board
  63. if: ${{ steps.check-major-version.outputs.MAJOR }}
  64. env:
  65. GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
  66. MAJOR: ${{ steps.check-major-version.outputs.MAJOR }}
  67. ELECTRON_ORG_ID: "O_kgDOAMybxg"
  68. ELECTRON_REPO_ID: "R_kgDOAI8xSw"
  69. TEMPLATE_PROJECT_ID: "PVT_kwDOAMybxs4AQvib"
  70. run: |
  71. # Copy template to create new project board
  72. PROJECT_ID=$(gh api graphql -f query='mutation ($ownerId: ID!, $projectId: ID!, $title: String!) {
  73. copyProjectV2(input: {
  74. includeDraftIssues: true,
  75. ownerId: $ownerId,
  76. projectId: $projectId,
  77. title: $title
  78. }) {
  79. projectV2 {
  80. id
  81. }
  82. }
  83. }' -f ownerId=$ELECTRON_ORG_ID -f projectId=$TEMPLATE_PROJECT_ID -f title="${MAJOR}-x-y" | jq -r '.data.copyProjectV2.projectV2.id')
  84. # Make the new project public
  85. gh api graphql -f query='mutation ($projectId: ID!) {
  86. updateProjectV2(input: {
  87. projectId: $projectId,
  88. public: true,
  89. }) {
  90. projectV2 {
  91. id
  92. }
  93. }
  94. }' -f projectId=$PROJECT_ID
  95. # Link the new project to the Electron repository
  96. gh api graphql -f query='mutation ($projectId: ID!, $repositoryId: ID!) {
  97. linkProjectV2ToRepository(input: {
  98. projectId: $projectId,
  99. repositoryId: $repositoryId
  100. }) {
  101. clientMutationId
  102. }
  103. }' -f projectId=$PROJECT_ID -f repositoryId=$ELECTRON_REPO_ID
  104. # Get all draft issues on the new project board
  105. gh api graphql -f query='query ($id: ID!) {
  106. node(id: $id) {
  107. ... on ProjectV2 {
  108. items(first: 100) {
  109. nodes {
  110. ... on ProjectV2Item {
  111. id
  112. content {
  113. ... on DraftIssue { id title
  114. body
  115. }
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. }' -f id=$PROJECT_ID > issues.json
  123. PROJECT_ITEMS=$(jq '.data.node.items.nodes[] | select(.content.id != null) | .id' issues.json)
  124. #
  125. # Do template replacement for draft issues
  126. #
  127. echo "{\"major\": $MAJOR, \"next-major\": $((MAJOR + 1)), \"prev-major\": $((MAJOR - 1))}" > variables.json
  128. # npx mustache is annoyingly slow, so install mustache directly
  129. yarn add -D mustache
  130. for PROJECT_ITEM_ID in $PROJECT_ITEMS; do
  131. # These are done with the raw output flag and sent to file to better retain formatting
  132. jq -r ".data.node.items.nodes[] | select(.id == $PROJECT_ITEM_ID) | .content.title" issues.json > title.txt
  133. jq -r ".data.node.items.nodes[] | select(.id == $PROJECT_ITEM_ID) | .content.body" issues.json > body.txt
  134. ./node_modules/.bin/mustache variables.json title.txt new_title.txt
  135. ./node_modules/.bin/mustache variables.json body.txt new_body.txt
  136. # Only update draft issues which had content change when interpolated
  137. if ! cmp --silent -- new_title.txt title.txt || ! cmp --silent -- new_body.txt body.txt; then
  138. DRAFT_ISSUE_ID=$(jq ".data.node.items.nodes[] | select(.id == $PROJECT_ITEM_ID) | .content.id" issues.json)
  139. gh api graphql -f query='mutation ($draftIssueId: ID!, $title: String!, $body: String!) {
  140. updateProjectV2DraftIssue(input: {
  141. draftIssueId: $draftIssueId,
  142. title: $title,
  143. body: $body
  144. }) {
  145. draftIssue {
  146. id
  147. }
  148. }
  149. }' -f draftIssueId=$DRAFT_ISSUE_ID -f title="$(cat new_title.txt)" -f body="$(cat new_body.txt)"
  150. fi
  151. done