Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support running inline php scripts #482

Closed
1 task
staabm opened this issue Aug 6, 2021 · 6 comments
Closed
1 task

support running inline php scripts #482

staabm opened this issue Aug 6, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@staabm
Copy link

staabm commented Aug 6, 2021

Describe the feature
writing bash scripts etc. within github action workflows is a real pain - especially if you are used to the php language.

additionally the feedback loop getsss soo long when try and error debugging github action workflows.

I would love if there would be something possible like:

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 7.4
          run-script: |
            echo "hello world";
            var_dump(file_get_contents("my/path.txt"));

            system("my-bin-script", $exitCode);
            // ...

so writing inline php within the workflow.

that way we could easily develop advanced logic without the need for advanced bash fu.

Version

  • I have checked releases, and the feature is missing in the latest patch version of v2.

Underlying issue

the long feedback look of github actions

Describe alternatives
in our use-case we cannot move the logic into a separat php file and run it with php -f file.php, since we need a self-containing workflow file (this is easier to distribute and keep in sync between github projects)

Additional context

n/a

Are you willing to submit a PR?

I don't think I can implement it myself

@staabm staabm added the enhancement New feature or request label Aug 6, 2021
@shivammathur
Copy link
Owner

shivammathur commented Aug 6, 2021

@staabm
It is possible to run inline PHP code in the workflow. You have to specify the shell for the step as php {0}.

It saves whatever is in the run property to a file and executes using the default shell for the OS. For Linux, the default shell would be sh or bash, which you can override to be php. {0} references the file saved.

Relevant ADR: https://github.com/actions/runner/blob/main/docs/adrs/0277-run-action-shell-options.md
Test workflow: https://github.com/shivammathur/test-setup-php/actions/runs/1105361404/workflow

- name: Setup PHP 
  uses: shivammathur/setup-php@v2
  with:
    php-version: '8.0'

- name: Run inline PHP code
  shell: php {0}
  run: |
     <?php
     $welcome = "Hello, world";
     echo $welcome;

@staabm staabm closed this as completed Aug 6, 2021
@staabm
Copy link
Author

staabm commented Aug 6, 2021

thanks for the great reply @shivammathur. wasn't aware it is already that easy <3

@staabm
Copy link
Author

staabm commented Aug 7, 2021

Do you think this is worth mentioning in the readme?

@shivammathur
Copy link
Owner

@staabm I will add it in the next release.

@shivammathur shivammathur added the documentation Improvements or additions to documentation are required label Aug 7, 2021
@shivammathur
Copy link
Owner

Added to README in 2.13.0

@shivammathur shivammathur removed the documentation Improvements or additions to documentation are required label Aug 23, 2021
@staabm
Copy link
Author

staabm commented Aug 23, 2021

thank you so much. already used it today and it is a pleasure to write gh-action workflows in php instead of bash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants