Publish gRPC to GitHub Releases #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish gRPC to GitHub Releases | |
| on: | |
| # Auto-trigger setelah build-grpc.yml selesai | |
| workflow_run: | |
| workflows: ["Build gRPC PHP (Ubuntu 24.04 Multi-Arch)"] | |
| types: [completed] | |
| # Manual trigger untuk publish | |
| workflow_dispatch: | |
| inputs: | |
| run_id: | |
| description: 'Run ID dari workflow build-grpc (kosongkan untuk auto-detect)' | |
| required: false | |
| jobs: | |
| publish-release: | |
| name: Publish to GitHub Releases | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Get Build Run ID | |
| id: get-run-id | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Gunakan run_id dari input jika ada, atau ambil dari workflow_run trigger | |
| RUN_ID="${{ github.event.inputs.run_id }}" | |
| if [ -z "$RUN_ID" ]; then | |
| # Jika dari workflow_run trigger | |
| if [ "${{ github.event_name }}" = "workflow_run" ]; then | |
| RUN_ID="${{ github.event.workflow_run.id }}" | |
| else | |
| # Cari run yang paling baru dan berhasil | |
| echo "Searching for latest successful build..." | |
| RUN_ID=$(gh run list \ | |
| --workflow build-grpc.yml \ | |
| --status success \ | |
| --json databaseId \ | |
| --jq ".[0].databaseId") | |
| if [ -z "$RUN_ID" ]; then | |
| echo "ERROR: No successful build found!" | |
| exit 1 | |
| fi | |
| fi | |
| fi | |
| echo "Using Run ID: $RUN_ID" | |
| echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT | |
| - name: Download Artifacts | |
| id: download | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| RUN_ID: ${{ steps.get-run-id.outputs.run_id }} | |
| run: | | |
| mkdir -p artifacts | |
| # Download semua artifacts dari build-grpc run | |
| echo "Downloading artifacts from run $RUN_ID..." | |
| gh run download "$RUN_ID" --dir artifacts | |
| # List downloaded files | |
| echo "Downloaded files:" | |
| find artifacts -type f -name "grpc.so" | head -20 | |
| - name: Extract Version and Organize Artifacts | |
| id: versions | |
| run: | | |
| # Ambil artifact directory pertama untuk extract versi | |
| ARTIFACT_DIR=$(find artifacts -type d -name "*grpc*" | head -1) | |
| if [ -z "$ARTIFACT_DIR" ]; then | |
| echo "ERROR: No artifact directory found!" | |
| ls -la artifacts/ | |
| exit 1 | |
| fi | |
| echo "Using artifact dir: $ARTIFACT_DIR" | |
| # Parse nama: grpc-{arch}-ubuntu24.04-php{php_version}-v{grpc_version} | |
| BASENAME=$(basename "$ARTIFACT_DIR") | |
| # Extract versions menggunakan regex | |
| if [[ $BASENAME =~ php([0-9.]+)-v(.+)$ ]]; then | |
| PHP_VERSION="${BASH_REMATCH[1]}" | |
| GRPC_VERSION="${BASH_REMATCH[2]}" | |
| else | |
| echo "ERROR: Could not parse artifact name: $BASENAME" | |
| exit 1 | |
| fi | |
| echo "PHP_VERSION=$PHP_VERSION" >> $GITHUB_OUTPUT | |
| echo "GRPC_VERSION=$GRPC_VERSION" >> $GITHUB_OUTPUT | |
| echo "Extracted versions:" | |
| echo " gRPC: $GRPC_VERSION" | |
| echo " PHP: $PHP_VERSION" | |
| # Organize files ke artifacts root | |
| echo "Organizing artifacts..." | |
| for arch_dir in artifacts/grpc-*-ubuntu*; do | |
| if [ -d "$arch_dir" ]; then | |
| if [[ $(basename "$arch_dir") == *"amd64"* ]]; then | |
| cp "$arch_dir/grpc.so" artifacts/grpc-amd64.so | |
| echo " Created: grpc-amd64.so" | |
| elif [[ $(basename "$arch_dir") == *"arm64"* ]]; then | |
| cp "$arch_dir/grpc.so" artifacts/grpc-arm64.so | |
| echo " Created: grpc-arm64.so" | |
| fi | |
| fi | |
| done | |
| - name: Create Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GRPC_VERSION: ${{ steps.versions.outputs.GRPC_VERSION }} | |
| PHP_VERSION: ${{ steps.versions.outputs.PHP_VERSION }} | |
| run: | | |
| RELEASE_TAG="v${GRPC_VERSION}-php${PHP_VERSION}" | |
| RELEASE_NAME="gRPC ${GRPC_VERSION} for PHP ${PHP_VERSION}" | |
| # Check if release sudah ada | |
| if gh release view "$RELEASE_TAG" &>/dev/null; then | |
| echo "WARNING: Release $RELEASE_TAG already exists, skipping..." | |
| exit 0 | |
| fi | |
| echo "Creating release: $RELEASE_TAG" | |
| # Create release dengan artifacts | |
| gh release create "$RELEASE_TAG" \ | |
| --title "$RELEASE_NAME" \ | |
| --notes "Pre-compiled gRPC extension for PHP ${PHP_VERSION} - gRPC Version: ${GRPC_VERSION} - PHP Version: ${PHP_VERSION} - Built on Ubuntu 24.04 (AMD64, ARM64) - Download: https://github.com/${{ github.repository }}/releases/download/${RELEASE_TAG}/grpc-amd64.so and https://github.com/${{ github.repository }}/releases/download/${RELEASE_TAG}/grpc-arm64.so" \ | |
| artifacts/grpc-amd64.so \ | |
| artifacts/grpc-arm64.so | |
| echo "Release $RELEASE_TAG created successfully!" | |
| - name: Print Release Summary | |
| env: | |
| GRPC_VERSION: ${{ steps.versions.outputs.GRPC_VERSION }} | |
| PHP_VERSION: ${{ steps.versions.outputs.PHP_VERSION }} | |
| run: | | |
| RELEASE_TAG="v${GRPC_VERSION}-php${PHP_VERSION}" | |
| echo "" | |
| echo "========================================" | |
| echo "Release Published Successfully!" | |
| echo "========================================" | |
| echo "" | |
| echo "Release Tag: $RELEASE_TAG" | |
| echo "Release URL: https://github.com/${{ github.repository }}/releases/tag/$RELEASE_TAG" | |
| echo "" | |
| echo "Download URLs:" | |
| echo " AMD64: https://github.com/${{ github.repository }}/releases/download/$RELEASE_TAG/grpc-amd64.so" | |
| echo " ARM64: https://github.com/${{ github.repository }}/releases/download/$RELEASE_TAG/grpc-arm64.so" | |
| echo "" | |
| echo "========================================" | |
| echo "" |