Skip to content

Instantly share code, notes, and snippets.

@zanechua
Last active April 11, 2023 11:51
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save zanechua/a67ed1de1fff20639edb121bdb0b6e4d to your computer and use it in GitHub Desktop.
Save zanechua/a67ed1de1fff20639edb121bdb0b6e4d to your computer and use it in GitHub Desktop.
Azure Pipeline + Laravel + MySQL + PHPUnit + Laravel Dusk

Azure Pipeline Sample YML File

What the script does

  • Install NodeJS v11.x

  • Install necessary packages, screen; nodejs; mysql-server; google-chrome-stable

  • Updates the MySQL password to poowf

  • Creates the MySQL Database

  • Copy the travis environment file(You can make one for azure)

  • Removes installed composer version(It's composer v1.0 built in 2016) (They fixed it)

  • Export the path for composer

  • Download new composer snapshot and update to stable

  • Install Composer dependencies

  • Run Migrations

  • Generate Key

  • Update NPM

  • Install NPM packages

  • Build package assets

  • Run google-chrome in a screen and detach

  • Run the web server in a screen and detach

  • Run Unit Tests

  • Run Browser Tests

  • Publish Test Results for both Unit and Browser Tests to Pipelines

# PHP
# Test and package your PHP project.
# Add steps that run tests, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/php
pool:
vmImage: 'Ubuntu 16.04'
variables:
phpVersion: 7.2
steps:
- script: |
sudo update-alternatives --set php /usr/bin/php$(phpVersion)
sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
php -version
displayName: 'Use PHP version $(phpVersion)'
- script: |
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get install -y build-essential debconf-utils screen nodejs mysql-server google-chrome-stable
sudo apt-get install -y unzip xvfb autogen autoconf libtool pkg-config nasm
sudo mysql -uroot -proot -e "use mysql; update user set authentication_string=PASSWORD('poowf') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
sudo mysql -u root -ppoowf -e 'create database invoiceneko_test;'
displayName: 'Installing System Dependencies'
- script: |
mysql --version
displayName: 'MySQL Version'
- script: |
cp .env.travis .env
displayName: 'Environment Setup'
- script: |
sudo composer self-update
composer install --no-interaction --prefer-dist --no-suggest
composer --version
displayName: 'Installing Package Dependencies'
- script: |
php artisan key:generate
php artisan migrate
displayName: 'Running Migrations'
- script: |
sudo npm i -g npm
sudo chown -R vsts:vsts ~/.npm
sudo chown -R vsts:vsts ~/.config
npm install
npm run prod
node -v
displayName: 'Generating build assets'
- script: |
screen -d -m google-chrome-stable --headless --disable-gpu --disable-dev-shm-usage --disable-software-rasterizer --remote-debugging-port=9222 http://localhost &
screen -d -m php artisan serve &
displayName: 'Starting Chrome and the Web Server'
- script: |
vendor/bin/phpunit --log-junit tests/Results/TEST-phpunit-junit.xml
displayName: 'Running Unit Tests'
- script: |
php artisan dusk --log-junit tests/Results/TEST-dusk-junit.xml
displayName: 'Running Browser Tests'
# Publish Test Results to Azure Pipelines/TFS
- task: PublishTestResults@2
inputs:
testRunner: 'JUnit' # Options: JUnit, NUnit, VSTest, xUnit
testResultsFiles: '**/TEST-*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/tests/Results' # Optional
mergeTestResults: false # Optional
#testRunTitle: # Optional
#buildPlatform: # Optional
#buildConfiguration: # Optional
#publishRunAttachments: true # Optional
condition: always()
@etiennepouliot
Copy link

Had to do something similar, but I couldn't get the MySQL to start with a recent version of Ubuntu that is now in Azure. Here how I did it : https://gist.github.com/etiennepouliot/acc4ab7f30a9c73434e6f15aa45fffcb

@Reyh
Copy link

Reyh commented Apr 11, 2023

Had to do something similar, but I couldn't get the MySQL to start with a recent version of Ubuntu that is now in Azure. Here how I did it : https://gist.github.com/etiennepouliot/acc4ab7f30a9c73434e6f15aa45fffcb

hi, you must start manually the mysql service, before run it :
sudo service mysql start

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