name: Add Release Assets

on:
    release:
        types: [published]
    workflow_dispatch:

jobs:
    asset:
        runs-on: ${{ matrix.operating-system }}
        strategy:
            matrix:
                operating-system: [ ubuntu-latest ]
                php: [ "8.1", "8.3" ]

        name: Upload Release Assets
        steps:
            - id: getTag
              name: Get Tag
              run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

            - name: Get release
              id: get_release
              uses: bruceadams/get-release@v1.2.2
              env:
                GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

            - name: Checkout
              uses: actions/checkout@v2

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                php-version: ${{ matrix.php }}

            - name: Install Dependencies
              uses: nick-invision/retry@v1
              with:
                timeout_minutes: 10
                max_attempts: 3
                command: composer remove --no-update --dev cache/filesystem-adapter && composer install --no-dev --prefer-dist

            - name: Create Archive
              run: |
                zip -r ${fileName} . &&
                zip -d ${fileName} ".git*" || true &&
                zip -d ${fileName} "tests*" || true &&
                zip -d ${fileName} "docs*" || true &&
                zip -d ${fileName} "phpcs.xml.dist" || true &&
                zip -d ${fileName} "phpunit.xml.dist" || true &&
                zip -d ${fileName} "tests*" || true &&
                zip -d ${fileName} "examples*" || true
              env:
                fileName: google-api-php-client-${{ steps.tagName.outputs.tag }}-PHP${{ matrix.php }}.zip

            - name: Upload Release Archive
              uses: actions/upload-release-asset@v1
              env:
                GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
              with:
                upload_url: ${{ steps.get_release.outputs.upload_url }}
                asset_path: ./google-api-php-client-${{ steps.tagName.outputs.tag }}-PHP${{ matrix.php }}.zip
                asset_name: google-api-php-client-${{ steps.tagName.outputs.tag }}-PHP${{ matrix.php }}.zip
                asset_content_type: application/zip
