Skip to content

Laravel Valet Windows 3 [v3.4.4] #1

Laravel Valet Windows 3 [v3.4.4]

Laravel Valet Windows 3 [v3.4.4] #1

Workflow file for this run

on:
release:
types: [prereleased, released]
env:
TAG_NAME: ${{ github.ref_name }}
TARGET_BRANCH: ${{ github.event.release.target_commitish }}
permissions:
contents: write
pull-requests: write
actions: read
name: Release Version Update
jobs:
validate-release-version:
name: Validate Release Version
runs-on: ubuntu-latest
if: github.event_name == 'release'
outputs:
version: ${{ steps.parse-version.outputs.version }}
is-valid: ${{ steps.parse-version.outputs.is-valid }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Parse and Validate Version
id: parse-version
run: |
TAG_NAME="${{ env.TAG_NAME }}"
# Remove 'v' prefix if present and validate semver format
if [[ $TAG_NAME =~ ^v?([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9\.-]+)?(\+[a-zA-Z0-9\.-]+)?)$ ]]; then
VERSION=${BASH_REMATCH[1]}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "is-valid=true" >> $GITHUB_OUTPUT
echo "βœ… Valid version format: $VERSION"
else
echo "is-valid=false" >> $GITHUB_OUTPUT
echo "❌ Invalid version format: $TAG_NAME"
echo "Version must follow semver format (e.g., v1.0.0, 1.0.0, v1.0.0-beta.1)"
exit 1
fi
update-version:
name: Update Version
needs: validate-release-version
runs-on: ubuntu-latest
if: needs.validate-release-version.outputs.is-valid == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Update Version in cli/version.php
run: |
VERSION="${{ needs.validate-release-version.outputs.version }}"
# If this is a prerelease, remove any prerelease tags to get base version
if [ "${{ github.event.action }}" = "prereleased" ]; then
BASE_VERSION=$(echo "$VERSION" | sed 's/-.*$//')
echo "πŸ”„ Prerelease detected: using base version $BASE_VERSION instead of $VERSION"
VERSION="$BASE_VERSION"
fi
CURRENT_VERSION=$(grep -oP "(?<=\\\$version = ')[^']+" cli/version.php)
if [ "$VERSION" = "$CURRENT_VERSION" ]; then
echo "ℹ️ cli/version.php already has version $VERSION, skipping update"
else
echo "πŸ“¦ Updating cli/version.php from $CURRENT_VERSION to $VERSION"
sed -i "s/\$version = '[^']*';/\$version = '$VERSION';/" cli/version.php
echo "βœ… Successfully updated version to $VERSION"
fi
- name: Update Changelog Release Heading
run: |
VERSION="${{ needs.validate-release-version.outputs.version }}"
TAG_NAME="${{ env.TAG_NAME }}"
REPO="${{ github.repository }}"
CURRENT_DATE=$(date +%Y-%m-%d)
# Check if CHANGELOG.md exists
if [ ! -f "CHANGELOG.md" ]; then
echo "⚠️ CHANGELOG.md not found, skipping changelog update"
exit 0
fi
# Check if Unreleased section exists (with or without a trailing URL)
if ! grep -qP "^## \[Unreleased\]" CHANGELOG.md; then
echo "ℹ️ No [Unreleased] section found in CHANGELOG.md, skipping update"
exit 0
fi
# Replace the entire [Unreleased] heading line (including any trailing URL) with
# a versioned release heading that links to the tree at the tag.
RELEASE_URL="${{ github.server_url }}/${REPO}/tree/${TAG_NAME}"
NEW_HEADING="## [${VERSION}](${RELEASE_URL}) - ${CURRENT_DATE}"
sed -i "s|^## \[Unreleased\].*|${NEW_HEADING}|" CHANGELOG.md
echo "βœ… Updated CHANGELOG.md:"
echo " [Unreleased] β†’ [${VERSION}]"
echo " Date: ${CURRENT_DATE}"
echo " URL: ${RELEASE_URL}"
- name: Check for Changes
id: git-check
run: |
# Check for any modified or untracked files
if [ -n "$(git status --porcelain)" ]; then
echo "changes=true" >> $GITHUB_OUTPUT
echo "πŸ“ Changes detected:"
git status --porcelain
else
echo "changes=false" >> $GITHUB_OUTPUT
echo "ℹ️ No changes to commit"
fi
- name: Create New Branch
if: steps.git-check.outputs.changes == 'true'
id: create-branch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e # Exit on any error
BRANCH_NAME="release/${{ env.TAG_NAME }}"
echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
# Check if branch already exists remotely
if git ls-remote --exit-code --heads origin "$BRANCH_NAME" >/dev/null 2>&1; then
echo "❌ Cannot create $BRANCH_NAME branch as it already exists. This may indicate:"
echo " - A previous workflow run failed partway through"
echo " - The branch was manually created"
echo "Please manually delete the branch or check for an existing PR and resolve manually."
exit 1
fi
# Create and checkout new branch
git checkout -b "$BRANCH_NAME" || {
echo "❌ Failed to create branch $BRANCH_NAME"
exit 1
}
echo "βœ… Created $BRANCH_NAME branch"
- name: Commit Changes
if: steps.git-check.outputs.changes == 'true'
id: commit-changes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e # Exit on any error
# Stage and commit changes
git add cli/version.php CHANGELOG.md || {
echo "❌ Failed to stage files"
exit 1
}
git commit -m "chore: version bump and update changelog" || {
echo "❌ Failed to commit changes"
exit 1
}
echo "βœ… Committed changes"
# Push to remote
BRANCH_NAME="${{ steps.create-branch.outputs.branch-name }}"
git push origin "$BRANCH_NAME" || {
echo "❌ Failed to push changes to remote"
exit 1
}
echo "βœ… Pushed changes to remote on $BRANCH_NAME branch"
- name: Create Pull Request
if: steps.git-check.outputs.changes == 'true'
id: create-pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e # Exit on any error
BRANCH_NAME="${{ steps.create-branch.outputs.branch-name }}"
echo "Creating pull request on $BRANCH_NAME branch into ${{ env.TARGET_BRANCH }}"
# Set PR title and body based on release type
RELEASE_TYPE="release"
if [ "${{ github.event.action }}" = "prereleased" ]; then
RELEASE_TYPE="pre-release"
fi
# Define PR details
# ^ capitalises the first letter
PR_TITLE="${RELEASE_TYPE^} ${{ env.TAG_NAME }}"
PR_BODY="Automated version bump for $RELEASE_TYPE ${{ env.TAG_NAME }}."
PR_LABELS="auto version bump,release"
# Create pull request
PR_URL=$(gh pr create \
--base "${{ env.TARGET_BRANCH }}" \
--head "$BRANCH_NAME" \
--title "$PR_TITLE" \
--body "$PR_BODY" \
--label "$PR_LABELS") || {
echo "❌ Failed to create pull request"
exit 1
}
echo "βœ… Pull request created successfully: $PR_URL"
# Extract PR number from URL and store as output
PR_NUMBER=$(echo "$PR_URL" | grep -oP '\d+$')
echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "pr-url=$PR_URL" >> $GITHUB_OUTPUT
# Enable GitHub PR auto-merge
gh pr merge "$PR_URL" --auto --squash || {
echo "❌ Failed to enable auto-merge"
echo "This may be due to:"
echo " - Auto-merge not being enabled in repository settings"
echo " - Required status checks not configured"
echo " - Insufficient permissions"
exit 1
}
echo "βœ… Enabled auto-merge for pull request"
- name: Wait for PR Merge
if: steps.git-check.outputs.changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER="${{ steps.create-pr.outputs.pr-number }}"
echo "⏳ Waiting for pull request #$PR_NUMBER to be merged..."
# Wait for PR to be merged (timeout after 5 minutes)
TIMEOUT=300
ELAPSED=0
INTERVAL=5
while [ $ELAPSED -lt $TIMEOUT ]; do
# Get PR state and merge status in one call
PR_DATA=$(gh pr view "$PR_NUMBER" --json state,mergedAt 2>/dev/null || echo '{"state":"UNKNOWN","mergedAt":null}')
PR_STATE=$(echo "$PR_DATA" | jq -r '.state')
PR_MERGED_AT=$(echo "$PR_DATA" | jq -r '.mergedAt')
if [ "$PR_STATE" = "MERGED" ] || [ "$PR_MERGED_AT" != "null" ]; then
echo "βœ… Pull request successfully merged"
break
fi
sleep $INTERVAL
ELAPSED=$((ELAPSED + INTERVAL))
echo "⏳ Still waiting... (${ELAPSED}s elapsed)"
done
if [ $ELAPSED -ge $TIMEOUT ]; then
echo "❌ Timeout waiting for pull request to merge"
exit 1
fi
- name: Update Tag Reference
if: steps.git-check.outputs.changes == 'true'
run: |
# Fetch the latest changes from target branch
git fetch origin ${{ env.TARGET_BRANCH }}
git checkout ${{ env.TARGET_BRANCH }}
git pull origin ${{ env.TARGET_BRANCH }}
# Move the existing tag to point to the new commit (preserves GitHub release relationship)
git tag ${{ env.TAG_NAME }} -f
git push origin ${{ env.TAG_NAME }} -f
echo "βœ… Updated tag ${{ env.TAG_NAME }} to point to release commit"