|
| 1 | +name: Update Fabric Version |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run daily at 2 AM UTC |
| 6 | + - cron: '0 2 * * *' |
| 7 | + workflow_dispatch: # Allow manual trigger |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + check-fabric-update: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + |
| 23 | + - name: Setup PHP |
| 24 | + uses: shivammathur/setup-php@v2 |
| 25 | + with: |
| 26 | + php-version: '8.2' |
| 27 | + tools: composer |
| 28 | + |
| 29 | + - name: Check for new Fabric release |
| 30 | + id: check_release |
| 31 | + run: | |
| 32 | + # Get the latest release version from GitHub API |
| 33 | + LATEST_VERSION=$(curl -s https://api.github.com/repos/danielmiessler/fabric/releases/latest | jq -r '.tag_name') |
| 34 | + echo "Latest fabric version: $LATEST_VERSION" |
| 35 | + |
| 36 | + # Get current version from composer.json |
| 37 | + CURRENT_VERSION=$(jq -r '.repositories[0].package.version' composer.json) |
| 38 | + echo "Current fabric version: $CURRENT_VERSION" |
| 39 | + |
| 40 | + # Compare versions |
| 41 | + if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then |
| 42 | + echo "New version available: $LATEST_VERSION" |
| 43 | + echo "new_version=$LATEST_VERSION" >> $GITHUB_OUTPUT |
| 44 | + echo "update_needed=true" >> $GITHUB_OUTPUT |
| 45 | + else |
| 46 | + echo "No update needed" |
| 47 | + echo "update_needed=false" >> $GITHUB_OUTPUT |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Update composer.json |
| 51 | + if: steps.check_release.outputs.update_needed == 'true' |
| 52 | + run: | |
| 53 | + NEW_VERSION="${{ steps.check_release.outputs.new_version }}" |
| 54 | + |
| 55 | + # Update the version in composer.json |
| 56 | + jq --arg version "$NEW_VERSION" \ |
| 57 | + --arg url "https://github.com/danielmiessler/fabric/archive/refs/tags/$NEW_VERSION.zip" \ |
| 58 | + '.repositories[0].package.version = $version | .repositories[0].package.dist.url = $url' \ |
| 59 | + composer.json > composer.json.tmp && mv composer.json.tmp composer.json |
| 60 | + |
| 61 | + # Update composer.lock |
| 62 | + composer update danielmiessler/fabric --no-interaction |
| 63 | +
|
| 64 | + - name: Determine new package version |
| 65 | + if: steps.check_release.outputs.update_needed == 'true' |
| 66 | + id: new_version |
| 67 | + run: | |
| 68 | + # Get current package version |
| 69 | + CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") |
| 70 | + echo "Current tag: $CURRENT_TAG" |
| 71 | + |
| 72 | + # Remove 'v' prefix and split version |
| 73 | + VERSION=${CURRENT_TAG#v} |
| 74 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" |
| 75 | + |
| 76 | + # Increment minor version |
| 77 | + NEW_MINOR=$((MINOR + 1)) |
| 78 | + NEW_TAG="v${MAJOR}.${NEW_MINOR}.0" |
| 79 | + |
| 80 | + echo "New tag: $NEW_TAG" |
| 81 | + echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT |
| 82 | +
|
| 83 | + - name: Create Pull Request |
| 84 | + if: steps.check_release.outputs.update_needed == 'true' |
| 85 | + uses: peter-evans/create-pull-request@v6 |
| 86 | + with: |
| 87 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + commit-message: | |
| 89 | + chore: update fabric to ${{ steps.check_release.outputs.new_version }} |
| 90 | + |
| 91 | + Updates danielmiessler/fabric from ${{ steps.check_release.outputs.current_version }} to ${{ steps.check_release.outputs.new_version }} |
| 92 | + branch: update-fabric-${{ steps.check_release.outputs.new_version }} |
| 93 | + delete-branch: true |
| 94 | + title: 'chore: update fabric to ${{ steps.check_release.outputs.new_version }}' |
| 95 | + body: | |
| 96 | + ## Description |
| 97 | + |
| 98 | + This PR updates the fabric dependency to version ${{ steps.check_release.outputs.new_version }}. |
| 99 | + |
| 100 | + ## Changes |
| 101 | + |
| 102 | + - Updated `danielmiessler/fabric` version in `composer.json` |
| 103 | + - Updated `composer.lock` with new dependency version |
| 104 | + |
| 105 | + ## Release Notes |
| 106 | + |
| 107 | + See the [fabric release notes](https://github.com/danielmiessler/fabric/releases/tag/${{ steps.check_release.outputs.new_version }}) for details about this update. |
| 108 | + |
| 109 | + --- |
| 110 | + |
| 111 | + *This PR was automatically created by the update-fabric workflow.* |
| 112 | + labels: | |
| 113 | + dependencies |
| 114 | + automated |
0 commit comments