Skip to content

ilaipi-freedom/process-ssh-connection-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Process SSH Connection Action

This action processes SSH connection details based on tag or branch name. It helps standardize environment variable names for SSH connections.

Features

  • Extract environment suffix from ref or use direct input
  • Convert environment-specific variable names to standard outputs
  • Automatically process SSH key line breaks
  • Support for multiple environments (prod, staging, etc.)

Inputs

Input Description Required Default
suffix Direct suffix value to use (takes precedence over ref) false ''
ref Reference string to process false ${{ github.ref }}
suffix_regex Regular expression to extract suffix from ref false 'refs/(tags|heads)/.*-(.+)'
suffix_group Group number in regex that contains the suffix false '2'

Outputs

Output Description
host Selected SSH host variable name
username Selected SSH username variable name
port Selected SSH port variable name
key SSH key with processed line breaks
environment Selected environment (lowercase suffix)
environment_upper Selected environment in uppercase

Environment Variables Required

For each environment (suffix), you need to set these environment variables:

  • SSH_HOST_{SUFFIX}
  • SSH_USERNAME_{SUFFIX}
  • SSH_PORT_{SUFFIX}
  • SSH_KEY_{SUFFIX}

Where {SUFFIX} is the uppercase version of your environment suffix.

Usage Examples

1. Using direct suffix

- uses: ilaipi-freedom/process-ssh-connection-action@v1.0.5
  with:
    suffix: 'prod'

2. Using ref with regex extraction

- uses: ilaipi-freedom/process-ssh-connection-action@v1.0.5
  with:
    ref: 'refs/tags/release-prod'
    suffix_regex: 'refs/(tags|heads)/.*-(.+)'
    suffix_group: '2'

Complete Workflow Example

name: Deploy
on:
  push:
    tags:
      - '*-prod'
      - '*-staging'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      # Load environment variables from .env file
      - name: Load Environment Variables
        uses: ilaipi-freedom/load-env-action@v1.0.2

      - name: Process SSH Connection
        id: ssh
        uses: ilaipi-freedom/process-ssh-connection-action@v1.0.5
      
      - name: Use SSH Connection
        uses: appleboy/ssh-action@v1.0.0
        with:
          host: ${{ env[steps.ssh.outputs.host] }}
          username: ${{ env[steps.ssh.outputs.username] }}
          port: ${{ env[steps.ssh.outputs.port] }}
          key: ${{ steps.ssh.outputs.key }}
          script: |
            echo "Connected to ${{ steps.ssh.outputs.environment }} environment!"

Notes

  1. The action will automatically convert the suffix to uppercase when constructing environment variable names.
  2. SSH key line breaks (\n) are automatically processed.
  3. Make sure all required environment variables are set before using this action.
  4. The action outputs both lowercase environment name (environment) and uppercase version (environment_upper) for flexibility.

About

Dynamically selects SSH connection configurations based on branch or tag suffixes. Useful when GitHub Secrets contain multiple SSH connection details. | 根据分支或标签的后缀,动态选择 SSH 连接配置。适用于 GitHub Secrets 中包含多个 SSH 连接信息的情况。

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors