diff --git a/.github/scripts/create-security-branch.sh b/.github/scripts/create-security-branch.sh new file mode 100644 index 00000000000..11a3a2f3808 --- /dev/null +++ b/.github/scripts/create-security-branch.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Construct the security branch name +SECURITY_BRANCH="${INPUT_RELEASE_BRANCH}+security-${INPUT_SECURITY_BRANCH_NUMBER}" + +# Check if branch already exists +if git show-ref --verify --quiet "refs/heads/${SECURITY_BRANCH}"; then + echo "::error::Security branch ${SECURITY_BRANCH} already exists" + exit 1 +fi + +# Create and push the new branch from the release branch +git checkout "${INPUT_RELEASE_BRANCH}" +git checkout -b "${SECURITY_BRANCH}" +git push origin "${SECURITY_BRANCH}" + +# Output the branch name for the workflow +echo "branch=${SECURITY_BRANCH}" >> "${GITHUB_OUTPUT}" diff --git a/.github/workflows/create-security-branch.yml b/.github/workflows/create-security-branch.yml index c61e91bb17e..adf8ee70899 100644 --- a/.github/workflows/create-security-branch.yml +++ b/.github/workflows/create-security-branch.yml @@ -9,7 +9,8 @@ on: security_branch_number: type: string description: 'The security branch number (e.g., 01)' - required: true + required: false + default: '01' repository: type: string description: 'The repository to create the security branch in (e.g., grafana/grafana-security-mirror)' @@ -27,7 +28,8 @@ on: security_branch_number: type: string description: 'The security branch number (e.g., 01)' - required: true + required: false + default: '01' repository: type: string description: 'The repository to create the security branch in (e.g., grafana/grafana-security-mirror)' @@ -67,9 +69,11 @@ jobs: - name: Create security branch id: branch - uses: grafana/grafana-github-actions-go/create-security-branch@main - with: - release_branch: ${{ inputs.release_branch }} - security_branch_number: ${{ inputs.security_branch_number }} - repository: ${{ inputs.repository }} - token: ${{ steps.generate_token.outputs.token }} + env: + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} + INPUT_RELEASE_BRANCH: ${{ inputs.release_branch }} + INPUT_SECURITY_BRANCH_NUMBER: ${{ inputs.security_branch_number }} + INPUT_REPOSITORY: ${{ inputs.repository }} + run: | + chmod +x .github/scripts/create-security-branch.sh + .github/scripts/create-security-branch.sh