GitHub Actions is a continuous integration platform that comes with GitHub.
Integrating Blackfire with GitHub Actions enables running Blackfire tests and scenarios, through PHPUnit tests, the Blackfire Player, or the Blackfire CLI Tool. It also makes it possible to trigger Blackfire builds.
Note
GitHub Actions support is available, via the setup-php action.
While this action is designed for PHP, it installs all needed components, making Blackfire usable by apps written in any language supported by Blackfire (Python, Go…).
To set up Blackfire on GitHub Actions, you need to define some secret variables in your project settings.
Define secrets for your Client credentials:
Define secrets for the Server credentials. Select the Blackfire environment which you want to use for your GitHub Actions-triggered tests:
Within your workflow, configure each job where you need Blackfire:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Blackfire via setup-php Action uses: shivammathur/setup-php@v2 with: # PHP Only: Setup PHP extensions, including Blackfire Probe. # It is recommended to disable xdebug. # Not needed for other languages. extensions: blackfire, :xdebug # Setup Blackfire Agent and CLI tool, and Blackfire Player tools: blackfire, blackfire-player env: # Expose your Blackfire credentials stored in secrets # as environment variables. BLACKFIRE_SERVER_ID: ${{ secrets.BLACKFIRE_SERVER_ID }} BLACKFIRE_SERVER_TOKEN: ${{ secrets.BLACKFIRE_SERVER_TOKEN }} BLACKFIRE_CLIENT_ID: ${{ secrets.BLACKFIRE_CLIENT_ID }} BLACKFIRE_CLIENT_TOKEN: ${{ secrets.BLACKFIRE_CLIENT_TOKEN }} # Trigger a profile using Blackfire CLI tool. - name: Profile list-users command env: APP_ENV: prod APP_DEBUG: 0 run: blackfire run php bin/console app:list-users # Other example using Python: #run: blackfire run python my_script.py |
Use option --env
to target a specific environment (see documentation).
Thanks to the setup-php action,
you can use Blackfire Player to run your scenarios and get build reports each time you push a new version of your
code on GitHub. setup-php
also supports the Symfony CLI tool. This
enables you to start the Symfony local webserver so that you can execute the
Blackfire Player scenarios directly from your running job.
Note
When using other languages than PHP, e.g. Python, you may use other
webservers like gunicorn
or the Django development server.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Blackfire via setup-php Action uses: shivammathur/setup-php@v2 with: php-version: '7.4' extensions: blackfire, :xdebug # Setup Blackfire Agent and CLI tool, Blackfire Player, and Symfony CLI tools: blackfire, blackfire-player, symfony env: BLACKFIRE_SERVER_ID: ${{ secrets.BLACKFIRE_SERVER_ID }} BLACKFIRE_SERVER_TOKEN: ${{ secrets.BLACKFIRE_SERVER_TOKEN }} BLACKFIRE_CLIENT_ID: ${{ secrets.BLACKFIRE_CLIENT_ID }} BLACKFIRE_CLIENT_TOKEN: ${{ secrets.BLACKFIRE_CLIENT_TOKEN }} - name: Symfony local server start env: APP_ENV: prod APP_DEBUG: 0 run: | symfony local:server:start -d # Start Symfony local webserver # Run Blackfire Player scenarios from .blackfire.yaml or .bkf files blackfire-player run --endpoint=http://localhost:8000 --blackfire-env=<your-blackfire-environment-id> .blackfire.yaml |
setup-php action
supports the blackfire
CLI tool. It enables to trigger a Blackfire build:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup PHP Action uses: shivammathur/setup-php@v2 with: # Setup Blackfire Agent and CLI tool and Blackfire Player tools: blackfire, blackfire-player env: BLACKFIRE_SERVER_ID: ${{ secrets.BLACKFIRE_SERVER_ID }} BLACKFIRE_SERVER_TOKEN: ${{ secrets.BLACKFIRE_SERVER_TOKEN }} BLACKFIRE_CLIENT_ID: ${{ secrets.BLACKFIRE_CLIENT_ID }} BLACKFIRE_CLIENT_TOKEN: ${{ secrets.BLACKFIRE_CLIENT_TOKEN }} - name: Trigger a Blackfire Build run: | blackfire build-trigger <ENDPOINT> --env=<ENV-UUID> --token=<TOKEN-VALUE> |