Skip to content

self hosted runners not used set cache keys #50

@lionslair

Description

@lionslair

Describe the bug

On self hosted runners it always appears to make a cache key based of the instance it runs on not the cache key set

Version

  • latest

Runners

  • Self Hosted

Operating systems
ubuntu 24.04

PHP versions

  • 8.3
  • 8.4

To Reproduce

name: CI

on:
  workflow_call:
  workflow_dispatch:

jobs:
  php-cs-fixer:
    runs-on: self-hosted
    env:
      extensions: "dom, curl, libxml, mbstring, zip, fileinfo, json, gd, redis, pdo, bcmath"
      key: "php-extensions-pint-20250505"

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup cache environment
        id: extcache
        uses: shivammathur/cache-extensions@v1
        with:
          php-version: '8.4'
          extensions: ${{ env.extensions }}
          key: ${{ env.key }}

      - name: Cache extensions
        uses: actions/cache@v4
        with:
          path: ${{ steps.extcache.outputs.dir }}
          key: ${{ steps.extcache.outputs.key }}
          restore-keys: ${{ steps.extcache.outputs.key }}

      - name: Cache Pint
        uses: actions/cache@v4
        with:
          path: ./storage/pint.cache
          key: ${{ runner.os }}-pint-${{ hashFiles('**/composer.lock') }}
          restore-keys: ${{ runner.os }}-pint-

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.4'
          tools: pint
        env:
          runner: self-hosted

      - name: Run Laravel Pint (PHP CS Fixer)
        run: pint
        continue-on-error: true

      - name: Commit changes
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          commit_message: Fix PHP Syntax Styling

  phpstan:
    name: phpstan
    runs-on: self-hosted
    env:
      extensions: "dom, curl, libxml, mbstring, zip, fileinfo, json, gd, redis, pdo, bcmath"
      key: "php-extensions-phpstan-20250505"

    strategy:
      fail-fast: true
      matrix:
        php: [ '8.4' ]

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup cache environment
        id: extcache
        uses: shivammathur/cache-extensions@v1
        with:
          php-version: ${{ matrix.php }}
          extensions: ${{ env.extensions }}
          key: ${{ env.key }}

      - name: Cache extensions
        uses: actions/cache@v4
        with:
          path: ${{ steps.extcache.outputs.dir }}
          key: ${{ steps.extcache.outputs.key }}
          restore-keys: ${{ steps.extcache.outputs.key }}

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: ${{ env.extensions }}
          coverage: none
        env:
          runner: self-hosted

      - name: Cache composer dependencies
        uses: actions/cache@v4
        with:
          path: vendor
          key: composer-${{ hashFiles('composer.lock') }}

      - name: Install Dependencies
        run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --ignore-platform-reqs
        env:
          APP_ENV: testing

      - name: Run PHPStan
        run: ./vendor/bin/phpstan --error-format=github
name: Application Tests

on:
  workflow_call:
  workflow_dispatch:

jobs:
  laravel_tests:
    runs-on: self-hosted

    strategy:
      fail-fast: false
      matrix:
        php: [ '8.4' ]
        #        stability: [ prefer-lowest, prefer-stable ]
        stability: [ prefer-stable ]
        typesense-version: [ '28.0' ]
        typesense-port: [ '8108:8108' ]
        testsuite: [
          'Architecture',
          'FeatureAdmin',
          'FeatureClient',
          'FeatureControllers',
          'FeatureInvoice',
          'FeatureMilestone',
          'FeatureProject',
          'FeatureQuote',
          'FeatureReport',
          'FeatureTicket',
          'FeatureTimesheet',
          'FeatureUser',
          'FeatureWiki',
          'FeatureMeta',
          'Unit'
        ]

    services:
      mysql:
        image: mysql:8.1
        env:
          MYSQL_DATABASE: forge
          MYSQL_PASSWORD: secret
          MYSQL_ROOT_PASSWORD: secret
        ports:
          - 33306:3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
      redis:
        image: redis:5.0
        ports:
          - 6379:6379
        options: --entrypoint redis-server
      typesense:
        image: typesense/typesense:${{ matrix.typesense-version }}
        ports:
          - 8108:8108
        env:
          TYPESENSE_API_KEY: abcd1234
          TYPESENSE_DATA_DIR: /tmp
          TYPESENSE_ENABLE_CORS: 1

    name: ${{ matrix.testsuite }} - PHP ${{ matrix.php }} - ${{ matrix.stability }} - Typesense ${{ matrix.typesense-version }}
    env:
      extensions: "dom, curl, libxml, mbstring, zip, fileinfo, json, gd, redis, pdo, bcmath"
      key: "php-extensions-tests-20250505"

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup cache environment
        id: extcache
        uses: shivammathur/cache-extensions@v1
        with:
          php-version: ${{ matrix.php }}
          extensions: ${{ env.extensions }}
          key: ${{ env.key }}

      - name: Cache extensions
        uses: actions/cache@v4
        with:
          path: ${{ steps.extcache.outputs.dir }}
          key: ${{ steps.extcache.outputs.key }}
          restore-keys: ${{ steps.extcache.outputs.key }}

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: ${{ env.extensions }}
          coverage: none
        env:
          runner: self-hosted

      - name: Copy .env
        run: php -r "file_exists('.env') || copy('.env.pipelines', '.env');"

      - name: Cache composer dependencies
        uses: actions/cache@v4
        with:
          path: vendor
          key: composer-${{ hashFiles('composer.lock') }}

      - name: Install Dependencies
        run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --ignore-platform-reqs
        env:
          APP_ENV: testing

      - name: Generate env key
        run: php artisan key:generate

      - name: Test Suite ${{ matrix.testsuite }} Tests
        #        run: ./vendor/bin/pest --parallel --testsuite ${{ matrix.testsuite }} --colors -c phpunit.xml
        run: ./vendor/bin/pest --testsuite ${{ matrix.testsuite }} --colors -c phpunit.xml
        env:
          DB_HOST: 127.0.0.1
          DB_PORT: 33306
          DB_DATABASE: forge
          DB_USERNAME: root
          DB_PASSWORD: secret
          REDIS_HOST: 127.0.0.1
          TYPESENSE_HOST: 127.0.0.1
          TYPESENSE_PORT: 8108

      - name: Upload artifacts
        uses: actions/upload-artifact@master
        if: failure()
        with:
          name: Logs
          path: ./storage/logs

Expected behavior

Cache keys set with the key I think. It load the extensions on new systems from cache not the instance

Screenshots/Logs

Image

Image

Image

Additional context

Are you willing to submit a PR?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions