Skip to content

Commit b622768

Browse files
committed
feat: integrate build and publish workflows for automatic releases
- Add workflow_run trigger to automatically publish releases after successful build - Download artifacts from current repo's build-grpc workflow (not external repo) - Auto-extract gRPC and PHP versions from artifact names - Organize artifacts for easy downloading - Add duplicate release prevention - Improve logging and UX with better status messages
1 parent cc3cc9c commit b622768

3 files changed

Lines changed: 279 additions & 85 deletions

File tree

Lines changed: 126 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,194 @@
11
name: Publish gRPC to GitHub Releases
22

33
on:
4+
# ✅ Trigger otomatis setelah build-grpc.yml selesai
5+
workflow_run:
6+
workflows: ["Build gRPC PHP (Ubuntu 22.04 Multi-Arch)"]
7+
types: [completed]
8+
branches: [main]
9+
10+
# Manual trigger untuk publish dengan versi spesifik
411
workflow_dispatch:
512
inputs:
6-
grpc_version:
7-
description: 'gRPC Version (e.g., 1.80.0RC1, 1.80.0)'
8-
required: true
9-
default: '1.80.0'
10-
php_version:
11-
description: 'PHP Version (e.g., 8.3)'
12-
required: true
13-
default: '8.3'
14-
source_run_id:
15-
description: 'GitHub Actions Run ID dari php-grpc-1.8RC (opsional, otomatis jika kosong)'
13+
run_id:
14+
description: 'Run ID dari workflow build-grpc (kosongkan untuk auto-detect yang terbaru)'
1615
required: false
1716

1817
jobs:
1918
publish-release:
2019
name: Publish to GitHub Releases
2120
runs-on: ubuntu-latest
22-
21+
2322
steps:
2423
- name: Checkout code
2524
uses: actions/checkout@v4
2625

