Giter VIP home page Giter VIP logo

psh's Introduction

Scrutinizer Code QualityBuild Statuscodecov

Latest Stable Version Total Downloads Latest Unstable Version License

PSH - PHP shell helper

Keep using your standard shell scripts

PSH is intended to be a simple and easy alternative to other build script solutions.

Table of contents

Introduction

You do not have to learn a new - and in most cases much more verbose - language, but can scale your existing skills on the command line.

Key benefits are:

  • Share your existing shell scripts with your team members
  • Add error handling if single statement in the sh scripts fails
  • Replace placeholders in sh scripts with variables
  • Overload variables and scripts in an environment configuration

Installation

Although you can use PSH as a composer dependency, we recommend to use the PHAR archive instead. PSH only communicates through the shell with your application and therefore does not need any influence on your other project dependencies.

Through composer

Locally:

composer require shopware/psh --dev

Globally:

composer global require shopware/psh

As a PHAR archive

Download psh.phar to your local environment.

wget https://shopwarelabs.github.io/psh/psh.phar # PHP7 Version
chmod +x psh.phar

As a PHAR archive via phive (preferred)

phive install psh

If you want to know how to install phive please click here.

Build it yourself

PSH is used to build itself. You need to clone the repository and install the composer dependencies by yourself first.

git clone https://github.com/shopwareLabs/psh.git
cd psh
composer install # assuming you have composer installed globally
composer bin box install # box is needed to build phar file

./psh unit # verify your installation by executing the test suite.
./psh build 

This will create a release phar in the build/psh.phar directory. The project itself requires PHP 7.2+.

Usage

Notice: The YAML configuration format is deprecated and will be removed in version 2.0. If you need the old documentation, please refer to older versions of this document

PSH is a CLI application. Before you can use it you need to create a configuration file in your project root named .psh.xml or .psh.xml.dist.

Configuration

The minimum required file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<psh xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopwareLabs/psh/master/resource/config.xsd">

</psh>

The root element (<psh>) can contain one many or all if the following configuration options.

Paths

In order to use psh as a script executor, you need to define the locations in which to search.

<path>deployment/scripts</path>
<path>test/scripts</path>
<path>more/scripts</path>

PSH will then search in all these locations for *.sh files. These scripts can then be executed through PSH.

Notice: If the script name starts with a dot (.) it will be excluded from the listing, but is callable like any other script. > psh.phar .hidden-action

Placeholders

Placeholders in your scripts looks like this:

ln -s __PATH__

The placeholder __PATH__ now needs to be part of your configuration file as either a constant or a variable.

Notice: All placeholders must be written in uppercase in scripts. Even if defined otherwise in configuration, replacement only works uppercase. With (sic!) add the end of a placeholder it will be escaped. As an example __DIR__(sic!).

Constants

Constants are the basic solution to placeholder replacements. You define placeholders in your config like this:

<placeholder>
    <const name="PATH">/var/www</const>
</placeholder>

This will then execute

ln -s /var/www

Variables

With variables you can use the output of one line shell statements in your scripts.

<placeholder>
    <dynamic name="PATH">echo $HOME</dynamic>
</placeholder>

The Variables get executed before the actual statement is executed, but you can imagine the outcome to be equivalent to:

ln -s `echo $HOME`

Dotenv

With dotenv you have the ability to load .env-files of your project.

<placeholder>
    <dotenv>.env</dotenv>
</placeholder>

You can also configure multiple paths to .env files.

<placeholder>
    <dotenv>.env</dotenv>
    <dotenv>.env2</dotenv>
</placeholder>

.env2 overrides .env in this example.

Example:

.psh.xml

<path>dev-ops/common/actions"</path>
<placeholder>
    <dotenv>.env</dotenv>
</placeholder>

.env

TEST=mytest

dev-ops/common/actions/test.sh

#!/usr/bin/env bash

echo __TEST__

Require

It may be necessary to require a placeholder to be set, but can't set right away. One such example might be a system dependent path. PSH allows you to communicate this to the user by adding this:

<placeholder>
    <require name="FOO" description="Foo needs to be a reference to bar"/>
