| name: Cut Release Branch | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version string (format X.Y)' | |
| required: true | |
| type: string | |
| commit_hash: | |
| description: 'The hash of the commit to branch off of' | |
| required: true | |
| type: string | |
| permissions: | |
| contents: read | |
| jobs: | |
| check-membership: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| is_member: ${{ steps.check.outputs.is_member }} | |
| steps: | |
| - name: Check if user is in the required team | |
| id: check | |
| run: | | |
| # Use the GitHub CLI to check team membership | |
| # Returns 204 if member, 404 if not | |
| if gh api "orgs/flutter/teams/flutter-release-eng/memberships/$ACTOR" --silent; then | |
| echo "is_member=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "::error::User $ACTOR is not a member of flutter-release-eng." | |
| exit 1 | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.FLUTTER_READ_ORG }} | |
| ACTOR: ${{ github.actor }} | |
| create-release-branch: | |
| needs: check-membership | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Required to create branches and push commits | |
| steps: | |
| - name: Validate Version Format | |
| env: | |
| VERSION: ${{ inputs.version }} | |
| run: | | |
| if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+$ ]]; then | |
| echo "Error: Version must be in 'X.Y' format (e.g., 3.10)." | |
| exit 1 | |
| fi | |
| - name: Checkout target commit | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| ref: ${{ inputs.commit_hash }} | |
| token: ${{ secrets.FLUTTERACTIONSBOT_CP_TOKEN }} | |
| persist-credentials: false | |
| - name: Configure Git | |
| run: | | |
| gh auth setup-git | |
| git config --global user.name "flutteractionsbot" | |
| git config --global user.email "<flutter-actions-bot@google.com>" | |
| env: | |
| GH_TOKEN: ${{ secrets.FLUTTERACTIONSBOT_CP_TOKEN }} | |
| - name: Set Environment Variables | |
| env: | |
| VERSION: ${{ inputs.version }} | |
| run: | | |
| echo "BRANCH_NAME=flutter-$VERSION-candidate.0" >> "$GITHUB_ENV" | |
| - name: Check if branch already exists | |
| run: | | |
| if git ls-remote --exit-code --heads origin "$BRANCH_NAME"; then | |
| echo "Error: Branch $BRANCH_NAME already exists on remote." | |
| exit 1 | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.FLUTTERACTIONSBOT_CP_TOKEN }} | |
| - name: Create Branch and Version File | |
| run: | | |
| # Create and switch to the new branch locally | |
| git checkout -b "$BRANCH_NAME" | |
| # Create the version file | |
| mkdir -p bin/internal/ | |
| echo -n "$BRANCH_NAME" > bin/internal/release-candidate-branch.version | |
| # Commit the change | |
| git add bin/internal/release-candidate-branch.version | |
| git commit -m "Initialize release branch $BRANCH_NAME" | |
| - name: Push new branch | |
| run: | | |
| git push origin "$BRANCH_NAME" | |
| { | |
| echo "## Release Branch \`$BRANCH_NAME\` Cut Successfully" | |
| echo "" | |
| echo "🔗 **View Branch** https://github.com/$GITHUB_REPOSITORY/tree/$BRANCH_NAME" | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| env: | |
| GH_TOKEN: ${{ secrets.FLUTTERACTIONSBOT_CP_TOKEN }} |