Build and upload Alpine APK packages to Forgejo #69
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: Build and upload Alpine APK packages to Forgejo | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| iteration: | |
| description: "Optional: override package iteration (integer). Leave empty for auto" | |
| required: false | |
| default: "" | |
| php_versions: | |
| description: "Optional: PHP versions (comma-separated, e.g., 8.2,8.5). Leave empty for all" | |
| required: false | |
| default: "" | |
| architectures: | |
| description: "Optional: Architectures (comma-separated, e.g., x86_64,aarch64). Leave empty for all" | |
| required: false | |
| default: "" | |
| packages: | |
| description: "Optional: override packages list. Leave empty for default" | |
| required: false | |
| default: "" | |
| debug_tmate: | |
| description: "Open tmate session on failure" | |
| type: boolean | |
| required: false | |
| default: false | |
| repository_dispatch: | |
| types: [spc-download] | |
| permissions: | |
| contents: read | |
| jobs: | |
| setup-matrix: | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Set up matrix | |
| id: set-matrix | |
| run: | | |
| # Default values | |
| default_php='["8.2","8.3","8.4","8.5"]' | |
| default_arch='["x86_64","aarch64"]' | |
| # Parse inputs or use defaults | |
| if [[ -n "${INPUTS_PHP_VERSIONS}" ]]; then | |
| php_versions=$(echo "${INPUTS_PHP_VERSIONS}" | jq -R 'split(",") | map(gsub("^\\s+|\\s+$";""))') | |
| else | |
| php_versions=$default_php | |
| fi | |
| if [[ -n "${INPUTS_ARCHITECTURES}" ]]; then | |
| arch_versions=$(echo "${INPUTS_ARCHITECTURES}" | jq -R 'split(",") | map(gsub("^\\s+|\\s+$";""))') | |
| else | |
| arch_versions=$default_arch | |
| fi | |
| # Create matrix JSON (compact, single line) | |
| matrix=$(jq -nc \ | |
| --argjson php "$php_versions" \ | |
| --argjson arch "$arch_versions" \ | |
| '{"php-version":$php,"arch":$arch}') | |
| echo "matrix=$matrix" >> $GITHUB_OUTPUT | |
| env: | |
| INPUTS_PHP_VERSIONS: ${{ inputs.php_versions }} | |
| INPUTS_ARCHITECTURES: ${{ inputs.architectures }} | |
| build: | |
| needs: setup-matrix | |
| name: Build for ${{ matrix.arch }} PHP ${{ matrix.php-version }} | |
| runs-on: ${{ matrix.arch == 'x86_64' && 'ubuntu-24.04' || 'ubuntu-24.04-arm' }} | |
| permissions: | |
| contents: read | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| ITERATION: ${{ inputs.iteration || '' }} | |
| PACKAGES: ${{ inputs.packages || '' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | |
| with: | |
| persist-credentials: false | |
| - name: Set PHP version short | |
| run: | | |
| # Convert "8.5" to "85" | |
| PHP_VERSION_SHORT=$(echo "${{ matrix.php-version }}" | tr -d '.') | |
| echo "PHP_VERSION_SHORT=$PHP_VERSION_SHORT" >> $GITHUB_ENV | |
| - name: Install APT dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y curl build-essential tar zstd python3 python3-requests | |
| sudo apt-get upgrade -y | |
| - name: Install nfpm | |
| run: | | |
| if [[ "${{ matrix.arch }}" == "aarch64" ]]; then | |
| NFPM_ARCH="arm64" | |
| else | |
| NFPM_ARCH="amd64" | |
| fi | |
| curl -L -o nfpm.deb https://github.com/goreleaser/nfpm/releases/download/v2.44.0/nfpm_2.44.0_${NFPM_ARCH}.deb | |
| sudo dpkg -i nfpm.deb | |
| rm nfpm.deb | |
| - name: Install composer | |
| run: | | |
| sudo curl -L https://files.henderkes.com/${{ matrix.arch }}-linux/php -o /usr/local/bin/php | |
| sudo chmod +x /usr/local/bin/php | |
| sudo curl -sS https://raw.githubusercontent.com/composer/getcomposer.org/f3108f64b4e1c1ce6eb462b159956461592b3e3e/web/installer | php -- --quiet | |
| sudo mv composer.phar /usr/local/bin/composer | |
| - name: Prepare cache directories | |
| run: | | |
| composer config -g cache-dir | |
| - name: Cache Composer downloads | |
| uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 | |
| with: | |
| path: ~/.cache/composer | |
| key: composer-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: | | |
| composer- | |
| - name: Install vendor | |
| run: composer install --no-interaction --prefer-dist --no-progress | |
| - name: Download artifact from spc-download.yml | |
| uses: dawidd6/action-download-artifact@ac66b43f0e6a346234dd65d4d0c8fbb31cb316e5 # v11 | |
| with: | |
| workflow: spc-download.yml | |
| name: downloads-tarball | |
| branch: master | |
| - name: Extract with permissions | |
| run: | | |
| mkdir -p downloads | |
| tar -xzf downloads.tar.gz -C downloads | |
| rm downloads.tar.gz | |
| - name: Build PHP packages | |
| run: | | |
| PACKAGES_FLAG="" | |
| if [[ -n "${{ env.PACKAGES }}" ]]; then | |
| PACKAGES_FLAG="--packages=${{ env.PACKAGES }}" | |
| fi | |
| ITERATION_FLAG="" | |
| if [[ -n "${ITERATION}" ]]; then | |
| ITERATION_FLAG="--iteration=${ITERATION}" | |
| fi | |
| php bin/spp all --target="native-native-musl -dynamic" --phpv=${{ matrix.php-version }} --prefix="-zts" --type=apk $ITERATION_FLAG $PACKAGES_FLAG | |
| - name: Upload to Forgejo | |
| working-directory: dist/apk | |
| run: | | |
| ../../bin/forgejo-helper upload alpine "${{ env.PHP_VERSION_SHORT }}" "${{ secrets.FORGEJO_PASSWORD }}" "*.apk" | |
| ../../bin/forgejo-helper --host=2 upload alpine "${{ env.PHP_VERSION_SHORT }}" "${{ secrets.FORGEJO_PASSWORD }}" "*.apk" | |
| - name: Upload logs on failure | |
| if: ${{ failure() }} | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | |
| with: | |
| name: build-logs-${{ matrix.arch }}-php${{ matrix.php-version }} | |
| path: log | |
| - name: Setup tmate session | |
| if: ${{ failure() && inputs.debug_tmate == true }} | |
| uses: mxschmitt/action-tmate@c0afd6f790e3a5564914980036ebf83216678101 # v3 | |
| timeout-minutes: 30 |