# This workflow is provided via the organization template repository # # https://github.com/nextcloud/.github # https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization # # SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors # SPDX-License-Identifier: MIT name: PHPUnit SQLite on: pull_request permissions: contents: read concurrency: group: phpunit-sqlite-${{ github.head_ref || github.run_id }} cancel-in-progress: true jobs: changes: runs-on: selfhosted permissions: contents: read pull-requests: read outputs: src: ${{ steps.changes.outputs.src}} steps: - uses: https://github.com/dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 id: changes continue-on-error: true with: filters: | src: - '.github/workflows/**' - 'appinfo/**' - 'lib/**' - 'templates/**' - 'tests/**' - 'vendor/**' - 'vendor-bin/**' - '.php-cs-fixer.dist.php' - 'composer.json' - 'composer.lock' versions: runs-on: selfhosted needs: changes if: needs.changes.outputs.src != 'false' outputs: php-version: ${{ steps.versions.outputs.php-available-list }} server-max: ${{ steps.versions.outputs.branches-max-list }} steps: - name: Checkout app uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - name: Get version matrix id: versions uses: https://github.com/icewind1991/nextcloud-version-matrix@8a7bac6300b2f0f3100088b297995a229558ddba # v1.3.2 phpunit-sqlite: runs-on: selfhosted container: image: docker.io/setupphp/node:php-${{ matrix.php-version }}-bookworm needs: [changes, versions] if: needs.changes.outputs.src != 'false' strategy: fail-fast: false matrix: php-version: ${{ fromJson(needs.versions.outputs.php-version) }} server-versions: ${{ fromJson(needs.versions.outputs.server-max) }} name: SQLite PHP ${{ matrix.php-version }} Nextcloud ${{ matrix.server-versions }} # Must match in appinfo/info.xml (repo name is nextcloud-shortcuts). # Job-level env is reliable on Forgejo; GITHUB_ENV may not feed ${{ env.* }} in later steps. env: APP_NAME: shortcuts steps: - name: Server cache day id: cache-day run: echo "day=$(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT" - name: Restore Nextcloud server cache uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: server-repo-cache with: path: ${{ github.workspace }} key: nextcloud-server-${{ matrix.server-versions }}-${{ steps.cache-day.outputs.day }} - name: Checkout server if: steps.server-repo-cache.outputs.cache-hit != 'true' uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false submodules: true repository: nextcloud/server ref: ${{ matrix.server-versions }} github-server-url: https://github.com token: ${{ secrets.TOKEN_GITHUB }} - name: Save Nextcloud server cache if: steps.server-repo-cache.outputs.cache-hit != 'true' uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: ${{ github.workspace }} key: ${{ steps.server-repo-cache.outputs.cache-primary-key }} - name: Checkout app uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false path: apps/${{ env.APP_NAME }} - name: Install PHP extensions run: | apt-get update apt-get install -y --no-install-recommends \ php${{ matrix.php-version }}-gd \ php${{ matrix.php-version }}-sqlite3 - name: Restore composer binary uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: composer-bin-cache with: path: .ci-bin/composer key: composer-2-${{ runner.os }}-php-${{ matrix.php-version }}-bookworm - name: Install composer if: steps.composer-bin-cache.outputs.cache-hit != 'true' run: | mkdir -p .ci-bin curl -sS https://getcomposer.org/installer | php -- --install-dir=.ci-bin --filename=composer - name: Save composer binary if: steps.composer-bin-cache.outputs.cache-hit != 'true' uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: .ci-bin/composer key: ${{ steps.composer-bin-cache.outputs.cache-primary-key }} - name: Add composer to PATH run: | chmod +x .ci-bin/composer echo "$GITHUB_WORKSPACE/.ci-bin" >> "$GITHUB_PATH" - name: Restore app composer vendor cache uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: app-vendor-cache with: path: | apps/${{ env.APP_NAME }}/vendor apps/${{ env.APP_NAME }}/vendor-bin/*/vendor key: ${{ runner.os }}-composer-vendor-app-${{ matrix.php-version }}-ocp-none-${{ hashFiles('apps/*/composer.lock', 'apps/*/vendor-bin/*/composer.lock') }} restore-keys: | ${{ runner.os }}-composer-vendor-app-${{ matrix.php-version }}-ocp-none- - name: Install app dependencies if: steps.app-vendor-cache.outputs.cache-hit != 'true' working-directory: apps/${{ env.APP_NAME }} run: | composer remove nextcloud/ocp --dev --no-scripts composer i --prefer-dist - name: Save app composer vendor cache if: steps.app-vendor-cache.outputs.cache-hit != 'true' uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: | apps/${{ env.APP_NAME }}/vendor apps/${{ env.APP_NAME }}/vendor-bin/*/vendor key: ${{ steps.app-vendor-cache.outputs.cache-primary-key }} - name: Set up Nextcloud env: DB_PORT: 4444 run: | test -f "apps/${APP_NAME}/appinfo/info.xml" mkdir -p data ./occ maintenance:install --verbose --database=sqlite --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin ./occ app:enable --force "$APP_NAME" - name: Check PHPUnit script is defined id: check_phpunit continue-on-error: true working-directory: apps/${{ env.APP_NAME }} run: | composer run --list | grep '^ test:unit ' | wc -l | grep 1 - name: PHPUnit # Only run if phpunit config file exists if: steps.check_phpunit.outcome == 'success' working-directory: apps/${{ env.APP_NAME }} run: composer run test:unit - name: Print logs if: always() run: | if [ -f data/nextcloud.log ]; then cat data/nextcloud.log; else echo 'No data/nextcloud.log (install may have failed earlier)'; fi - name: Skipped # Fail the action when neither unit nor integration tests ran if: steps.check_phpunit.outcome == 'failure' run: | echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts' exit 1 summary: permissions: contents: none runs-on: selfhosted needs: [changes, phpunit-sqlite] if: always() name: phpunit-sqlite-summary steps: - name: Summary status run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-sqlite.result != 'success' }}; then exit 1; fi