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

feat: capture stdout and store as output #287

Merged
merged 25 commits into from
Dec 4, 2024
Merged

Conversation

GammaGames
Copy link
Contributor

@GammaGames GammaGames commented Jan 2, 2024

Possibly fixes #274, #38

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: SSH
        id: ssh
        uses: https://github.com/GammaGames/ssh-action@master
        with:
          host: [fill in]
          capture_stdout: 'true'
          script: |
            ls -l ~/test/
      - name: echo
        run: echo "${{ steps.ssh.outputs.stdout }}"

If successful, it has the following in steps.ssh.outputs.stdout:

======CMD======
ls -l ~/test/
======END======
out: total 0
out: -rw-rw-r-- 1 user group 0 Jan  2 14:24 file1
out: -rw-rw-r-- 1 user group 0 Jan  2 14:24 file2
==============================================
✅ Successfully executed commands to all host.
==============================================

On error it acts like it does now.

@GammaGames
Copy link
Contributor Author

One potential issue is that secrets aren't masked in the output variable like they are in the log. I was able to fix it with a filtering step, but it's manual:

- uses: mad9000/actions-find-and-replace-string@4
  id: filter
  with:
    source: ${{ steps.ssh.outputs.stdout }}
    find: '${{ secrets.value }}'
    replace: '***'
    replaceAll: true
- run: echo '${{ steps.filter.outputs.value }}'

@GammaGames
Copy link
Contributor Author

GammaGames commented Apr 3, 2024

fixed conflicts

edit: fixed conflicts

@hasechris
Copy link

hasechris commented May 21, 2024

@appleboy
Could you take a look at this? Having an output would be great

@Digital-Lemon
Copy link

I'd add a variable to enable (or disable) this behavior, as sometimes the outputs could be huge

@GammaGames
Copy link
Contributor Author

Good point, it should probably also not capture by default because the output has all command output (without censoring, like the gh step interface has)

@uchar
Copy link

uchar commented Sep 10, 2024

I think the script should handle masking secrets by itself , not very good practice to depend on another step for doing it , this can cause security issues if some one forget it

@GammaGames
Copy link
Contributor Author

GammaGames commented Sep 10, 2024

I agree! Is there a way to get secret names at runtime? I was under the impression that github action output is filtered before displaying, but doesn't have any filtering on the server side
Edit: "censoring" values should probably be another pr, maybe another variable you could pass ${{ toJSON(secrets) }} to?

@mikesalvia
Copy link

@GammaGames or @appleboy is there any update on when this would be merged in?

@GammaGames
Copy link
Contributor Author

@mikesalvia I don't know, but I should probably make it optional and disabled by default first. I started working on that a little today but have yet to test it: https://github.com/GammaGames/ssh-action/tree/capture_vars

@GammaGames GammaGames changed the title Capture stdout and store as output WIP: Capture stdout and store as output Nov 25, 2024
@GammaGames
Copy link
Contributor Author

GammaGames commented Nov 25, 2024

Okay it's optional now. Idk why it's not showing in the github action, it's working fine on nektos act and gitea: https://github.com/GammaGames/ssh-action/actions/runs/12017938366/job/33504424638

edit: started discussion asking for help - https://github.com/orgs/community/discussions/145592

@GammaGames GammaGames changed the title WIP: Capture stdout and store as output Capture stdout and store as output Nov 25, 2024
@appleboy
Copy link
Owner

I will take it.

@appleboy
Copy link
Owner

appleboy commented Dec 3, 2024

@GammaGames Please help to resolve the conflicts.

@GammaGames
Copy link
Contributor Author

Fixed, also changed the test to use true instead of "true" (though both work)

Why remove the script_stop feature?

@appleboy appleboy changed the title Capture stdout and store as output feat: capture stdout and store as output Dec 4, 2024
@appleboy appleboy merged commit 102c0d2 into appleboy:master Dec 4, 2024
@appleboy
Copy link
Owner

appleboy commented Dec 4, 2024

@GammaGames Thanks.

Why remove the script_stop feature?

The script_stop function detects each line of instruction, but it cannot handle line breaks using the backslash (). Therefore, I will write another method to solve this problem.

@banagale
Copy link

banagale commented Dec 4, 2024

Thank you @GammaGames and all who assisted!

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

Successfully merging this pull request may close these issues.

Example of how to use this and get output of one or more lines to $GITHUB_OUTPUT
8 participants