diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b4a7fb7..b15f849 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,6 @@ name: Test Alpacon CP Action +permissions: + contents: read on: push: @@ -83,4 +85,47 @@ jobs: source: './test-dir/' target-server: ${{ secrets.TEST_ALPACON_SERVER_NAME }} target-path: '/tmp/test-upload-dir/' - recursive: true \ No newline at end of file + recursive: true + + test-upload-with-username: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Alpacon CLI + uses: alpacax/alpacon-setup-action@v1.0.0 + + - 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 \ No newline at end of file diff --git a/README.md b/README.md index 6a9a38d..49c9aae 100644 --- a/README.md +++ b/README.md @@ -33,19 +33,20 @@ 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/alpacon-cp-action@v1.0.0 + uses: alpacax/alpacon-cp-action@v1.0.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/alpacon-cp-action@v1.0.0 + uses: alpacax/alpacon-cp-action@v1.0.1 with: workspace-url: ${{ secrets.ALPACON_WORKSPACE_URL }} api-token: ${{ secrets.ALPACON_API_TOKEN }} @@ -53,12 +54,13 @@ This action requires the Alpacon CLI to be installed in your workflow. Use the [ 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/alpacon-cp-action@v1.0.0 + uses: alpacax/alpacon-cp-action@v1.0.1 with: workspace-url: ${{ secrets.ALPACON_WORKSPACE_URL }} api-token: ${{ secrets.ALPACON_API_TOKEN }} @@ -66,12 +68,13 @@ This action requires the Alpacon CLI to be installed in your workflow. Use the [ target-server: 'worker1' target-path: '/data/' recursive: true + username: ubuntu ``` ### Download a directory recursively ```yaml - name: Download Directory - uses: alpacax/alpacon-cp-action@v1.0.0 + uses: alpacax/alpacon-cp-action@v1.0.1 with: workspace-url: ${{ secrets.ALPACON_WORKSPACE_URL }} api-token: ${{ secrets.ALPACON_API_TOKEN }} @@ -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 @@ -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 diff --git a/action.yml b/action.yml index 4405047..24e9406 100644 --- a/action.yml +++ b/action.yml @@ -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" @@ -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