</placeholder>

Now unless foo is set, it is not possible to execute any psh script. The description is optional and can be omitted.

Templates

If your application depends on files that are not part of your repository because they differ for different systems (Typically *.dist files), you can use templates to achieve automatic deployment of these files.

<template 
    source="templates/consts.tpl" 
    destination="app/consts.php"
/>

This reads the contents of templates/consts.tpl, replaces placeholders with constants or variables from your configuration and writes the result to app/consts.php.

It is even possible to use placeholders in template destinations:

<template
    source="templates/consts.tpl"
    destination="app/consts-__ENVIRONMENT__.php"
/>

Environments

Environments are used to extend or overwrite your base configuration. You can add more scripts, redefine or add constants or variables. A environment called foo may look like this:

<environment name="foo">

    <path>foo/sh/scripts</path>
    <path>bar/sh/scripts</path>
    
    <placeholder>
        <const name="TEST">1</const>
        <dynamic name="ID">id</dynamic>   
    </placeholder>

</environment>

This environment loads all scripts from foo/sh/scripts and bar/sh/scripts, adds a constant TEST and a variable ID. If you want to call a script in this environment you have to prefix your call with foo:.

In order to exclude a whole environment from the listing add the hidden attribute to the environment tag and set it to true, like this:

<environment name="internal" hidden="true">
    <path>internal/only/scripts</path>
</environment>

These scripts can be executed like any regular script, they will just not be shown in the listing.

Headers

