|
| 1 | +name: Create Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 10.x |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + if: github.event_name == 'push' && github.ref == 'refs/heads/10.x' |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + |
| 19 | + - name: Setup PHP |
| 20 | + uses: shivammathur/setup-php@v2 |
| 21 | + with: |
| 22 | + php-version: 8.3 |
| 23 | + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo |
| 24 | + coverage: none |
| 25 | + |
| 26 | + - name: Install dependencies |
| 27 | + run: composer install --no-dev --prefer-dist --no-interaction --optimize-autoloader |
| 28 | + |
| 29 | + - name: Run tests |
| 30 | + run: | |
| 31 | + composer require "laravel/framework:^11.0" "orchestra/testbench:^9.0" --no-interaction --no-update |
| 32 | + composer update --prefer-stable --prefer-dist --no-interaction |
| 33 | + vendor/bin/pest --ci |
| 34 | +
|
| 35 | + - name: Get next version |
| 36 | + id: get_version |
| 37 | + run: | |
| 38 | + # Get the latest tag (handle both v-prefixed and non-prefixed) |
| 39 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0") |
| 40 | + echo "Latest tag: $LATEST_TAG" |
| 41 | +
|
| 42 | + # Extract version numbers (remove 'v' prefix if present) |
| 43 | + VERSION_NUM=${LATEST_TAG#v} |
| 44 | +
|
| 45 | + # Split version into parts |
| 46 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION_NUM" |
| 47 | +
|
| 48 | + # Default to 0 if parts are empty |
| 49 | + MAJOR=${MAJOR:-0} |
| 50 | + MINOR=${MINOR:-0} |
| 51 | + PATCH=${PATCH:-0} |
| 52 | +
|
| 53 | + # Get the previous tag for commit analysis |
| 54 | + PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") |
| 55 | + |
| 56 | + # Analyze commits since last tag to determine version bump |
| 57 | + if [ -z "$PREVIOUS_TAG" ]; then |
| 58 | + # If no previous tags, analyze all commits |
| 59 | + COMMITS=$(git log --pretty=format:"%s" --no-merges) |
| 60 | + else |
| 61 | + # Get commits since last tag |
| 62 | + COMMITS=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"%s" --no-merges) |
| 63 | + fi |
| 64 | +
|
| 65 | + echo "Analyzing commits:" |
| 66 | + echo "$COMMITS" |
| 67 | +
|
| 68 | + # Check for breaking changes (MAJOR version bump) |
| 69 | + if echo "$COMMITS" | grep -E "^(BREAKING|BREAKING CHANGE|feat!|fix!):" > /dev/null; then |
| 70 | + echo "Found breaking changes, incrementing MAJOR version" |
| 71 | + MAJOR=$((MAJOR + 1)) |
| 72 | + MINOR=0 |
| 73 | + PATCH=0 |
| 74 | + # Check for features (MINOR version bump) |
| 75 | + elif echo "$COMMITS" | grep -E "^feat(\(.+\))?:" > /dev/null; then |
| 76 | + echo "Found features, incrementing MINOR version" |
| 77 | + MINOR=$((MINOR + 1)) |
| 78 | + PATCH=0 |
| 79 | + # Default to patch version bump |
| 80 | + else |
| 81 | + echo "No features or breaking changes found, incrementing PATCH version" |
| 82 | + PATCH=$((PATCH + 1)) |
| 83 | + fi |
| 84 | +
|
| 85 | + # Create new version (no v prefix) |
| 86 | + NEW_VERSION="$MAJOR.$MINOR.$PATCH" |
| 87 | +
|
| 88 | + echo "New version: $NEW_VERSION" |
| 89 | + echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 90 | + echo "tag_name=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 91 | +
|
| 92 | + - name: Generate changelog |
| 93 | + id: changelog |
| 94 | + run: | |
| 95 | + # Get the previous tag for changelog |
| 96 | + PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") |
| 97 | +
|
| 98 | + if [ -z "$PREVIOUS_TAG" ]; then |
| 99 | + # If no previous tags, get all commits |
| 100 | + COMMITS=$(git log --pretty=format:"* %s (%an)" --no-merges) |
| 101 | + else |
| 102 | + # Get commits since last tag |
| 103 | + COMMITS=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"* %s (%an)" --no-merges) |
| 104 | + fi |
| 105 | +
|
| 106 | + # Create changelog |
| 107 | + CHANGELOG="## What's Changed\n\n$COMMITS" |
| 108 | +
|
| 109 | + # Handle multiline output for GitHub Actions |
| 110 | + echo "changelog<<EOF" >> $GITHUB_OUTPUT |
| 111 | + echo -e "$CHANGELOG" >> $GITHUB_OUTPUT |
| 112 | + echo "EOF" >> $GITHUB_OUTPUT |
| 113 | +
|
| 114 | + - name: Create Release |
| 115 | + uses: softprops/action-gh-release@v1 |
| 116 | + env: |
| 117 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 118 | + with: |
| 119 | + tag_name: ${{ steps.get_version.outputs.tag_name }} |
| 120 | + name: Release ${{ steps.get_version.outputs.tag_name }} |
| 121 | + body: ${{ steps.changelog.outputs.changelog }} |
| 122 | + draft: false |
| 123 | + prerelease: false |
0 commit comments