|
1 | 1 | name: Publish gRPC to GitHub Releases |
2 | 2 |
|
3 | 3 | 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 |
4 | 11 | workflow_dispatch: |
5 | 12 | 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)' |
16 | 15 | required: false |
17 | 16 |
|
18 | 17 | jobs: |
19 | 18 | publish-release: |
20 | 19 | name: Publish to GitHub Releases |
21 | 20 | runs-on: ubuntu-latest |
22 | | - |
| 21 | + |
23 | 22 | steps: |
24 | 23 | - name: Checkout code |
25 | 24 | uses: actions/checkout@v4 |
26 | 25 |
|
27 | | - - name: Find Build Artifacts |
28 | | - id: find-artifacts |
| 26 | + - name: Get Build Run ID |
| 27 | + id: get-run-id |
29 | 28 | env: |
30 | 29 | 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 }} |
34 | 30 | 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 | +
|
36 | 34 | 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 |
49 | 51 | fi |
50 | 52 | fi |
51 | | - |
52 | | - echo "Using Run ID: $RUN_ID" |
| 53 | +
|
53 | 54 | echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT |
| 55 | + echo "✅ Using Run ID: $RUN_ID" |
54 | 56 |
|
55 | | - - name: Download Artifacts from php-grpc-1.8RC |
| 57 | + - name: Download Artifacts |
56 | 58 | id: download |
57 | 59 | env: |
58 | 60 | 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 }} |
62 | 62 | run: | |
63 | 63 | 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 | +
|
71 | 69 | # 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 |
85 | 118 | fi |
86 | 119 | done |
87 | | - |
88 | | - echo "Final artifacts:" |
89 | | - ls -lh artifacts/ |
90 | 120 |
|
91 | 121 | - name: Create Release |
92 | 122 | env: |
93 | 123 | 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 }} |
96 | 126 | run: | |
97 | 127 | RELEASE_TAG="v${GRPC_VERSION}-php${PHP_VERSION}" |
98 | 128 | 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 |
101 | 139 | gh release create "$RELEASE_TAG" \ |
102 | 140 | --title "$RELEASE_NAME" \ |
103 | 141 | --notes "Pre-compiled gRPC extension for PHP ${PHP_VERSION} |
104 | | - |
| 142 | +
|
105 | 143 | **gRPC Version:** ${GRPC_VERSION} |
106 | 144 | **PHP Version:** ${PHP_VERSION} |
107 | 145 | **Built on:** Ubuntu 22.04 |
108 | 146 | **Architectures:** AMD64, ARM64 |
109 | 147 |
|
110 | | -## Usage in Dockerfile |
| 148 | +## 📥 Usage in Dockerfile |
111 | 149 |
|
112 | 150 | \`\`\`dockerfile |
113 | 151 | # Download and install gRPC |
114 | | -RUN curl -L -o /tmp/grpc-amd64.so \\ |
| 152 | +RUN curl -L -o /tmp/grpc.so \\ |
115 | 153 | 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 && \\ |
117 | 155 | docker-php-ext-enable grpc |
118 | 156 | \`\`\` |
119 | 157 |
|
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\` |
123 | 167 | " \ |
124 | 168 | artifacts/grpc-amd64.so \ |
125 | 169 | artifacts/grpc-arm64.so |
126 | | - |
| 170 | +
|
127 | 171 | echo "✅ Release $RELEASE_TAG created successfully!" |
128 | 172 |
|
129 | | - - name: Print Release Info |
| 173 | + - name: Print Release Summary |
130 | 174 | 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 }} |
133 | 177 | run: | |
134 | 178 | RELEASE_TAG="v${GRPC_VERSION}-php${PHP_VERSION}" |
135 | | - |
| 179 | +
|
| 180 | + echo "" |
136 | 181 | echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
137 | 182 | echo "✅ Release Published Successfully!" |
138 | 183 | echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
139 | 184 | 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" |
146 | 188 | 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" |
152 | 192 | echo "" |
153 | 193 | echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 194 | + echo "" |
0 commit comments