appleboy / ssh-action

GitHub Actions for executing remote ssh commands.
https://github.com/marketplace/actions/ssh-remote-commands
MIT License
4.85k stars 578 forks source link

Error: missing server host when called from `workflow_call` #316

Closed Juknum closed 6 months ago

Juknum commented 7 months ago

Hi, it might be intentional (I did not see anything in the README) but I was trying to use appleboy/ssh-action@master trough a workflow call like so (for testing purpose as this use case is a no-go aha, why would you deploy on a PR) :

# .github/workflows/update.yml
# https://docs.github.com/en/actions/using-workflows/reusing-workflows
name: PR/Push update

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  deploy:
    uses: ./.github/workflows/linting.yml
# .github/workflows/deploy.yml
name: Deploy

on:
  workflow_call:

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Executing remote command
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          password: ${{ secrets.PASSWORD }}
          port: ${{ secrets.PORT }}
          script: whoami

But the action failed (with the same error message as #19) without further explanation (I guess something doesn't get passed trough the call)

Whereas using it directly on a push change event does work as expected:

appleboy commented 7 months ago

@Juknum Please help to try the following guide.

https://docs.github.com/en/enterprise-cloud@latest/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_callsecrets

on:
  workflow_call:
    secrets:
      access-token:
        description: 'A token passed from the caller workflow'
        required: false

jobs:

  pass-secret-to-action:
    runs-on: ubuntu-latest
    steps:
    # passing the secret to an action
      - name: Pass the received secret to an action
        uses: ./.github/actions/my-action
        with:
          token: ${{ secrets.access-token }}

  # passing the secret to a nested reusable workflow
  pass-secret-to-workflow:
    uses: ./.github/workflows/my-workflow
    secrets:
       token: ${{ secrets.access-token }}
BotanMan commented 6 months ago

For me it was just an issue with secrets. I forgot to add them to repository Settings.

Juknum commented 6 months ago

For me it was just an issue with secrets. I forgot to add them to repository Settings.

It wasn't that for me (I checked at least 10x times aha)

I changed my workflow so I'm not concerned by the issue anymore but I'm pretty sure @appleboy provided the right answer (I did not tried it)

ariwijayaikd commented 6 months ago

May I see the changed one?

julesfe commented 5 months ago

i had to add the environment and it worked.

name: Deploy

on:
  push:
    branches:
      - prod

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: prod
    steps:
      - uses: actions/checkout@v4.1.7
      - name: Deploy to server
        uses: appleboy/ssh-action@v1.0.3
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          port: ${{ secrets.PORT }}
          key: ${{ secrets.SSHKEY }}
          script: ".scripts/deploy.sh"
nicoagr commented 4 months ago

i had to add the environment and it worked.

name: Deploy

on:
  push:
    branches:
      - prod

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: prod
    steps:
      - uses: actions/checkout@v4.1.7
      - name: Deploy to server
        uses: appleboy/ssh-action@v1.0.3
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          port: ${{ secrets.PORT }}
          key: ${{ secrets.SSHKEY }}
          script: ".scripts/deploy.sh"

For me it was also the environment!! No problems with the issue at all, but forgot to include the "environment: " tag on every step of my action