Optionally - and just for fun - you can output a ASCII header in front of every PSH execution.

    <header><![CDATA[
         _
     ___| |__   ___  _ ____      ____ _ _ __ ___
    / __| '_ \ / _ \| '_ \ \ /\ / / _` | '__/ _ \
    \__ \ | | | (_) | |_) \ V  V / (_| | | |  __/
    |___/_| |_|\___/| .__/ \_/\_/ \__,_|_|  \___|
                    |_|
    ]]></header>

Overriding configuration file

You can place a .psh.xml.override inside your directory where the .psh.xml is located to override the specific configurations.

Notice: You can overwrite a XML config file with a YAML file to ease the migration from one format to the other.

Importing configuration files

You can import environments, actions and placeholders by using the import statement and telling psh to look in another place.

<import path="another/config/file/location" />

These directories should contain a psh.xml or psh.xml.dist. If no file is found a warning is issued but no braking error, since it may very well be that psh is currently installing or downloading the files. You can also use a glob pattern like "tools/**/config"

Notice: This happens through merging the different configurations into one. Be aware that you might overwrite base configuration.

PSH-Scripts

Although most of your existing sh scripts should work just fine, you may find some of the following additions useful or necessary.

Keep in mind: Commands will be validated for successful execution -> All failures will fail the script!

Defining placeholders

In order to ensure that your scripts are reusable you can add placeholders that PSH will replace with configured values. All placeholders start and end with __, and contain only upper case letters, numbers, and single _ characters.

__TEST_IT__

Including other actions

It is possible to include other scripts by it's name.

ACTION: build # default environment or
ACTION: pipelines:build # if it's in an environment

The benefit of this instead of Including other scripts is that you don't have to deal with absolute or relative paths in general.

Including other scripts

Prefixing a line with INCLUDE: will treat the remaining part of the line as the path to another script to be included and executed here.

INCLUDE: my/sub/script.sh

If the path is relative, PSH will attempt to load the script relative to the location of the current script or relative to the configuration file.

On demand templates

Prefixing a line with TEMPLATE: will trigger an on demand template creation. The remaining part of the line then must look like this: SOURCE_PATH:DESTINATION_PATH

TEMPLATE: ../templates/template.ini.tpl:../destination/template.ini

Notice that all paths here must be relative to the script location.

Defer execution to the background

Execute the script in the background, so the following command gets executed right away

D: php generate_some_things.php

Wait for all deferred commands to execute

If you then want to wait for all results, just add a WAIT in there.

WAIT:

Open a ssh connection to another machine

Many dev-ops script open a SSH channel to a locally running virtual machine / container or a remote staging / test system. If you do this through PSH you have to prefix the line with TTY:

TTY: vagrant ssh

Ignoring if a statement errored

Contrary to your usual shell scripts, to PSH it matters if a sh statement fails or not. If you need it to ignore errors, you have to prefix the line with I:

I: rm -R sometimes/there

Breaking statements into multiple lines

If a single shell statement is to long for a single line, you can break it in PSH and intend it with three spaces in the next line. PSH will then concatenate it prior to execution and execute it all in one.

bin/phpunit
    --debug
    --verbose

Description

You can add a description to a script which will be printed when the command list will be displayed.

#!/usr/bin/env bash
#DESCRIPTION: My useful comment.

Downsides

  • export statements and internal variables do not work, since the statements do no longer share a single environment.
  • Statements that change the flow of a script do not work out of the box.

BASH-Scripts

PSH allows you to execute bash scripts directly. Most features from the above described PSH-Scripts do not work in this part of the runtime, but placeholder usage is still possible an encouraged.

So if you have Bash scripts that you want PSH to execute directly just add a second line after the shebang:

#!/usr/bin/env bash
# <PSH_EXECUTE_THROUGH_CMD>

FOO="BAR"

echo $PWD
echo $FOO
echo __PLACEHOLDER__

# <PSH_EXECUTE_THROUGH_CMD> will advice PSH to execute the script through your current OS.

Notice: PSH is written for security and predictability first, so it will warn you if you forget to add set -euo pipefail to the beginning of your script.

Internals

  • If and only if a placeholder is present PSH will internally create a hidden file in the same directory and mark it executable, please make shure that your environment allows that.
  • Future versions of PSH will change this to requiring a special shebang line for PSH-Scripts, please be aware of that (Something like #!/usr/bin/env psh).

Executing it

The general format is ./psh.phar <application-options> <script-names> <script-options>. The only currently supported application option is --no-header, script names are a comma separated list of actions (or one) and script options are key value pairs to overwrite placeholders. Let's look at some examples:

Executing the phar will print a listing overview of all available commands

> ./psh.phar

###################
Available commands:

	- build
	- unit

2 script(s) available

The first argument is always the script name. This for example will execute the unit script:

> ./psh.phar unit

###################
Starting Execution of 'unit' ('actions/unit.sh')


(1/3) Starting
> bin/php-cs-fixer fix
	You are running php-cs-fixer with xdebug enabled. This has a major impact on runtime performance.
	
	Loaded config from "/var/www/swag/psh/.php_cs".
	
	[....]

You can add more commands to be executed in a chain, by comma separating the script names:

> ./psh.phar unit,build #executes both scripts in order

You can add parameter for replace placeholder in your .sh files like the following examples:

    ./psh.phar unit --param someValue  #or
    ./psh.phar unit --param=someValue --otherParam value --onMoreParam=value ...
    ./psh.phar list --add -l

in your .sh files write.

    ls __ADD__

executes:

    ls -l

Bash Autocompletion

Bash autocompletion is only provided by PSH-Global. This will install a global script that fetches the psh.phar file in your project and that will install the autocompletion for you.

psh's People

Contributors

bcremer avatar dennisgarding avatar dependabot[bot] avatar dnoegel avatar janbuecker avatar janpietrzyk avatar jensknipper avatar jissereitsma avatar nlubisch avatar pascalthesing avatar peter-bztrs avatar sebastianfranze avatar svenfinke avatar teiling88 avatar xpand4b avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

psh's Issues

Add used config files to startup output

On startup PSH should print out wich config file(s) are used. Therefore something like the following should be added to the output

> Using ./.psh.yml.dist extended by ./psh.yaml.overwrite

Invalid template path error

Also here use a nice error message instead of the raw exception if the template directory/file does not exist:

PHP Fatal error:  Uncaught InvalidArgumentException: File source not found in "/var/www/jp/psh-demo/my/templates/greet.tpl" in phar:///var/www/jp/psh-demo/psh.phar/src/ScriptRuntime/Template.php:29

Command line parameters

It would be nice to set or even overwrite placeholders through the command line.

> ./psh.phar init --env=dev
> ./psh.phar init --env="string that must be parsed"
> ./psh.phar init --env="echo my_script.sh" # should **not** execute the script depending on the type of variable

Would then result for

echo __ENV__ 

in

> dev

Remember the issue with replacing dynamic variables with constant values. All CLI-Parameters should always be created as constants

This idea was brought forward by @janwalther in #18. Therefore it is labeled question, as in "if this is not what you want, please comment" ;)

Bug: floats with only `0` as decimal places are converted to integer

In the Shopware development template I want to explicitly use the docker image webdevops/php-apache-dev:8.0. For this I tried to use the following configuration:

const:
  DOCKER_IMAGE_PHP: webdevops/php-apache-dev
  DOCKER_IMAGE_PHP_VERSION: 8.0

If I do so, docker will try to pull webdevops/php-apache-dev:8 (note the missing .0) which is not available on dockerhub. I got a workaround by wrapping it in quotes which works fine on Linux:

const:
  DOCKER_IMAGE_PHP: webdevops/php-apache-dev
  DOCKER_IMAGE_PHP_VERSION: "8.0"

Today we tried to set it up on a MacBook of a colleague, although it's wrapped with quotes it will still convert it to an integer and therefore try to pull that non-existent image tag. We tried to escape them with the following options which all didn't work. They all were put into the docker-compose.override.yml literally:

\"8.0\"
8\.0
8.0 !!float

We also tried it with single quotes ('8.0') which led to the same result as double quotes.

For now we just use 8.1 on macOS which works fine. Is there a solution to this or is this something which has to be adjusted in the psh code?

Increase process time limit

When I try to run psh unit tests for SwagImportExport I run into timeout issues as Symfony Process kills processes by default after 60 seconds running.
Either increasing this limit globally or as a CLI option would be a very welcome addition.

Add optional parameters

If you add a placeholder in your script and omit the option on the CLI a RuntimeException is thrown.

PHP Fatal error:  Uncaught RuntimeException: Missing required value for "PROVISION" in phar:///.../src/ScriptRuntime/TemplateEngine.php:55
Stack trace:
#0 phar:///.../src/ScriptRuntime/TemplateEngine.php(26): Shopware\Psh\ScriptRuntime\TemplateEngine->getValue('__PROVISION__', Array)
#1 phar:///.../src/ScriptRuntime/ProcessExecutor.php(117): Shopware\Psh\ScriptRuntime\TemplateEngine->render('echo "__PROVISI...', Array)
#2 phar:///.../src/ScriptRuntime/ProcessExecutor.php(66): Shopware\Psh\ScriptRuntime\ProcessExecutor->getParsedShellCommand(Object(Shopware\Psh\ScriptRuntime\ProcessCommand))
#3 phar:///.../src/Application/Application.php(170): Shopware\Psh\ScriptRuntime\ProcessExecutor->execute(Object(Shopware\Psh\Listing\Script), Array)
#4 phar:///.../p in phar:///.../src/ScriptRuntime/TemplateEngine.php on line 55

Instead of throwing the Exception i would expect a default value if the option is not passed, so that i can handle whether the option is passed or not.

create SSH_ENTER command

It would be very nice if we create a SSH_ENTER command do execute shell scripts on a remote host without sshpass.

ls
ping

SSH_ENTER: __REMOTE__ /var/ww/shop

The schemaOrCallable argument has to be a valid path to XSD file or callable.

Using the psh.phar file cause an error with an xml configuration file.
config.xsd doesnt exist.

jenkins@forestsoft:/www/shopware-plugins/plugin-builder$ bin/psh.phar -v
PHP InvalidArgumentException: The schemaOrCallable argument has to be a valid path to XSD file or callable. in phar:///www/shopware-plugins/plugin-builder/bin/psh.phar/vendor/symfony/config/Util/XmlUtils.php on line 88
PHP Stack trace:
PHP 1. {main}() /www/shopware-plugins/plugin-builder/bin/psh.phar:0
PHP 2. require() /www/shopware-plugins/plugin-builder/bin/psh.phar:10
PHP 3. Shopware\Psh\Application\Application->run($inputArgs = array (0 => 'bin/psh.phar', 1 => '-v')) phar:///www/shopware-plugins/plugin-builder/bin/psh.phar/psh:12
PHP 4. Shopware\Psh\Application\ApplicationFactory->createConfig($rootDirectory = '/www/shopware-plugins/plugin-builder', $params = array (0 => 'bin/psh.phar', 1 => '-v')) phar:///www/shopware-plugins/plugin-builder/bin/psh.phar/src/Application/Application.php:67
PHP 5. Shopware\Psh\Config\XmlConfigFileLoader->load($file = '/www/shopware-plugins/plugin-builder/.psh.xml', $params = array ()) phar:///www/shopware-plugins/plugin-builder/bin/psh.phar/src/Application/ApplicationFactory.php:54
PHP 6. Shopware\Psh\Config\XmlConfigFileLoader->loadXmlRoot($file = '/www/shopware-plugins/plugin-builder/.psh.xml') phar:///www/shopware-plugins/plugin-builder/bin/psh.phar/src/Config/XmlConfigFileLoader.php:67
PHP 7. Symfony\Component\Config\Util\XmlUtils::loadFile($file = '/www/shopware-plugins/plugin-builder/.psh.xml', $schemaOrCallable = 'phar:///www/shopware-plugins/plugin-builder/bin/psh.phar/src/Config/../../resource/config.xsd') phar:///www/shopware-plugins/plugin-builder/bin/psh.phar/src/Config/XmlConfigFileLoader.php:195

The schemaOrCallable argument has to be a valid path to XSD file or callable.

Phar archive via composer

I suggest that a separate composer package containing the phar archive only is being set up.
Loading the phar file via composer is much more convenient.
Especially because minor versions and bugfixes are automatically updated if using the correct version constraints in your composer.json.

PHPStan, Psalm and Deptrac are just some examples of projects using this approach.

composer require shopware/psh --dev fails

die Installation schlägt fehl!
Umgebung: LINUX (Mittwald Server), PHP 7.2

Problem 1
- Installation request for shopware/psh ^1.4 -> satisfiable by shopware/psh[v1.4.0].
- Conclusion: remove symfony/dependency-injection v4.4.1
- Conclusion: don't install symfony/dependency-injection v4.4.1
....
Installation request for symfony/dependency-injection (locked at v4.4.1, required as ~4.4) ...

Installation failed, reverting ./composer.json to its original content.

Update installation instructions to reflect not suitable for composer dependency

The installation instructions suggest it can be used as a composer dependency:

Installation
Although you can use PSH as a composer dependency, we recommend to use the PHAR archive instead. PSH only communicates through the shell with your application and therefore does not need any influence on your other project dependencies.

However, apparently this is not the case:

psh should be used as an phar archive and not as a composer requirement.

Originally posted by @teiling88 in #97 (comment)

Xml ist invalide

Meine .psh.xml enthält folgenden Inhalt und ich erhalte die Fehlermeldung "The schemaOrCallable argument has to be a valid path to XSD file or callable.". Ich benutze die von euch bereitgestellte phar.

<?xml version="1.0" encoding="UTF-8"?>

<psh xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopwareLabs/psh/master/resource/config.xsd">

    <header>TEST</header>
    <import path="tests"/>
    <import path="**/*"/>
    <path>actions</path>
</psh>

PHP 8 Support

Fatal error: Uncaught TypeError: abs(): Argument #1 ($number) must be of type int|float, string given in phar:///builds/shopware/5/product/shopware/psh.phar/vendor/symfony/yaml/Parser.php:554
Stack trace:
#0 phar:///builds/shopware/5/product/shopware/psh.phar/vendor/symfony/yaml/Parser.php(554): abs('')
#1 phar:///builds/shopware/5/product/shopware/psh.phar/vendor/symfony/yaml/Parser.php(254): Symfony\Component\Yaml\Parser->parseValue('|', 0, 'mapping')
#2 phar:///builds/shopware/5/product/shopware/psh.phar/src/Config/YamlConfigFileLoader.php(102): Symfony\Component\Yaml\Parser->parse('header: |\n  SHO...')
#3 phar:///builds/shopware/5/product/shopware/psh.phar/src/Config/YamlConfigFileLoader.php(53): Shopware\Psh\Config\YamlConfigFileLoader->parseFileContents('header: |\n  SHO...')
#4 phar:///builds/shopware/5/product/shopware/psh.phar/src/Application/ApplicationFactory.php(41): Shopware\Psh\Config\YamlConfigFileLoader->load('/builds/shopwar...', Array)
#5 phar:///builds/shopware/5/product/shopware/psh.phar/src/Application/Application.php(57): Shopware\Psh\Application\ApplicationFactory->createConfig('/builds/shopwar...', Array)
#6 phar:///builds/shopware/5/product/shopware/psh.phar/psh(12): Shopware\Psh\Application\Application->run(Array)
#7 /builds/shopware/5/product/shopware/psh.phar(10): require('phar:///builds/...')
#8 {main}
  thrown in phar:///builds/shopware/5/product/shopware/psh.phar/vendor/symfony/yaml/Parser.php on line 554

Invalid script path error

Would be nice to have a prettier error message if script paths are invalid.

Warning:  scandir(/var/www/jp/psh-demo/path/to/my/scripts): failed to open dir: No such file or directory

PHP constants in template files

I need an escape character for placeholders to prevent psh to replace __DIR__ with the placeholder value.

As a workaround - i create a placeholder __DIR__ with the value __DIR__ 🙈

Yaml Parser does not only provide strings

Currently you can not set placeholders as integers

const:
   DEVPORT: 8080

Leads to

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Shopware\Psh\ScriptRuntime\SimpleValueProvider::__construct() must be of the type string, integer given, called in phar:///var/www/swag/shopware-x/psh.phar/src/ScriptRuntime/ProcessEnvironment.php on line 47 and defined in phar:///var/www/swag/shopware-x/psh.phar/src/ScriptRuntime/SimpleValueProvider.php:19
Stack trace:
#0 phar:///var/www/swag/shopware-x/psh.phar/src/ScriptRuntime/ProcessEnvironment.php(47): Shopware\Psh\ScriptRuntime\SimpleValueProvider->__construct(8080)
#1 phar:///var/www/swag/shopware-x/psh.phar/src/ScriptRuntime/ProcessEnvironment.php(34): Shopware\Psh\ScriptRuntime\ProcessEnvironment->initializeConstants(Array)
#2 phar:///var/www/swag/shopware-x/psh.phar/src/Application/ApplicationFactory.php(80): Shopware\Psh\ScriptRuntime\ProcessEnvironment->__construct(Array, Array, Array)
#3 phar:///var/www/swag/shopware-x/psh.phar/src/Application/Application.php(183): Shopware\Psh\Application\ApplicationFactory->createProcessExecutor(Object(Shopware\Psh\List in phar:///var/www/swag/shopware-x/psh.phar/src/ScriptRuntime/SimpleValueProvider.php on line 19
jpietrzyk@SW-NB-JP:/var/www/swag/shopware-x$ ./psh.phar administration:watch

A string cast during config load is necessary.

override .psh.yml

It would be nice to provide more than one configuration file, i.e. through a .psh.yml.override.

Implement a plugin system

There might be functions that are useful for PSH, but not in every project. I think about stuff that adds some convenience, like bridges for other tools like ant or the symfony cli. As these tools are not used in every project, it would be great to have a plugin system that provides the possibility to add these commands.

Why am I not simply adding scripts?

I'm thinking about adding functionality that goes beyond a simple command. Thins like loading commands from ant or symfony. The plugins could be adding dynamic collections of commands. Of course, this could be done by adding a bridge script that gets the command as a parameter, but then you lose features like a complete list of commands, the search and autocompletion.

How?

I'm not sure about that... probably we could provide an interface with functions that need to be implemented, and psh is going the collection of plugins and calling the necessary functions from the plugins. The most simple plugin would only contain one .php file, more complex stuff could make use of separate services that are used by this class. But I'm not too happy with this... any other ideas?

sub environments

it would be great if we can create nested environments. As an example:

default init for local dev environment:
./psh.pahr init

default init for local dev environment with docker 7.1 container:
./psh.phar init:php7.1

default init for ci environment:
./psh.pahr ci:init

default init for local dev environment with docker 7.1 container:
./psh.phar ci:init:php7.1

Multiple paths per environment

Given a software project with a set of environments, you may want to use the existing environment with some 3rd party scripts.

Example use case
A simple example would be a software project with some environments like local or CI and an extension for that project which comes from another repository. You now want to use the environment from the main project and run your own scripts provided from the extension repository in the same CI environment without duplicating the whole environment itself into that extension.

My current solution is to copy the scripts into the core environments but that's a little bit hacky...

A change to psh could be to extend an existing environment by specifying multiple paths to read from. Maybe it is possible to solve this problem with #18 ?

Constant concatenating

I have a command which uses 2 constants, __APP_HOST__ and __APP_PATH__. The command needs both constants concatenated to create a url.

Example values

APP_HOST: 'github.com'
APP_PATH: '/shopwareLabs/psh'

Example command

curl http://__APP_HOST____APP_PATH__

Expected result

curl http://github.com/shopwareLabs/psh

Given result

PHP Fatal error:  Uncaught RuntimeException: Missing required value for "APP_HOST____APP_PATH" in phar:///Users/jb/web/master/psh.phar/src/ScriptRuntime/TemplateEngine.php:55

Relative Path problem

While executing psh.phar commands from a remote bash the relative pathes could not been resolved.

Bug: Only one included script is executed

I have a similar directory structure to the shopware 6 development template:

dev-ops
-- common
---- actions
---- scripts
------ my-script.sh
-- testenv
---- actions
------ my-action.sh
---- scripts
------ my-second-script.sh

The "scripts" directories should contain bash scripts that are used in actions. But they should not get called as an action, thats why there is a special directory for them.

This is the "my-action.sh":

#!/usr/bin/env bash
#DESCRIPTION: My action

INCLUDE: dev-ops/common/scripts/my-script.sh
INCLUDE: dev-ops/testenv/scripts/my-second-script.sh

For whatever reason only the second script is executed now. There is only 1/1 step. If I remove the second script, the first script is working. But if I add the second script again, the first script is skipped again.

I'm using the current psh.phar downloaded today. Am I doing something wrong, or is that a bug?

EDIT: The problem only occurs if I include scripts having the # <PSH_EXECUTE_THROUGH_CMD> comment. If I remove that from my scripts and just add a echo Hello every script is executed.

Implement .env support

Implement a way to load environment variables from .env files in a global or environment-specific way.
e.g.

dotenv: 
  - .env
  - ./path/to/.env
environments:
  foo:
    dotenv:
      - foo/.env

Add local placeholders

Since PSH is now used on multiple different systems by different people it seems to be about time to add some local variable handling and helpers.

const: [...]
dynamic: [...]
local:
   foo: 
      description: "Set foo to bar or baz" (optional if has default)
      default: "bar" (optional if has description)
      storable: true|false (optional: default true)

On first use of a particular environment PSH should ask for these parameters and (optionally) write them to a .overwrite file.

Parse symfony cli commands

I'd like to implement this as one of the first plugins for the plugin system.

Since this is used in projects with other "command collections" - like the symfony cli - it might be convenient to offer the possibility to parse these and use psh as the single interaction point. In combination with psh-global, this would provide things like autocomplete for the symfony cli.

Symfony is not providing a simple list with just the commands and no overhead, so the parsing might be quite tedious. To enable a fast autocompletion and a good overall performance, it might be a good idea to introduce a command cache.

The commands should probably be prefixed with a custom name and the group header should describe that these commands are not coming from psh.

Support for defining ENV variables

It would be nice to be able to define some ENV variable in the scripts.

e.g. this command prints out the database credentials for every one to see (and they might
even be logged). It would be great to be able to define an ENV variable to hold the password, in the case of mysql this would be MYSQL_PWD

mysql -u '__DB_USER__' -p'__DB_PASSWORD__' -h '__DB_HOST__' --port='__DB_PORT__' -e "DROP DATABASE IF EXISTS \`__DB_NAME__\`"

Shortcut for including other actions

Im writing some scripts and want to include other tasks i've written before.
I kinda find it tedious to write absolute / relative paths for some task.
It's also hard to read especially relative paths like this one: https://github.com/shopware/shopware/blob/5.5/dev-ops/bamboo.shopware.com/actions/init.sh

I wish i could write something like the following in my scripts to include other actions.

#!/usr/bin/env bash

ACTION: shopware:update # Reference to dev-ops/shopware/actions/update.sh
ACTION: unit # Reference to dev-ops/common/actions/unit.sh

PSH composer conflicts with Shopware

PSH requires "symfony/config": "^3.3" whereas symfony/dependency-injection v4.4 requires "symfony/config": "^4.3" and conflicts with "symfony/config": "<4.3|>=5.0"

Shopware in its production version distributes with a composer.json requirement for symfony/dependency-injection v4.4:

https://github.com/shopwareLabs/psh/blob/master/composer.json
https://github.com/symfony/dependency-injection/blob/4.4/composer.json
https://github.com/shopware/production/blob/6.1/composer.json

Full message below:

C:\shopware> composer require shopware/psh --dev
Using version ^1.4 for shopware/psh
./composer.json has been updated
> [ ! -f vendor/autoload.php ] || php bin/console system:update:prepare
Run Update preparations
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for shopware/psh ^1.4 -> satisfiable by shopware/psh[v1.4.0].
    - Conclusion: remove symfony/dependency-injection v4.4.1
    - Conclusion: don't install symfony/dependency-injection v4.4.1
    - shopware/psh v1.4.0 requires symfony/config ^3.3 -> satisfiable by symfony/config[v3.3.0, v3.3.1, v3.3.10, v3.3.11, v3.3.12, v3.3.13, v3.3.14, v3.3.15, v3.3.16, v3.3.17, v3.3.18, v3.3.2, v3.3.3, v3.3.4, v3.3.5, v3.3.6, v3.3.7, v3.3.8, v3.3.9, v3.4.0, v3.4.1, v3.4.10, v3.4.11, v3.4.12, v3.4.13, v3.4.14, v3.4.15, v3.4.16, v3.4.17, v3.4.18, v3.4.19, v3.4.2, v3.4.20, v3.4.21, v3.4.22, v3.4.23, v3.4.24, v3.4.25, v3.4.26, v3.4.27, v3.4.28, v3.4.29, v3.4.3, v3.4.30, v3.4.31, v3.4.32, v3.4.33, v3.4.34, v3.4.35, v3.4.36, v3.4.37, v3.4.38, v3.4.39, v3.4.4, v3.4.5, v3.4.6, v3.4.7, v3.4.8, v3.4.9].
    - symfony/config v3.4.0 conflicts with symfony/dependency-injection[v4.4.1].
    - symfony/config v3.4.1 conflicts with symfony/dependency-injection[v4.4.1].
    ... blah blah blah ...
    - symfony/config v3.3.9 conflicts with symfony/dependency-injection[v4.4.1].
    - Installation request for symfony/dependency-injection (locked at v4.4.1, required as ~4.4) -> satisfiable by symfony/dependency-injection[v4.4.1].


Installation failed, reverting ./composer.json to its original content.

Why is yaml configuration deprecated?

Hi @JanPietrzyk ,

I have a question:

Why is the yaml configuration format deprecated and removed in 2.0? I just found your blog post from 2016 where you wrote this:

[...] The verbosity of XML makes reading even the simplest statements a pain.

[...] This all meant for us that all XML based build tools [...] were no longer an option

So I wonder why you have decided to again use XML and not YAML anymore.

No GPG Signature for version 1.7.0 when installing via PHIVE

Hi together,

the installation via PHIVE only works for version 1.4.0:

phive install psh

Phive 0.15.0 - Copyright (C) 2015-2021 by Arne Blankerts, Sebastian Heuer and Contributors
[WARNING] psh 1.7.0: No GPG Signature
[WARNING] psh 1.6.0: No downloadable PHAR
[WARNING] psh 1.5.0: No downloadable PHAR

Best regards
Frank

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.