diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index f3f8d8e..2869804 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -7,55 +7,23 @@ on: jobs: php-tests: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest strategy: matrix: - php: [8.1, 8.0, 7.4, 7.3, 7.2] - laravel: [9.*, 8.*, 7.*, 6.*, 5.8.*, 5.7.*, 5.6.*] - os: [ubuntu-latest] - include: - - laravel: 9.* - testbench: 7.* - - laravel: 8.* - testbench: 6.* - - laravel: 7.* - testbench: 5.* - - laravel: 6.* - testbench: 4.* - - laravel: 5.8.* - testbench: 3.8.* - - laravel: 5.7.* - testbench: 3.7.* - - laravel: 5.6.* - testbench: 3.6.* - exclude: - - laravel: 9.* - php: 7.2 - - laravel: 9.* - php: 7.3 - - laravel: 9.* - php: 7.4 - - laravel: 8.* - php: 7.2 - - laravel: 5.8.* - php: 8.0 - - laravel: 5.7.* - php: 8.0 - - laravel: 5.6.* - php: 8.0 - - laravel: 5.6.* - php: 8.1 - - laravel: 5.7.* - php: 8.1 - - laravel: 5.8.* - php: 8.1 - - laravel: 6.* - php: 8.1 - - laravel: 7.* - php: 8.1 + db: ['mysql', 'pgsql'] + payload: + - { queue: 'github-actions-laravel9-php81', laravel: '9.*', php: '8.1', 'testbench': '7.*'} + - { queue: 'github-actions-laravel9-php80', laravel: '9.*', php: '8.0', 'testbench': '7.*'} + - { queue: 'github-actions-laravel8-php81', laravel: '8.*', php: '8.1', 'testbench': '6.*'} + - { queue: 'github-actions-laravel8-php80', laravel: '8.*', php: '8.0', 'testbench': '6.*'} + - { queue: 'github-actions-laravel8-php74', laravel: '8.*', php: '7.4', 'testbench': '6.*'} + - { queue: 'github-actions-laravel7-php80', laravel: '7.*', php: '8.0', 'testbench': '5.*' } + - { queue: 'github-actions-laravel7-php74', laravel: '7.*', php: '7.4', 'testbench': '5.*' } + - { queue: 'github-actions-laravel6-php80', laravel: '6.*', php: '8.0', 'testbench': '4.*' } + - { queue: 'github-actions-laravel6-php74', laravel: '6.*', php: '7.4', 'testbench': '4.*' } - name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} + name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }} - DB ${{ matrix.db }} steps: - name: Checkout code @@ -64,13 +32,34 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php }} + php-version: ${{ matrix.payload.php }} extensions: mbstring, dom, fileinfo coverage: none + - name: Set up MySQL and PostgreSQL + run: | + MYSQL_PORT=3307 POSTGRES_PORT=5432 docker compose up ${{ matrix.db }} -d - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.payload.laravel }}" "orchestra/testbench:${{ matrix.payload.testbench }}" --no-interaction --no-update composer update --prefer-stable --prefer-dist --no-interaction --no-suggest + if [ "${{ matrix.db }}" = "mysql" ]; then + while ! mysqladmin ping --host=127.0.0.1 --user=cloudtasks --port=3307 --password=cloudtasks --silent; do + echo "Waiting for MySQL..." + sleep 1 + done + else + echo "Not waiting for MySQL." + fi - name: Execute tests - run: vendor/bin/phpunit + env: + DB_DRIVER: ${{ matrix.db }} + CI_CLOUD_TASKS_PROJECT_ID: ${{ secrets.CI_CLOUD_TASKS_PROJECT_ID }} + CI_CLOUD_TASKS_QUEUE: ${{ secrets.CI_CLOUD_TASKS_QUEUE }} + CI_CLOUD_TASKS_LOCATION: ${{ secrets.CI_CLOUD_TASKS_LOCATION }} + CI_CLOUD_TASKS_SERVICE_ACCOUNT_EMAIL: ${{ secrets.CI_CLOUD_TASKS_SERVICE_ACCOUNT_EMAIL }} + CI_SERVICE_ACCOUNT_JSON_KEY: ${{ secrets.CI_SERVICE_ACCOUNT_JSON_KEY }} + CI_CLOUD_TASKS_CUSTOM_QUEUE: ${{ matrix.payload.queue }} + run: | + echo $CI_SERVICE_ACCOUNT_JSON_KEY > tests/Support/gcloud-key-valid.json + vendor/bin/phpunit diff --git a/README.md b/README.md index 1796458..9f9d9c7 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,6 @@ Please check the table below for supported Laravel and PHP versions: |Laravel Version| PHP Version | |---|---| -| 5.6 | 7.2 or 7.3 or 7.4 -| 5.7 | 7.2 or 7.3 or 7.4 -| 5.8 | 7.2 or 7.3 or 7.4 | 6.x | 7.2 or 7.3 or 7.4 or 8.0 | 7.x | 7.2 or 7.3 or 7.4 or 8.0 | 8.x | 7.3 or 7.4 or 8.0 or 8.1 @@ -96,6 +93,27 @@ Please check the table below on what the values mean and what their value should |`STACKKIT_CLOUD_TASKS_QUEUE`|The queue a job will be added to|`emails` |`STACKKIT_CLOUD_TASKS_SERVICE_EMAIL`|The email address of the AppEngine service account. Important, it should have the *Cloud Tasks Enqueuer* role. This is used for securing the handler.|`my-service-account@appspot.gserviceaccount.com` +## Dashboard + +The package comes with a dashboard that can be used to monitor all queued jobs. + +To make use of it, publish its assets: + +``` +php artisan vendor:publish --tag=cloud-tasks-assets +``` + +We expose a dashboard at the /cloud-tasks URI. By default, you will only be able to access this dashboard in the local environment. However, within your app/Providers/AppServiceProvider.php file, there is an authorization gate definition. This authorization gate controls access to Cloud Tasks in non-local environments. You are free to modify this gate as needed to restrict access to your Cloud Tasks installation: + + +```php +Gate::define('viewCloudTasks', function ($user) { + return in_array($user->email, [ + 'me@example.com', + ]); +}); +``` + # Authentication Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable with a path to the credentials file. diff --git a/composer.json b/composer.json index 5683ac1..c01c313 100644 --- a/composer.json +++ b/composer.json @@ -9,13 +9,15 @@ ], "require": { "ext-json": "*", - "google/cloud-tasks": "^v1.9", - "firebase/php-jwt": "^5.5", - "phpseclib/phpseclib": "~2.0" + "phpseclib/phpseclib": "~2.0", + "google/cloud-tasks": "^1.10", + "thecodingmachine/safe": "^1.0|^2.0" }, "require-dev": { - "mockery/mockery": "^1.2", - "orchestra/testbench": "^3.5 || ^3.6 || ^3.7 || ^3.8 || ^4.0 || ^5.0" + "orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0", + "nunomaduro/larastan": "^1.0 || ^2.0", + "thecodingmachine/phpstan-safe-rule": "^1.2", + "laravel/legacy-factories": "^1.3" }, "autoload": { "psr-4": { @@ -24,7 +26,8 @@ }, "autoload-dev": { "psr-4": { - "Tests\\": "tests/" + "Tests\\": "tests/", + "Factories\\": "factories/" } }, "extra": { diff --git a/config/cloud-tasks.php b/config/cloud-tasks.php new file mode 100644 index 0000000..dd26f16 --- /dev/null +++ b/config/cloud-tasks.php @@ -0,0 +1,9 @@ + [ + 'enabled' => env('CLOUD_TASKS_MONITOR_ENABLED', false), + ], +]; diff --git a/dashboard/.gitignore b/dashboard/.gitignore new file mode 100644 index 0000000..a84704d --- /dev/null +++ b/dashboard/.gitignore @@ -0,0 +1,4 @@ +node_modules +.DS_Store +dist-ssr +*.local \ No newline at end of file diff --git a/dashboard/.prettierrc.js b/dashboard/.prettierrc.js new file mode 100644 index 0000000..0614ee7 --- /dev/null +++ b/dashboard/.prettierrc.js @@ -0,0 +1,6 @@ +module.exports = { + trailingComma: 'es5', + tabWidth: 2, + semi: false, + singleQuote: true, +} diff --git a/dashboard/README.md b/dashboard/README.md new file mode 100644 index 0000000..c0793a8 --- /dev/null +++ b/dashboard/README.md @@ -0,0 +1,7 @@ +# Vue 3 + Vite + +This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 ` + + + +
+ + + +