fix: wip #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Create Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: 8.3 | |
| extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo | |
| coverage: none | |
| - name: Install dependencies | |
| run: composer install --no-dev --prefer-dist --no-interaction --optimize-autoloader | |
| - name: Run tests | |
| run: | | |
| composer require "laravel/framework:^11.0" "orchestra/testbench:^9.0" --no-interaction --no-update | |
| composer update --prefer-stable --prefer-dist --no-interaction | |
| vendor/bin/pest --ci | |
| - name: Get version from composer.json | |
| id: get_version | |
| run: | | |
| VERSION=$(php -r "echo json_decode(file_get_contents('composer.json'), true)['version'] ?? 'v1.0.0';") | |
| if [[ ! $VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then | |
| # If no version in composer.json, use timestamp-based version | |
| VERSION="v1.0.$(date +%Y%m%d%H%M%S)" | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag_name=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Check if tag exists | |
| id: check_tag | |
| run: | | |
| if git rev-parse --verify "refs/tags/${{ steps.get_version.outputs.tag_name }}" >/dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Generate changelog | |
| id: changelog | |
| if: steps.check_tag.outputs.exists == 'false' | |
| run: | | |
| # Get the latest tag | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -z "$LATEST_TAG" ]; then | |
| # If no previous tags, get all commits | |
| COMMITS=$(git log --pretty=format:"* %s (%an)" --no-merges) | |
| else | |
| # Get commits since last tag | |
| COMMITS=$(git log ${LATEST_TAG}..HEAD --pretty=format:"* %s (%an)" --no-merges) | |
| fi | |
| # Create changelog | |
| CHANGELOG="## What's Changed\n\n$COMMITS" | |
| # Handle multiline output for GitHub Actions | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| echo -e "$CHANGELOG" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create Release | |
| if: steps.check_tag.outputs.exists == 'false' | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.get_version.outputs.tag_name }} | |
| release_name: Release ${{ steps.get_version.outputs.tag_name }} | |
| body: ${{ steps.changelog.outputs.changelog }} | |
| draft: false | |
| prerelease: false | |
| - name: Skip release (tag exists) | |
| if: steps.check_tag.outputs.exists == 'true' | |
| run: | | |
| echo "Tag ${{ steps.get_version.outputs.tag_name }} already exists. Skipping release creation." |