Skip to content

Commit 2b9cb98

Browse files
OskarStarkclaude
andauthored
feat: add GitHub Actions to auto-update fabric dependency (#1)
* feat: add GitHub Actions to auto-update fabric dependency - Add workflow to check for new fabric releases daily - Automatically create PR when new version is available - Add workflow to tag new minor release when PR is merged - Updates composer.json and composer.lock automatically 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * fix: add newlines at end of workflow files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 082d444 commit 2b9cb98

File tree

2 files changed

+184
-0
lines changed

2 files changed

+184
-0
lines changed

.github/workflows/tag-release.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Tag Release on Fabric Update
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches: [main]
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
tag-release:
13+
if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'update fabric to')
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
22+
- name: Configure Git
23+
run: |
24+
git config user.name "github-actions[bot]"
25+
git config user.email "github-actions[bot]@users.noreply.github.com"
26+
27+
- name: Determine new version
28+
id: version
29+
run: |
30+
# Get current tag
31+
CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
32+
echo "Current tag: $CURRENT_TAG"
33+
34+
# Remove 'v' prefix and split version
35+
VERSION=${CURRENT_TAG#v}
36+
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
37+
38+
# Increment minor version
39+
NEW_MINOR=$((MINOR + 1))
40+
NEW_TAG="v${MAJOR}.${NEW_MINOR}.0"
41+
42+
echo "New tag: $NEW_TAG"
43+
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
44+
45+
- name: Create and push tag
46+
run: |
47+
NEW_TAG="${{ steps.version.outputs.new_tag }}"
48+
49+
# Extract fabric version from PR title
50+
FABRIC_VERSION=$(echo "${{ github.event.pull_request.title }}" | grep -oP '(?<=update fabric to )[0-9.]+')
51+
52+
# Create annotated tag
53+
git tag -a "$NEW_TAG" -m "Release $NEW_TAG - Update fabric to $FABRIC_VERSION"
54+
55+
# Push tag
56+
git push origin "$NEW_TAG"
57+
58+
- name: Create GitHub Release
59+
uses: softprops/action-gh-release@v2
60+
with:
61+
tag_name: ${{ steps.version.outputs.new_tag }}
62+
name: ${{ steps.version.outputs.new_tag }}
63+
body: |
64+
## What's Changed
65+
66+
- Updated danielmiessler/fabric to version ${{ github.event.pull_request.title }}
67+
68+
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ steps.version.outputs.current_tag }}...${{ steps.version.outputs.new_tag }}
69+
draft: false
70+
prerelease: false
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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

Comments
 (0)