-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (111 loc) · 4.09 KB
/
publish.yml
File metadata and controls
128 lines (111 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Publish to Packagist
on:
push:
tags:
- 'v*.*.*'
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Tag to publish (e.g., v0.7.0)'
required: true
type: string
permissions:
contents: read
jobs:
# ====================
# Validate & Extract version
# ====================
prepare:
name: Prepare Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Extract version from tag
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.tag }}"
elif [ "${{ github.event_name }}" = "release" ]; then
VERSION="${{ github.event.release.tag_name }}"
else
VERSION=${GITHUB_REF#refs/tags/}
fi
VERSION=${VERSION#v}
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Version: ${VERSION}"
# ====================
# Build & Test
# ====================
validate:
name: Build & Test
runs-on: ubuntu-latest
needs: prepare
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: curl, json, mbstring
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Run tests
run: composer test
- name: Run PHPStan
run: composer phpstan
- name: Check code style
run: composer cs
# ====================
# Publish all packages to Packagist
# ====================
publish:
name: Publish to Packagist
runs-on: ubuntu-latest
needs: [prepare, validate]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: curl, json, mbstring
- name: Set version in all packages
run: |
VERSION="${{ needs.prepare.outputs.version }}"
echo "Setting version to ${VERSION} in all packages..."
for file in composer.json packages/*/composer.json; do
if [ -f "$file" ]; then
php -r "
\$pkg = json_decode(file_get_contents('$file'), true);
\$pkg['version'] = '${VERSION}';
file_put_contents('$file', json_encode(\$pkg, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . \"\n\");
"
echo " Updated $file to ${VERSION}"
fi
done
- name: Notify Packagist
run: |
echo "Notifying Packagist to re-index repository..."
curl -s -X POST \
"https://packagist.org/api/update-package?username=logtide&apiToken=${{ secrets.PACKAGIST_TOKEN }}" \
-d '{"repository":{"url":"https://github.com/logtide-dev/logtide-php"}}' \
|| echo "Warning: Failed to notify Packagist"
- name: Create publish summary
run: |
VERSION="${{ needs.prepare.outputs.version }}"
echo "## Packagist Packages Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Version: **${VERSION}**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Package | Install Command |" >> $GITHUB_STEP_SUMMARY
echo "|---------|-----------------|" >> $GITHUB_STEP_SUMMARY
echo "| logtide/logtide | \`composer require logtide/logtide:${VERSION}\` |" >> $GITHUB_STEP_SUMMARY
echo "| logtide/logtide-laravel | \`composer require logtide/logtide-laravel:${VERSION}\` |" >> $GITHUB_STEP_SUMMARY
echo "| logtide/logtide-symfony | \`composer require logtide/logtide-symfony:${VERSION}\` |" >> $GITHUB_STEP_SUMMARY
echo "| logtide/logtide-slim | \`composer require logtide/logtide-slim:${VERSION}\` |" >> $GITHUB_STEP_SUMMARY
echo "| logtide/logtide-wordpress | \`composer require logtide/logtide-wordpress:${VERSION}\` |" >> $GITHUB_STEP_SUMMARY