Skip to content

Instantly share code, notes, and snippets.

@acidjazz
Created June 11, 2020 21:27
Show Gist options
  • Save acidjazz/0f4e0047b6519692fc9ba21bb1d75efa to your computer and use it in GitHub Desktop.
Save acidjazz/0f4e0047b6519692fc9ba21bb1d75efa to your computer and use it in GitHub Desktop.
github test workflow for a laravel project
name: Test
on:
push:
branches-ignore:
- staging
- production
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: 'MySQL - tweak mysql'
run: |
echo "[mysqld]" | sudo tee -a /etc/mysql/conf.d/mysql.cnf > /dev/null
echo "skip-grant-tables" | sudo tee -a /etc/mysql/conf.d/mysql.cnf > /dev/null
- name: MySQL - restart and add database
run: |
sudo service mysql restart
mysql -u root -e "CREATE DATABASE IF NOT EXISTS \`test-grappling\`"
- uses: actions/checkout@v2
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
- name: Run phpunit
run: vendor/bin/phpunit --color=always --testdox --coverage-text --coverage-html coverage/
- uses: actions/upload-artifact@v2
with:
name: coverage-html
path: coverage/
@acidjazz
Copy link
Author

and here is deploy.yml

name: Deploy
on:
  push:
    branches: [ staging ]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      -
        uses: actions/checkout@v2
      - name: Extract branch name
        shell: bash
        run: echo "::set-env name=BRANCH::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')"
      -
        name: Install Vapor
        run: composer global require laravel/vapor-cli
      - name: Deploy With vapor
        run: /home/runner/.composer/vendor/bin/vapor deploy ${BRANCH} --commit="${GITHUB_SHA}" --message="${GITHUB_MESSAGE}"
        env:
          VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}```

@acidjazz
Copy link
Author

Place these in .github/workflows and set your appropiate secrets and you're done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment