diff --git a/.github/workflows/tag-release.yml b/.github/workflows/tag-release.yml new file mode 100644 index 0000000..0632ae2 --- /dev/null +++ b/.github/workflows/tag-release.yml @@ -0,0 +1,70 @@ +name: Tag Release on Fabric Update + +on: + pull_request: + types: [closed] + branches: [main] + +permissions: + contents: write + +jobs: + tag-release: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'update fabric to') + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Configure Git + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Determine new version + id: version + run: | + # Get current tag + CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") + echo "Current tag: $CURRENT_TAG" + + # Remove 'v' prefix and split version + VERSION=${CURRENT_TAG#v} + IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" + + # Increment minor version + NEW_MINOR=$((MINOR + 1)) + NEW_TAG="v${MAJOR}.${NEW_MINOR}.0" + + echo "New tag: $NEW_TAG" + echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT + + - name: Create and push tag + run: | + NEW_TAG="${{ steps.version.outputs.new_tag }}" + + # Extract fabric version from PR title + FABRIC_VERSION=$(echo "${{ github.event.pull_request.title }}" | grep -oP '(?<=update fabric to )[0-9.]+') + + # Create annotated tag + git tag -a "$NEW_TAG" -m "Release $NEW_TAG - Update fabric to $FABRIC_VERSION" + + # Push tag + git push origin "$NEW_TAG" + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.version.outputs.new_tag }} + name: ${{ steps.version.outputs.new_tag }} + body: | + ## What's Changed + + - Updated danielmiessler/fabric to version ${{ github.event.pull_request.title }} + + **Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ steps.version.outputs.current_tag }}...${{ steps.version.outputs.new_tag }} + draft: false + prerelease: false diff --git a/.github/workflows/update-fabric.yml b/.github/workflows/update-fabric.yml new file mode 100644 index 0000000..35acdb0 --- /dev/null +++ b/.github/workflows/update-fabric.yml @@ -0,0 +1,114 @@ +name: Update Fabric Version + +on: + schedule: + # Run daily at 2 AM UTC + - cron: '0 2 * * *' + workflow_dispatch: # Allow manual trigger + +permissions: + contents: write + pull-requests: write + +jobs: + check-fabric-update: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + tools: composer + + - name: Check for new Fabric release + id: check_release + run: | + # Get the latest release version from GitHub API + LATEST_VERSION=$(curl -s https://api.github.com/repos/danielmiessler/fabric/releases/latest | jq -r '.tag_name') + echo "Latest fabric version: $LATEST_VERSION" + + # Get current version from composer.json + CURRENT_VERSION=$(jq -r '.repositories[0].package.version' composer.json) + echo "Current fabric version: $CURRENT_VERSION" + + # Compare versions + if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then + echo "New version available: $LATEST_VERSION" + echo "new_version=$LATEST_VERSION" >> $GITHUB_OUTPUT + echo "update_needed=true" >> $GITHUB_OUTPUT + else + echo "No update needed" + echo "update_needed=false" >> $GITHUB_OUTPUT + fi + + - name: Update composer.json + if: steps.check_release.outputs.update_needed == 'true' + run: | + NEW_VERSION="${{ steps.check_release.outputs.new_version }}" + + # Update the version in composer.json + jq --arg version "$NEW_VERSION" \ + --arg url "https://github.com/danielmiessler/fabric/archive/refs/tags/$NEW_VERSION.zip" \ + '.repositories[0].package.version = $version | .repositories[0].package.dist.url = $url' \ + composer.json > composer.json.tmp && mv composer.json.tmp composer.json + + # Update composer.lock + composer update danielmiessler/fabric --no-interaction + + - name: Determine new package version + if: steps.check_release.outputs.update_needed == 'true' + id: new_version + run: | + # Get current package version + CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") + echo "Current tag: $CURRENT_TAG" + + # Remove 'v' prefix and split version + VERSION=${CURRENT_TAG#v} + IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" + + # Increment minor version + NEW_MINOR=$((MINOR + 1)) + NEW_TAG="v${MAJOR}.${NEW_MINOR}.0" + + echo "New tag: $NEW_TAG" + echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT + + - name: Create Pull Request + if: steps.check_release.outputs.update_needed == 'true' + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: | + chore: update fabric to ${{ steps.check_release.outputs.new_version }} + + Updates danielmiessler/fabric from ${{ steps.check_release.outputs.current_version }} to ${{ steps.check_release.outputs.new_version }} + branch: update-fabric-${{ steps.check_release.outputs.new_version }} + delete-branch: true + title: 'chore: update fabric to ${{ steps.check_release.outputs.new_version }}' + body: | + ## Description + + This PR updates the fabric dependency to version ${{ steps.check_release.outputs.new_version }}. + + ## Changes + + - Updated `danielmiessler/fabric` version in `composer.json` + - Updated `composer.lock` with new dependency version + + ## Release Notes + + See the [fabric release notes](https://github.com/danielmiessler/fabric/releases/tag/${{ steps.check_release.outputs.new_version }}) for details about this update. + + --- + + *This PR was automatically created by the update-fabric workflow.* + labels: | + dependencies + automated