27-
- name: Find Build Artifacts
28-
id: find-artifacts
26+
- name: Get Build Run ID
27+
id: get-run-id
2928
env:
3029
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31-
GRPC_VERSION: ${{ github.event.inputs.grpc_version }}
32-
PHP_VERSION: ${{ github.event.inputs.php_version }}
33-
RUN_ID: ${{ github.event.inputs.source_run_id }}
3430
run: |
35-
# Jika run_id tidak diberikan, cari yang terbaru dengan grpc_version dan php_version
31+
# Gunakan run_id dari input jika ada, atau ambil dari workflow_run trigger
32+
RUN_ID="${{ github.event.inputs.run_id }}"
33+
3634
if [ -z "$RUN_ID" ]; then
37-
echo "Searching for latest build artifacts..."
38-
RUN_ID=$(gh run list \
39-
--repo agissept/php-grpc-1.8RC \
40-
--workflow build-grpc.yml \
41-
--status success \
42-
--json databaseId,headBranch \
43-
--jq ".[] | select(.headBranch == \"main\" or .headBranch == \"master\") | .databaseId" \
44-
| head -1)
45-
46-
if [ -z "$RUN_ID" ]; then
47-
echo "❌ No successful build found. Please provide source_run_id manually."
48-
exit 1
35+
# Jika dari workflow_run trigger
36+
if [ "${{ github.event_name }}" = "workflow_run" ]; then
37+
RUN_ID="${{ github.event.workflow_run.id }}"
38+
else
39+
# Cari run yang paling baru dan berhasil
40+
echo "🔍 Searching for latest successful build..."
41+
RUN_ID=$(gh run list \
42+
--workflow build-grpc.yml \
43+
--status success \
44+
--json databaseId \
45+
--jq ".[0].databaseId")
46+
47+
if [ -z "$RUN_ID" ]; then
48+
echo "❌ No successful build found!"
49+
exit 1
50+
fi
4951
fi
5052
fi
51-
52-
echo "Using Run ID: $RUN_ID"
53+
5354
echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT
55+
echo "✅ Using Run ID: $RUN_ID"
5456
55-
- name: Download Artifacts from php-grpc-1.8RC
57+
- name: Download Artifacts
5658
id: download
5759
env:
5860
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59-
RUN_ID: ${{ steps.find-artifacts.outputs.run_id }}
60-
PHP_VERSION: ${{ github.event.inputs.php_version }}
61-
GRPC_VERSION: ${{ github.event.inputs.grpc_version }}
61+
RUN_ID: ${{ steps.get-run-id.outputs.run_id }}
6262
run: |
6363
mkdir -p artifacts
64-
65-
# Download artifacts from the build repo
66-
gh run download $RUN_ID \
67-
--repo agissept/php-grpc-1.8RC \
68-
--dir artifacts \
69-
--pattern "*php${PHP_VERSION}*"
70-
64+
65+
# Download semua artifacts dari build-grpc run
66+
echo "📥 Downloading artifacts from run $RUN_ID..."
67+
gh run download "$RUN_ID" --dir artifacts
68+
7169
# List downloaded files
72-
echo "Downloaded files:"
73-
find artifacts -type f -name "grpc.so"
74-
75-
# Rename files for clarity
76-
echo "Renaming files..."
77-
find artifacts -name "grpc.so" | while read file; do
78-
dirname=$(dirname "$file")
79-
80-
# Extract arch from directory name
81-
if [[ "$dirname" == *"amd64"* ]]; then
82-
mv "$file" "artifacts/grpc-amd64.so"
83-
elif [[ "$dirname" == *"arm64"* ]]; then
84-
mv "$file" "artifacts/grpc-arm64.so"
70+
echo "📦 Downloaded files:"
71+
find artifacts -type f -name "grpc.so" | head -20
72+
73+
- name: Extract Version & Organize Artifacts
74+
id: versions
75+
run: |
76+
# Ambil artifact directory pertama untuk extract versi
77+
ARTIFACT_DIR=$(find artifacts -type d -name "*grpc*" | head -1)
78+
79+
if [ -z "$ARTIFACT_DIR" ]; then
80+
echo "❌ No artifact directory found!"
81+
ls -la artifacts/
82+
exit 1
83+
fi
84+
85+
echo "📂 Using artifact dir: $ARTIFACT_DIR"
86+
87+
# Parse nama: grpc-{arch}-ubuntu22.04-php{php_version}-v{grpc_version}
88+
# Contoh: grpc-amd64-ubuntu22.04-php8.3-v1.80.0RC1
89+
BASENAME=$(basename "$ARTIFACT_DIR")
90+
91+
# Extract versions menggunakan regex
92+
if [[ $BASENAME =~ php([0-9.]+)-v(.+)$ ]]; then
93+
PHP_VERSION="${BASH_REMATCH[1]}"
94+
GRPC_VERSION="${BASH_REMATCH[2]}"
95+
else
96+
echo "❌ Could not parse artifact name: $BASENAME"
97+
exit 1
98+
fi
99+
100+
echo "PHP_VERSION=$PHP_VERSION" >> $GITHUB_OUTPUT
101+
echo "GRPC_VERSION=$GRPC_VERSION" >> $GITHUB_OUTPUT
102+
103+
echo "✅ Extracted versions:"
104+
echo " gRPC: $GRPC_VERSION"
105+
echo " PHP: $PHP_VERSION"
106+
107+
# Organize files ke artifacts root
108+
echo "📝 Organizing artifacts..."
109+
for arch_dir in artifacts/grpc-*-ubuntu*; do
110+
if [ -d "$arch_dir" ]; then
111+
if [[ $(basename "$arch_dir") == *"amd64"* ]]; then
112+
cp "$arch_dir/grpc.so" artifacts/grpc-amd64.so
113+
echo " ✓ grpc-amd64.so"
114+
elif [[ $(basename "$arch_dir") == *"arm64"* ]]; then
115+
cp "$arch_dir/grpc.so" artifacts/grpc-arm64.so
116+
echo " ✓ grpc-arm64.so"
117+
fi
85118
fi
86119
done
87-
88-
echo "Final artifacts:"
89-
ls -lh artifacts/
90120
91121
- name: Create Release
92122
env:
93123
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94-
GRPC_VERSION: ${{ github.event.inputs.grpc_version }}
95-
PHP_VERSION: ${{ github.event.inputs.php_version }}
124+
GRPC_VERSION: ${{ steps.versions.outputs.GRPC_VERSION }}
125+
PHP_VERSION: ${{ steps.versions.outputs.PHP_VERSION }}
96126
run: |
97127
RELEASE_TAG="v${GRPC_VERSION}-php${PHP_VERSION}"
98128
RELEASE_NAME="gRPC ${GRPC_VERSION} for PHP ${PHP_VERSION}"
99-
100-
# Create release with assets
129+
130+
# Check if release sudah ada
131+
if gh release view "$RELEASE_TAG" &>/dev/null; then
132+
echo "⚠️ Release $RELEASE_TAG already exists, skipping..."
133+
exit 0
134+
fi
135+
136+
echo "🚀 Creating release: $RELEASE_TAG"
137+
138+
# Create release dengan artifacts
101139
gh release create "$RELEASE_TAG" \
102140
--title "$RELEASE_NAME" \
103141
--notes "Pre-compiled gRPC extension for PHP ${PHP_VERSION}
104-
142+
105143
**gRPC Version:** ${GRPC_VERSION}
106144
**PHP Version:** ${PHP_VERSION}
107145
**Built on:** Ubuntu 22.04
108146
**Architectures:** AMD64, ARM64
109147

110-
## Usage in Dockerfile
148+
## 📥 Usage in Dockerfile
111149

112150
\`\`\`dockerfile
113151
# Download and install gRPC
114-
RUN curl -L -o /tmp/grpc-amd64.so \\
152+
RUN curl -L -o /tmp/grpc.so \\
115153
https://github.com/${{ github.repository }}/releases/download/${RELEASE_TAG}/grpc-amd64.so && \\
116-
mv /tmp/grpc-amd64.so /usr/local/lib/php/extensions/no-debug-non-zts-20220829/grpc.so && \\
154+
mv /tmp/grpc.so /usr/local/lib/php/extensions/no-debug-non-zts-20220829/grpc.so && \\
117155
docker-php-ext-enable grpc
118156
\`\`\`
119157

120-
**Artifacts:**
121-
- \`grpc-amd64.so\` - AMD64 (x86_64) architecture
122-
- \`grpc-arm64.so\` - ARM64 architecture
158+
## 📦 Available Downloads
159+
160+
- **AMD64**: \`grpc-amd64.so\` - x86_64 architecture
161+
- **ARM64**: \`grpc-arm64.so\` - ARM 64-bit architecture
162+
163+
## 📝 Download URLs
164+
165+
- AMD64: \`https://github.com/${{ github.repository }}/releases/download/${RELEASE_TAG}/grpc-amd64.so\`
166+
- ARM64: \`https://github.com/${{ github.repository }}/releases/download/${RELEASE_TAG}/grpc-arm64.so\`
123167
" \
124168
artifacts/grpc-amd64.so \
125169
artifacts/grpc-arm64.so
126-
170+
127171
echo "✅ Release $RELEASE_TAG created successfully!"
128172

129-
- name: Print Release Info
173+
- name: Print Release Summary
130174
env:
131-
GRPC_VERSION: ${{ github.event.inputs.grpc_version }}
132-
PHP_VERSION: ${{ github.event.inputs.php_version }}
175+
GRPC_VERSION: ${{ steps.versions.outputs.GRPC_VERSION }}
176+
PHP_VERSION: ${{ steps.versions.outputs.PHP_VERSION }}
133177
run: |
134178
RELEASE_TAG="v${GRPC_VERSION}-php${PHP_VERSION}"
135-
179+
180+
echo ""
136181
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
137182
echo "✅ Release Published Successfully!"
138183
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
139184
echo ""
140-
echo "Release Tag: $RELEASE_TAG"
141-
echo "Release URL: https://github.com/${{ github.repository }}/releases/tag/$RELEASE_TAG"
142-
echo ""
143-
echo "Download URLs:"
144-
echo " AMD64: https://github.com/${{ github.repository }}/releases/download/$RELEASE_TAG/grpc-amd64.so"
145-
echo " ARM64: https://github.com/${{ github.repository }}/releases/download/$RELEASE_TAG/grpc-arm64.so"
185+
echo "📦 Release Tag: $RELEASE_TAG"
186+
echo "🔗 Release URL:"
187+
echo " https://github.com/${{ github.repository }}/releases/tag/$RELEASE_TAG"
146188
echo ""
147-
echo "Dockerfile Usage:"
148-
echo " RUN curl -L -o /tmp/grpc.so \\"
149-
echo " https://github.com/${{ github.repository }}/releases/download/$RELEASE_TAG/grpc-amd64.so && \\"
150-
echo " mv /tmp/grpc.so /usr/local/lib/php/extensions/no-debug-non-zts-20220829/ && \\"
151-
echo " docker-php-ext-enable grpc"
189+
echo "📥 Download URLs:"
190+
echo " AMD64: https://github.com/${{ github.repository }}/releases/download/$RELEASE_TAG/grpc-amd64.so"
191+
echo " ARM64: https://github.com/${{ github.repository }}/releases/download/$RELEASE_TAG/grpc-arm64.so"
152192
echo ""
153193
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
194+
echo ""

.serena/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/cache
2+
/project.local.yml

0 commit comments

Comments
 (0)