Laravel #234
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Laravel | |
on: | |
push: | |
pull_request: | |
schedule: | |
- cron: "0 8 * * 6" # 8AM Saturdays | |
workflow_dispatch: | |
jobs: | |
laravel-tests: | |
runs-on: ubuntu-latest | |
continue-on-error: ${{ matrix.experimental }} | |
strategy: | |
matrix: | |
php: ["8.0"] | |
experimental: [false] | |
services: | |
mariadb: | |
image: mariadb:10.3 | |
env: | |
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: yes | |
MARIADB_DATABASE: laravel | |
MARIADB_USER: ci | |
MARIADB_PASSWORD: ci | |
ports: | |
- 3306:3306 | |
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e | |
with: | |
php-version: ${{ matrix.php }} | |
- name: Get Composer Cache Directory | |
id: composer-cache | |
run: | | |
echo "::set-output name=dir::$(composer config cache-files-dir)" | |
- uses: actions/cache@v2 | |
with: | |
path: ${{ steps.composer-cache.outputs.dir }} | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: | | |
${{ runner.os }}-composer- | |
- name: Read .nvmrc | |
run: echo NVMRC=`cat .nvmrc` >> $GITHUB_ENV | |
- name: Setup node | |
uses: actions/setup-node@v2 | |
with: | |
node-version: ${{ env.NVMRC }} | |
- uses: actions/cache@v2 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Copy .env | |
run: php -r "file_exists('.env') || copy('.env.ci', '.env');" | |
- name: Create Database | |
run: touch database/database.tests.sqlite | |
- name: Install Dependencies | |
run: composer install --no-ansi --no-interaction --no-progress | |
- name: Generate key | |
run: php artisan key:generate --no-interaction | |
- name: Install Dependencies | |
run: composer deploy-dev | |
- name: Execute tests via PHPUnit (SQLite) | |
run: vendor/bin/phpunit --configuration phpunit.xml | |
- name: Execute tests via PHPUnit (MariaDB) and publish coverage | |
uses: paambaati/[email protected] | |
env: | |
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | |
XDEBUG_MODE: coverage | |
with: | |
coverageCommand: vendor/bin/phpunit --configuration phpunit.mysql.xml --coverage-clover build/logs/clover.xml | |
- name: Display logs after a failure | |
if: ${{ failure() }} | |
run: cat storage/logs/laravel.log | |
docker: | |
runs-on: ubuntu-latest | |
needs: laravel-tests | |
env: | |
IMAGE_NAME: nfarrington/vatsim-url-shortener | |
steps: | |
- name: Configure IMAGE_VERSION | |
run: | | |
shopt -s extglob | |
IMAGE_VERSION=${GITHUB_REF} | |
IMAGE_VERSION=${IMAGE_VERSION##refs/?(heads/|tags/)} | |
IMAGE_VERSION=${IMAGE_VERSION//\//-} | |
[[ $IMAGE_VERSION == v[[:digit:]]* ]] && IMAGE_VERSION=${IMAGE_VERSION#v} | |
echo "IMAGE_VERSION=$IMAGE_VERSION" >> $GITHUB_ENV | |
- name: Configure IMAGE_TAG | |
run: echo "IMAGE_TAG=$IMAGE_NAME:$IMAGE_VERSION" >> $GITHUB_ENV | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Build and push nginx | |
id: docker_build_nginx | |
uses: docker/build-push-action@v2 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ env.IMAGE_TAG }}-nginx | |
build-args: | | |
APP_COMMIT=${{ github.sha }} | |
APP_VERSION=${{ env.IMAGE_VERSION }} | |
target: nginx | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
- name: Nginx image digest | |
run: echo ${{ steps.docker_build_nginx.outputs.digest }} | |
- name: Build and push php-fpm | |
id: docker_build_php_fpm | |
uses: docker/build-push-action@v2 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ env.IMAGE_TAG }}-php-fpm | |
build-args: | | |
APP_COMMIT=${{ github.sha }} | |
APP_VERSION=${{ env.IMAGE_VERSION }} | |
target: php-fpm | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
- name: php-fpm image digest | |
run: echo ${{ steps.docker_build_php_fpm.outputs.digest }} | |
# Temp fix (from https://github.com/docker/build-push-action/blob/1bc1040caef9e604eb543693ba89b5bf4fc80935/docs/advanced/cache.md) | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |