mirror of
https://github.com/ivuorinen/actions.git
synced 2026-01-26 11:34:00 +00:00
135 lines
4.1 KiB
YAML
135 lines
4.1 KiB
YAML
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
|
|
# permissions:
|
|
# - contents: read # Required for checking out repository
|
|
---
|
|
name: Laravel Setup and Composer test
|
|
description: 'Setup PHP, install dependencies, generate key, create database and run composer test'
|
|
author: 'Ismo Vuorinen'
|
|
|
|
branding:
|
|
icon: 'terminal'
|
|
color: 'blue'
|
|
|
|
inputs:
|
|
php-version:
|
|
description: 'PHP Version to use, see https://github.com/marketplace/actions/setup-php-action#php-version-optional'
|
|
required: false
|
|
default: 'latest'
|
|
php-version-file:
|
|
description: 'PHP Version file to use, see https://github.com/marketplace/actions/setup-php-action#php-version-file-optional'
|
|
required: false
|
|
default: '.php-version'
|
|
extensions:
|
|
description: 'PHP extensions to install, see https://github.com/marketplace/actions/setup-php-action#extensions-optional'
|
|
required: false
|
|
default: 'mbstring, intl, json, pdo_sqlite, sqlite3'
|
|
coverage:
|
|
description: 'Specify code-coverage driver, see https://github.com/marketplace/actions/setup-php-action#coverage-optional'
|
|
required: false
|
|
default: 'none'
|
|
token:
|
|
description: 'GitHub token for authentication'
|
|
required: false
|
|
default: ''
|
|
|
|
outputs:
|
|
php-version:
|
|
description: 'The PHP version that was setup'
|
|
value: ${{ steps.setup-php.outputs.php-version }}
|
|
php-version-file:
|
|
description: 'The PHP version file that was used'
|
|
value: ${{ steps.setup-php.outputs.php-version-file }}
|
|
extensions:
|
|
description: 'The PHP extensions that were installed'
|
|
value: ${{ steps.setup-php.outputs.extensions }}
|
|
coverage:
|
|
description: 'The code-coverage driver that was setup'
|
|
value: ${{ steps.setup-php.outputs.coverage }}
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Mask Secrets
|
|
shell: bash
|
|
env:
|
|
GITHUB_TOKEN: ${{ inputs.token }}
|
|
run: |
|
|
if [ -n "$GITHUB_TOKEN" ]; then
|
|
echo "::add-mask::$GITHUB_TOKEN"
|
|
fi
|
|
|
|
- name: Detect PHP Version
|
|
id: php-version
|
|
uses: ivuorinen/actions/php-version-detect@7061aafd35a2f21b57653e34f2b634b2a19334a9
|
|
with:
|
|
default-version: ${{ inputs.php-version }}
|
|
|
|
- uses: shivammathur/setup-php@bf6b4fbd49ca58e4608c9c89fba0b8d90bd2a39f # 2.35.5
|
|
id: setup-php
|
|
with:
|
|
php-version: ${{ steps.php-version.outputs.php-version }}
|
|
extensions: ${{ inputs.extensions }}
|
|
coverage: ${{ inputs.coverage }}
|
|
|
|
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
|
with:
|
|
token: ${{ inputs.token != '' && inputs.token || github.token }}
|
|
|
|
- name: 'Check file existence'
|
|
id: check_files
|
|
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
|
|
with:
|
|
files: 'package.json, artisan'
|
|
|
|
- name: Copy .env
|
|
if: steps.check_files.outputs.files_exists == 'true'
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
php -r "file_exists('.env') || copy('.env.example', '.env');"
|
|
|
|
- name: Install Dependencies
|
|
if: steps.check_files.outputs.files_exists == 'true'
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
|
|
|
- name: Generate key
|
|
if: steps.check_files.outputs.files_exists == 'true'
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
php artisan key:generate
|
|
|
|
- name: Directory Permissions
|
|
if: steps.check_files.outputs.files_exists == 'true'
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
chmod -R 777 storage bootstrap/cache
|
|
|
|
- name: Create Database
|
|
if: steps.check_files.outputs.files_exists == 'true'
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
mkdir -p database
|
|
touch database/database.sqlite
|
|
|
|
- name: Execute composer test (Unit and Feature tests)
|
|
if: steps.check_files.outputs.files_exists == 'true'
|
|
shell: bash
|
|
env:
|
|
DB_CONNECTION: sqlite
|
|
DB_DATABASE: database/database.sqlite
|
|
run: |-
|
|
set -euo pipefail
|
|
|
|
composer test
|