devshop / yaml-tasks
Plugin to run commands from a YML file and pass to GitHub commit status API.
Installs: 4 981
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 1
Type:composer-plugin
Requires
- composer-plugin-api: ^1.0 || ^2.0
- ext-json: *
- consolidation/robo: ^2
- devshop/power-process: @dev
- guzzlehttp/guzzle: ^6
- guzzlehttp/psr7: ^1.9
- http-interop/http-factory-guzzle: ^1.2
- knplabs/github-api: ^3.9||^1.0
- php-http/guzzle6-adapter: 2.x-dev
- teqneers/php-stream-wrapper-for-git: ^2.0
Requires (Dev)
- 2.x-dev
- 1.x-dev
- 1.8.x-dev
- 1.8.0-beta3
- 1.8.0-beta2
- 1.8.0-beta1
- 1.8.0-alpha1
- 1.7.x-dev
- 1.7.0-alpha4
- 1.7.0-alpha3
- 1.7.0-alpha2
- 1.7.0-alpha1
- dev-component/yaml-tasks/env-fixes / 1.6.x-dev
- 1.6.0-alpha4
- 1.6.0-alpha3
- 1.6.0-alpha2
- 1.6.0-alpha1
- dev-bug/local/docker-command
- dev-bug/bitbucket-builds
- dev-bug/bitbucket/integration
- dev-bug/build-fast
- dev-bug/composer-broke
- dev-bug/composer-install-fails-preserve-paths
- dev-bug/deploy
- dev-bug/deploy-apis
- dev-bug/destroyed
- dev-bug/docker-logs-artifacts
- dev-bug/docker/actions
- dev-bug/docker/hub
- dev-bug/everything
- dev-bug/failing-again
- dev-bug/fucked-containers
- dev-bug/full-stack-stuff
- dev-bug/github/actions
- dev-bug/last-passing-commit
- dev-bug/little-things
- dev-bug/no-drush
- dev-bug/provision-files
- dev-bug/queues
- dev-bug/remote-hosts
- dev-bug/reset
- dev-bug/sync
- dev-bug/tasks
- dev-bug/ubuntu-scripts
- dev-bug/unpreserved-paths
- dev-bug/updated-containers
- dev-bug/upgrade
- dev-bug/verify
- dev-bug/verify-fail-after-install
- dev-bugs/beta-blockers
- dev-bugs/contrib
- dev-bugs/various
- dev-component/devshop-behat-extension
- dev-dev/github/fixes
- dev-dev/stuff
- dev-feature/ansible-tweaks
- dev-feature/ansible/faster
- dev-feature/bitbucket-fixes
- dev-feature/commands
- dev-feature/development/lando
- dev-feature/devshop-control-in-root
- dev-feature/devshop-platform
- dev-feature/drupal-10
- dev-feature/hosting/default_hosting_settings
- dev-feature/hosting_docker
- dev-feature/linuxserver
- dev-feature/megamerge
- dev-feature/minor-ansible-improvements
- dev-feature/no-platforms
- dev-feature/php-81-default
- dev-feature/php-intl
- dev-feature/php/8.1-default
- dev-feature/platform-user
- dev-feature/reinstall
- dev-feature/release-docs
- dev-feature/remote-host-container
- dev-feature/site-audit
- dev-feature/ubuntu22
- dev-release-1.8.0-beta1
- dev-release-1.8.0-beta2
- dev-tests/docker/from-devshop-server
- dev-tests/failing-install
- dev-updates/2023-10
- dev-bug/github/settings-ui
- dev-bug/hosting-queue-runner-commands
- dev-feature/php/8.1
- dev-bug/ansible/detect-site
- dev-bug/docker/no-buildtime-tag
- dev-dev/install/platforms
- dev-feature/composer/git-traits
- dev-feature/docker/hub-publish
- dev-ops/ansible/default-project-vars
- dev-php81
- dev-bug/docker/build-again
- dev-bug/docker/removed-too-much
- dev-bug/scripts/fix-path
- dev-bug/sites/git-reset
- dev-feature/docker/build-run
- dev-feature/os/ubuntu20
- dev-feature/os/ubuntu2004
- dev-feature/php-8
- dev-feature/php/8
- dev-feature/php/8.0
- dev-feature/robo/cleanup
- dev-feature/docker/fix-it-all
- dev-feature/components/php-8
- dev-feature/php80
- dev-bug/composer-common-installable
- dev-bug/docker-compose-up
- dev-bug/pr655/tests-failing
- dev-bug/tests-and-local
- dev-feature/php-versions
- dev-feature/shape-up
- dev-feature/ubuntu20
- dev-ops/ansible/update
- dev-release-1.7.0
- dev-testing/php74
- dev-bug/git-split/composer-plugin-api-version
- dev-bug/ch586/main-branch-tests
- dev-bug/ch587/install-sh-forks
- dev-bug/components-ci-fail
- dev-bug/composer-ansible-fail
- dev-bug/composer-fail
- dev-bug/gh385/deploy
- dev-bug/gh656/protect-site
- dev-bug/hosting-queue-stop
- dev-bug/install-builder
- dev-dependabot/add-v2-config-file
- dev-dev/ux/task-site-urls
- dev-feature/ch475/better-install-sh
- dev-feature/ch584/better-dx
- dev-feature/ch86/deploy-component
- dev-feature/git-remote-monitor
- dev-pr/655
- dev-tests/control/pseudo-repo
- dev-feature/gh644/devshop-control-codebase
- dev-bug/chXYZ/yaml-tasks-bugs
- dev-bug/ch112/release-fixes
- dev-bug/ch118/uid-reset
- dev-bug/ch177/detect-hostname
- dev-bug/ch460/bad-1.x-builds
- dev-bug/ch460/scheduled-build-branch
- dev-bug/ch472/composer-devshop-control
- dev-bug/ch477/composer-tests
- dev-bug/ch477/lost-control
- dev-bug/ch479/simplify-ansible-inventory-generation
- dev-bug/ch504/1x-ci-fail
- dev-bug/ch505/ansible-role-vars
- dev-bug/gh642/disabled-sites
- dev-component/devmaster/task-line-numbers
- dev-dev/environment/classes
- dev-dev/support/fixes
- dev-feature/ch115/hugo-site
- dev-feature/ch256/devshop-developers
- dev-feature/ch534/github-actions-checkout
- dev-feature/gh644/path-devmaster-repo
- dev-bug/ch185/composer-2
- dev-bug/ch118/provision-release
- dev-bug/ch118/test-fails
- dev-bug/ch122/test-devshop-control
- dev-bug/ch185/composer-1
- dev-dev/ux/tasks
- dev-feature/ch121/links-to-domains
- dev-feature/ch139/ansible-cloud
- dev-feature/ch139/repos
- dev-ux/create/redirect
- dev-component/composer/devmaster
- dev-integration
- dev-bug/ch101/devshop-test-volumes
- dev-component/composer/deploy
- dev-feature/ch81/composer-devshop
- dev-feature/ch86/deploy
- dev-feature/ch87/rapid-tests
- dev-feature/ch87/rapid-tests-2
- dev-feature/ch89/core-values
- dev-feature/ch90/readme
- dev-ops/docker/dockerfiles
- dev-bug/ch17/test-assets-folder
- dev-bug/ch20/ansible-lint
- dev-bug/ch35/tests-passing
- dev-bug/ch36/little-bugs
- dev-components
- dev-feature/ch37/dev-environment
- dev-feature/test-composer-template
- dev-ci/install/devshop-tech
- dev-ci/makefiles/ci-makefile
- dev-component/composer/set-path
- dev-component/docs
- dev-composer/node/suggests
- dev-dev/devshop/docker-tools
- dev-install/get.devshop.tech
- dev-install/install-sh/ansible-pip
- dev-ops/os/centos8
- dev-pull/589
- dev-ci/github/actions-branches
- dev-ci/github/actions-fixes
- dev-component/github-api-cli/ssl-ignore
- dev-dependabot/composer/composer/composer-1.10.4
- dev-dependabot/composer/composer/composer-1.10.5
- dev-develop
- dev-component/common
- dev-component/github-api-cli/deployments
- dev-component/github-cli
- dev-component/yaml-tasks/output-options
- dev-dependabot/composer/drush/drush-10.2.2
- dev-development/drupalvm
- dev-ops/docker/fast-container
- dev-component/cli/remove-asm
- dev-component/composer/github-api
- dev-dependabot/composer/drush/drush-9.0.0-alpha1
- dev-component/yaml-tasks/bin-path
- dev-component/power-process/must-run-bug
- dev-dependabot/composer/drush/drush-9.4.0
- dev-infra/components/monorepo-testing
- dev-component/composer/power-process
- dev-component/composer/yaml-tasks
- dev-devshop-2020
This package is auto-updated.
Last update: 2024-11-04 12:30:29 UTC
README
Formerly Yaml Tests
Yaml Tasks is a simple composer plugin that make it as simple as possible to define and run a set of commands using YML.
It provides a composer command and an executable script that simply reads a YML file and runs each line as a process.
In addition, it integrates with GitHub's Commit Status API. If GITHUB_TOKEN
is specified, the status of each command will be posted back to GitHub.com, to be displayed on the pull request.
The output is rendered in a way to be easier to read, and proper exit code returns if a single process fails.
Get Started
-
Add YamlTasks to your project.
cd my-composer-project composer require devshop/yaml-tasks
-
Create a
tests.yml
file that looks something like this:myproject/php/lint: find src -name '*.php' -print0 | xargs -0 -n1 php -l myproject/php/cs: description: CodeSniffer command: bin/phpcs --standard=PSR2 -n --colors myproject/debug/environment: | env
-
Run the
yaml-tasks
composer command or theyaml-tasks
bin script:composer yaml-tasks bin/yaml-tasks
or
composer y
Global Install
composer global require devshop/yaml-tasks
To confirm the command is installed, ask for help:
composer yaml-tests --help
Or run the bin/yaml-tasks
command:
bin/yaml-tasks
GitHub Integration
If you pass yaml-tasks
a GitHub Token, it will send the test results as
"commit status" indicators.
There are 3 ways to pass the GitHub Token to YamlTasks:
-
Use the
--github-token
command line option. Don't use this in CI, or you might expose your GitHub token in logs. -
Set a GITHUB_TOKEN environment variable. This is pretty simple in Docker, but can be a challenge if your tasks get run in different environments.
-
Recommended: Create a
.env
file in your repo, or in your user's home directory:GITHUB_TOKEN=abcdefg
There is a
.env.example
file in this directory you can use as an example.
Writing tasks
Create tasks.yml file
By default the composer yaml-tasks
command looks for a tasks.yml file in the project root. You can also pass a path using the --tasks-file
option.
The tasks.yml
file is read as a simple collection of commands. The key can be any string, as long as it is unique in the test suite.
test/dir: pwd test/environment: env
You can also include commands in a list:
lint: - find src -name '*.php' -print0 | xargs -0 -n1 php -l - find web/modules/custom -name '*.php' -print0 | xargs -0 -n1 php -l - find tasks/src -name '*.php' -print0 | xargs -0 -n1 php -l
You can include a description for each test like:
debug: command: env description: Current Environment
Commands in tasks.yml
Yaml Tasks work like Composer Scripts: If your project has the config.bin-dir
set in composer.json
, Composer will automatically add that directory to the PATH when scripts or other commands are run.
For example, you can include PHPUnit and call it without specifying the full path in composer scripts or tasks.yml
composer.json
:
{ "config": { "bin-dir": "bin/" }, "require": { "devshop/yaml-tasks": "^1.5", "phpunit/phpunit": "^8.1" }, "scripts": { "test": [ "which phpunit", "phpunit --version" ] } }
Having the scripts.test
section in composer.json
creates a composer command called composer test
.
tasks.yml
:
test/debug: - which phpunit - phpunit --version
If you want to only maintain one set of scripts, you can reference composer scripts in tasks.yml
:
tasks.yml
:
test/debug: composer test
Running tasks
Once the tasks.yml
file is in place, and the composer yaml-tasks
command is available, you can trigger test runs.
Dry Runs vs Normal
This plugin was also designed to pass these tasks as "Commit Statuses" on GitHub. This allows us to tag the results to the specific commit, pass or fail.
If the environment variable GITHUB_TOKEN
or the command line option --github-token
is NOT set, the --dry-run
option will be forced.
Use the --dry-run
option if you have a token set but do not want to post test results to GitHub.
Run composer yaml-tasks
or, just like all composer commands, you can use shortcuts like compose y
.
composer yaml-tasks
The output will look something like this:
And you will get a nice summary at the end like this:
Yaml-Tasks executable
There is now a "bin" for yaml-tasks, allowing the command to be run by itself.
If you require devshop/yaml-tasks
, you will see a symlink to yaml-tasks
in your bin-dir
.