|
| 1 | +name: Publish gRPC to GitHub Releases |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + 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)' |
| 16 | + required: false |
| 17 | + |
| 18 | +jobs: |
| 19 | + publish-release: |
| 20 | + name: Publish to GitHub Releases |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout code |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Find Build Artifacts |
| 28 | + id: find-artifacts |
| 29 | + env: |
| 30 | + 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 | + run: | |
| 35 | + # Jika run_id tidak diberikan, cari yang terbaru dengan grpc_version dan php_version |
| 36 | + 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 |
| 49 | + fi |
| 50 | + fi |
| 51 | + |
| 52 | + echo "Using Run ID: $RUN_ID" |
| 53 | + echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT |
| 54 | +
|
| 55 | + - name: Download Artifacts from php-grpc-1.8RC |
| 56 | + id: download |
| 57 | + env: |
| 58 | + 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 }} |
| 62 | + run: | |
| 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 | + |
| 71 | + # 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" |
| 85 | + fi |
| 86 | + done |
| 87 | + |
| 88 | + echo "Final artifacts:" |
| 89 | + ls -lh artifacts/ |
| 90 | +
|
| 91 | + - name: Create Release |
| 92 | + env: |
| 93 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + GRPC_VERSION: ${{ github.event.inputs.grpc_version }} |
| 95 | + PHP_VERSION: ${{ github.event.inputs.php_version }} |
| 96 | + run: | |
| 97 | + RELEASE_TAG="v${GRPC_VERSION}-php${PHP_VERSION}" |
| 98 | + RELEASE_NAME="gRPC ${GRPC_VERSION} for PHP ${PHP_VERSION}" |
| 99 | + |
| 100 | + # Create release with assets |
| 101 | + gh release create "$RELEASE_TAG" \ |
| 102 | + --title "$RELEASE_NAME" \ |
| 103 | + --notes "Pre-compiled gRPC extension for PHP ${PHP_VERSION} |
| 104 | + |
| 105 | +**gRPC Version:** ${GRPC_VERSION} |
| 106 | +**PHP Version:** ${PHP_VERSION} |
| 107 | +**Built on:** Ubuntu 22.04 |
| 108 | +**Architectures:** AMD64, ARM64 |
| 109 | + |
| 110 | +## Usage in Dockerfile |
| 111 | + |
| 112 | +\`\`\`dockerfile |
| 113 | +# Download and install gRPC |
| 114 | +RUN curl -L -o /tmp/grpc-amd64.so \\ |
| 115 | + 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 && \\ |
| 117 | + docker-php-ext-enable grpc |
| 118 | +\`\`\` |
| 119 | + |
| 120 | +**Artifacts:** |
| 121 | +- \`grpc-amd64.so\` - AMD64 (x86_64) architecture |
| 122 | +- \`grpc-arm64.so\` - ARM64 architecture |
| 123 | +" \ |
| 124 | + artifacts/grpc-amd64.so \ |
| 125 | + artifacts/grpc-arm64.so |
| 126 | + |
| 127 | + echo "✅ Release $RELEASE_TAG created successfully!" |
| 128 | + |
| 129 | + - name: Print Release Info |
| 130 | + env: |
| 131 | + GRPC_VERSION: ${{ github.event.inputs.grpc_version }} |
| 132 | + PHP_VERSION: ${{ github.event.inputs.php_version }} |
| 133 | + run: | |
| 134 | + RELEASE_TAG="v${GRPC_VERSION}-php${PHP_VERSION}" |
| 135 | + |
| 136 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 137 | + echo "✅ Release Published Successfully!" |
| 138 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 139 | + 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" |
| 146 | + 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" |
| 152 | + echo "" |
| 153 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
0 commit comments