name: Typecho Dev Test

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  php:
    name: PHP ${{ matrix.php }} Tests
    runs-on: ubuntu-latest
    if: ${{ !contains(github.event.head_commit.message, 'skip ci') }}
    strategy:
      fail-fast: false
      matrix:
        php: ['7.4', '8.0', '8.1', '8.2']
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
    - name: Setup PHP only
      uses: shivammathur/setup-php@v2
      with:
        php-version: ${{ matrix.php }}
    - name: Test
      run: |
        find . -type f -name '*.php' -print0 | xargs -0 -n1 -P4 php -l -n | (! grep -v "No syntax errors detected" )
  build:
    name: Typecho Build
    runs-on: ubuntu-latest
    if: ${{ !contains(github.event.head_commit.message, 'skip ci') && github.event_name != 'pull_request' }}
    needs:
        - php
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
    - name: Build
      run: |
        mkdir build
        cp -r LICENSE.txt index.php install.php admin install usr var build/
        mkdir build/usr/uploads/
        chmod 755 build/usr/uploads/
        rm -rf build/admin/src
        rm -rf build/usr/themes/classic-22/static/scss
        cd build && zip -q -r typecho.zip * && mv typecho.zip ../ && cd -
    - name: Upload a Build Artifact
      uses: WebFreak001/deploy-nightly@v1.1.0
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: https://uploads.github.com/repos/typecho/typecho/releases/49532662/assets{?name,label}
        release_id: 49532662
        asset_path: ./typecho.zip
        asset_name: typecho.zip
        asset_content_type: application/zip
        max_releases: 1
