|
| 1 | +--- |
| 2 | +name: "remote ssh command" |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + port: |
| 7 | + description: "Specify the SSH port number for the remote connection." |
| 8 | + type: string |
| 9 | + default: "22" |
| 10 | + sync: |
| 11 | + description: "Enable synchronous execution when dealing with multiple hosts." |
| 12 | + type: string |
| 13 | + required: false |
| 14 | + timeout: |
| 15 | + description: "Timeout duration for establishing an SSH connection to the host." |
| 16 | + type: string |
| 17 | + default: "30s" |
| 18 | + required: false |
| 19 | + command_timeout: |
| 20 | + description: "Timeout duration for executing SSH commands." |
| 21 | + type: string |
| 22 | + default: "10m" |
| 23 | + required: false |
| 24 | + script: |
| 25 | + description: "Specify the commands to be executed on the remote host." |
| 26 | + required: false |
| 27 | + type: string |
| 28 | + script_stop: |
| 29 | + description: "Stop the script after the first failure." |
| 30 | + type: string |
| 31 | + default: false |
| 32 | + envs: |
| 33 | + description: "Specify environment variables to be passed to the remote shell script." |
| 34 | + type: string |
| 35 | + debug: |
| 36 | + description: "Enable debug mode for additional logging." |
| 37 | + type: string |
| 38 | + default: false |
| 39 | + request_pty: |
| 40 | + description: "Request a pseudo-terminal from the server." |
| 41 | + type: string |
| 42 | + default: false |
| 43 | + slack_username: |
| 44 | + description: "It is the name displayed to others in Message on Slack channel" |
| 45 | + required: false |
| 46 | + type: string |
| 47 | + slack_footer: |
| 48 | + description: "Additional information or context often placed at the bottom of a message in Slack" |
| 49 | + required: false |
| 50 | + type: string |
| 51 | + slack_icon: |
| 52 | + description: "The visual representation associated with a user or a group on Slack" |
| 53 | + required: false |
| 54 | + type: string |
| 55 | + slack_message: |
| 56 | + description: "The content or information you want to share on Slack, which is a messaging platform." |
| 57 | + required: false |
| 58 | + type: string |
| 59 | + slack_color: |
| 60 | + description: "The visual styling applied to elements within a message or interface on Slack." |
| 61 | + required: false |
| 62 | + type: string |
| 63 | + slack-notification: |
| 64 | + description: "sending a brief message to a designated Slack channel." |
| 65 | + default: false |
| 66 | + type: string |
| 67 | + secrets: |
| 68 | + PRIVATE_SSH_KEY: |
| 69 | + description: "Private SSH Key for secure communication with the server." |
| 70 | + required: true |
| 71 | + HOST: |
| 72 | + description: "Public IP address of the server for remote access." |
| 73 | + required: true |
| 74 | + USERNAME: |
| 75 | + description: "Username for authentication on the remote system or service." |
| 76 | + required: true |
| 77 | + SLACK_WEBHOOK_URL: |
| 78 | + description: Specify Slack Incoming Webhook URL |
| 79 | + required: false |
| 80 | +jobs: |
| 81 | + ssh-action: |
| 82 | + runs-on: ubuntu-latest |
| 83 | + |
| 84 | + steps: |
| 85 | + - name: Checkout git repo |
| 86 | + uses: actions/checkout@v4 |
| 87 | + |
| 88 | + - name: executing remote ssh commands using ssh key |
| 89 | + |
| 90 | + with: |
| 91 | + host: ${{ secrets.HOST }} |
| 92 | + username: ${{ secrets.USERNAME }} |
| 93 | + key: ${{ secrets.PRIVATE_SSH_KEY }} |
| 94 | + port: ${{ inputs.port }} |
| 95 | + envs: ${{ inputs.envs }} |
| 96 | + request_pty: ${{ inputs.request_pty }} |
| 97 | + script: | |
| 98 | + ${{ inputs.script }} |
| 99 | +
|
| 100 | + - name: slack notification |
| 101 | + if: ${{ inputs.slack-notification == 'true' && always() }} |
| 102 | + uses: rtCamp/action-slack-notify@v2 |
| 103 | + env: |
| 104 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 105 | + SLACK_MESSAGE: ${{ inputs.slack_message }} |
| 106 | + SLACK_ICON: ${{ inputs.slack_icon }} |
| 107 | + SLACK_USERNAME: ${{ inputs.slack_username }} |
| 108 | + SLACK_FOOTER: ${{ inputs.slack_footer }} |
| 109 | + SLACK_COLOR: ${{ job.status }} |
| 110 | + slack-notification: ${{ inputs.slack-notification }} |
| 111 | +... |
0 commit comments