name: Create Release Branch on: workflow_dispatch: inputs: version: description: 'Release version (SemVer format, e.g., 1.2.3 or 2.0.0-rc.1)' required: true type: string permissions: contents: write jobs: create-release-branch: name: Create Release Branch runs-on: ubuntu-latest environment: release steps: - name: Validate SemVer format id: validate run: | VERSION="${{ github.event.inputs.version }}" # SemVer regex: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string SEMVER_REGEX='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$' if ! echo "$VERSION" | grep -Pq "$SEMVER_REGEX"; then echo "Error: Version '$VERSION' is not valid SemVer format" echo "Examples: 1.2.3, 2.0.0-rc.1, 1.0.0-beta.2+build.123" exit 1 fi echo "version=$VERSION" >> "$GITHUB_OUTPUT" # Check if pre-release (contains hyphen) if echo "$VERSION" | grep -q '-'; then echo "Detected pre-release version: $VERSION" else echo "Detected stable release version: $VERSION" fi - name: Checkout code uses: actions/checkout@v5 with: token: ${{ secrets.PUBLISHER_TOKEN }} - name: Configure Git run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - name: Check if branch exists run: | BRANCH_NAME="release/${{ steps.validate.outputs.version }}" if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then echo "Error: Branch '$BRANCH_NAME' already exists" exit 1 fi echo "Branch '$BRANCH_NAME' does not exist, proceeding..." - name: Create release branch and update version run: | BRANCH_NAME="release/${{ steps.validate.outputs.version }}" VERSION="${{ steps.validate.outputs.version }}" # Create and checkout new branch git checkout -b "$BRANCH_NAME" # Update version.py echo "__version__ = \"$VERSION\"" > src/version.py # Commit changes git add src/version.py git commit -m "chore: bump version to $VERSION" # Push branch (this will trigger the publish workflow) git push origin "$BRANCH_NAME" echo "✅ Created branch '$BRANCH_NAME'" echo "✅ Updated version to $VERSION" echo "✅ The publish workflow will now build Docker images and create the GitHub release"