Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,47 @@
source: './test-dir/'
target-server: ${{ secrets.TEST_ALPACON_SERVER_NAME }}
target-path: '/tmp/test-upload-dir/'
recursive: true
recursive: true

test-upload-with-username:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Alpacon CLI
uses: alpacax/[email protected]

- name: Create test file
run: echo "Test content with username" > test-file-username.txt

- name: Test File Upload with username
uses: ./
with:
workspace-url: ${{ secrets.TEST_ALPACON_WORKSPACE_URL }}
api-token: ${{ secrets.TEST_ALPACON_API_TOKEN }}
source: './test-file-username.txt'
target-server: ${{ secrets.TEST_ALPACON_SERVER_NAME }}
target-path: '/tmp/test-upload-username.txt'
username: root

- name: Test File Download with username
uses: ./
with:
workspace-url: ${{ secrets.TEST_ALPACON_WORKSPACE_URL }}
api-token: ${{ secrets.TEST_ALPACON_API_TOKEN }}
source: '/tmp/test-upload-username.txt'
target-server: ${{ secrets.TEST_ALPACON_SERVER_NAME }}
target-path: './'
mode: download
username: root

- name: Verify downloaded file
run: |
if [ -f "test-upload-username.txt" ]; then
echo "✅ File with username option downloaded successfully"
cat test-upload-username.txt
else
echo "❌ File download with username failed"
exit 1
fi
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,48 @@ This action requires the Alpacon CLI to be installed in your workflow. Use the [
### Upload a file to a remote server
```yaml
- name: Upload File
uses: alpacax/[email protected].0
uses: alpacax/[email protected].1
with:
workspace-url: ${{ secrets.ALPACON_WORKSPACE_URL }}
api-token: ${{ secrets.ALPACON_API_TOKEN }}
source: './data/file.txt'
target-server: 'worker1'
target-path: '/data/file.txt'
username: ubuntu
```

### Download a file from a remote server
```yaml
- name: Download File
uses: alpacax/[email protected].0
uses: alpacax/[email protected].1
with:
workspace-url: ${{ secrets.ALPACON_WORKSPACE_URL }}
api-token: ${{ secrets.ALPACON_API_TOKEN }}
source: '/data/file.txt'
target-server: 'worker1'
target-path: './data/' # Directory path - file will be saved as './data/file.txt'
mode: download
username: ubuntu
```

### Upload a directory recursively
```yaml
- name: Upload Directory
uses: alpacax/[email protected].0
uses: alpacax/[email protected].1
with:
workspace-url: ${{ secrets.ALPACON_WORKSPACE_URL }}
api-token: ${{ secrets.ALPACON_API_TOKEN }}
source: './data/'
target-server: 'worker1'
target-path: '/data/'
recursive: true
username: ubuntu
```

### Download a directory recursively
```yaml
- name: Download Directory
uses: alpacax/[email protected].0
uses: alpacax/[email protected].1
with:
workspace-url: ${{ secrets.ALPACON_WORKSPACE_URL }}
api-token: ${{ secrets.ALPACON_API_TOKEN }}
Expand All @@ -80,6 +83,7 @@ This action requires the Alpacon CLI to be installed in your workflow. Use the [
target-path: './data/'
mode: download
recursive: true
username: ubuntu
```

## Inputs
Expand All @@ -93,6 +97,8 @@ This action requires the Alpacon CLI to be installed in your workflow. Use the [
| target-path | Destination path (remote for upload, local for download). | Yes |
| mode | "upload" (default) or "download". | No |
| recursive | Set to true to copy directories recursively. | No |
| username | Username for server authentication (optional). | No |
| groupname | Group name for server authentication (optional). | No |

## Notes

Expand Down
19 changes: 19 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ inputs:
description: 'Set to true to copy directories recursively (-r option).'
required: false
default: 'false'
username:
description: 'Username to execute the command as (e.g., root, ubuntu).'
required: false
groupname:
description: 'Group name to execute the command as.'
required: false

runs:
using: "composite"
Expand All @@ -39,10 +45,23 @@ runs:
shell: bash
- name: Execute CP
run: |
# Validate groupname requires username
if [[ -z "${{ inputs.username }}" && -n "${{ inputs.groupname }}" ]]; then
echo "Error: groupname requires username to be specified"
exit 1
fi

# Build command with optional flags
CP_CMD="alpacon cp"
if [ "${{ inputs.recursive }}" = "true" ]; then
CP_CMD="$CP_CMD -r"
fi
if [[ -n "${{ inputs.username }}" && -n "${{ inputs.groupname }}" ]]; then
CP_CMD="$CP_CMD -u ${{ inputs.username }} -g ${{ inputs.groupname }}"
elif [[ -n "${{ inputs.username }}" ]]; then
CP_CMD="$CP_CMD -u ${{ inputs.username }}"
fi

if [ "${{ inputs.mode }}" = "download" ]; then
$CP_CMD ${{ inputs.target-server }}:${{ inputs.source }} ${{ inputs.target-path }}
else
Expand Down
Loading