Skip to content

Branch Created

Branch Created #2213

name: Branch Created
on:
create:
permissions: {}
jobs:
release-branch-created:
name: Release Branch Created
if: ${{ github.event.ref_type == 'branch' && endsWith(github.event.ref, '-x-y') }}
permissions:
contents: read
pull-requests: write
repository-projects: write # Required for labels
runs-on: ubuntu-latest
steps:
- name: Determine Major Version
id: check-major-version
run: |
if [[ ${{ github.event.ref }} =~ ^([0-9]+)-x-y$ ]]; then
echo "MAJOR=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
else
echo "Not a release branch: ${{ github.event.ref }}"
fi
- name: New Release Branch Tasks
if: ${{ steps.check-major-version.outputs.MAJOR }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: electron/electron
MAJOR: ${{ steps.check-major-version.outputs.MAJOR }}
NUM_SUPPORTED_VERSIONS: 3
run: |
PREVIOUS_MAJOR=$((MAJOR - 1))
UNSUPPORTED_MAJOR=$((MAJOR - NUM_SUPPORTED_VERSIONS - 1))
# Create new labels
gh label create $MAJOR-x-y --color 8d9ee8 || true
gh label create target/$MAJOR-x-y --color ad244f --description "PR should also be added to the \"${MAJOR}-x-y\" branch." || true
gh label create merged/$MAJOR-x-y --color 61a3c6 --description "PR was merged to the \"${MAJOR}-x-y\" branch." || true
gh label create in-flight/$MAJOR-x-y --color db69a6 || true
gh label create needs-manual-bp/$MAJOR-x-y --color 8b5dba || true
# Change color of old labels
gh label edit $UNSUPPORTED_MAJOR-x-y --color ededed || true
gh label edit target/$UNSUPPORTED_MAJOR-x-y --color ededed || true
gh label edit merged/$UNSUPPORTED_MAJOR-x-y --color ededed || true
gh label edit in-flight/$UNSUPPORTED_MAJOR-x-y --color ededed || true
gh label edit needs-manual-bp/$UNSUPPORTED_MAJOR-x-y --color ededed || true
# Add the new target label to any PRs which:
# * target the previous major
# * are in-flight for the previous major
# * need manual backport for the previous major
for PREVIOUS_MAJOR_LABEL in target/$PREVIOUS_MAJOR-x-y in-flight/$PREVIOUS_MAJOR-x-y needs-manual-bp/$PREVIOUS_MAJOR-x-y; do
PULL_REQUESTS=$(gh pr list --label $PREVIOUS_MAJOR_LABEL --jq .[].number --json number --limit 500)
if [[ $PULL_REQUESTS ]]; then
echo $PULL_REQUESTS | xargs -n 1 gh pr edit --add-label target/$MAJOR-x-y || true
fi
done
- name: Generate GitHub App token
if: ${{ steps.check-major-version.outputs.MAJOR }}
uses: electron/github-app-auth-action@384fd19694fe7b6dcc9a684746c6976ad78228ae # v1.1.1
id: generate-token
with:
creds: ${{ secrets.RELEASE_BOARD_GH_APP_CREDS }}
org: electron
- name: Generate Release Project Board Metadata
if: ${{ steps.check-major-version.outputs.MAJOR }}
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
id: generate-project-metadata
with:
script: |
const major = ${{ steps.check-major-version.outputs.MAJOR }}
core.setOutput("template-view", JSON.stringify({
major,
"next-major": major + 1,
"prev-major": major - 1,
}))
core.setOutput("title", `${major}-x-y`)
- name: Create Release Project Board
if: ${{ steps.check-major-version.outputs.MAJOR }}
uses: dsanders11/project-actions/copy-project@a24415515fa60a22f71f9d9d00e36ca82660cde9 # v1.0.1
with:
drafts: true
project-number: 64
# TODO - Set to public once GitHub fixes their GraphQL bug
# public: true
template-view: ${{ steps.generate-project-metadata.outputs.template-view }}
title: ${{ steps.generate-project-metadata.outputs.title}}
token: ${{ steps.generate-token.outputs.token }}