From 15dedafe37491a9d4cdf0fcd78cd2346004bf7d1 Mon Sep 17 00:00:00 2001 From: Nguyen Huu Thuong Date: Sat, 13 Jun 2020 15:31:44 +0200 Subject: [PATCH] update action --- .github/workflows/deploy.yml | 10 +++++++--- Dockerfile | 3 +-- README.md | 4 +++- app.py | 21 ++++++++++++--------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 88a8671..29ca03b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,6 +4,9 @@ on: branches: - latest +env: + TARGET_DIR: /home/github/test + jobs: build: name: Build @@ -32,7 +35,7 @@ jobs: mkdir -p /home/github/test/test2 && scp: |- './test/*' => /home/github/test/ - ./test/test1* => /home/github/test/test1/ + ./test/test1* => $TARGET_DIR/test1/ ./test/test*.csv => "/home/github/test/test2/" last_ssh: |- echo $LASTSSH && @@ -49,7 +52,7 @@ jobs: pass: ${{ secrets.DC_PASS }} scp: |- ./test/test1* => /home/github/test/test1/ - ./test/test*.csv => "/home/github/test/test2/" + "." => "$TARGET_DIR/test3/" last_ssh: |- echo $LASTSSH ls -la @@ -58,9 +61,10 @@ jobs: uses: cross-the-world/ssh-scp-ssh-pipelines@latest env: WELCOME: "scp pipelines" + TO_DIR: /home/github/test/test4 with: host: ${{ secrets.DC_HOST }} user: ${{ secrets.DC_USER }} pass: ${{ secrets.DC_PASS }} scp: |- - './test/*' => /home/github/test/ \ No newline at end of file + '.' => $TO_DIR \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index caec6e0..c5c9d1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.8.3-slim-buster LABEL "maintainer"="Scott Ng " LABEL "repository"="https://github.com/cross-the-world/ssh-scp-ssh-pipelines" -LABEL "version"="latest" +LABEL "version"="v1.1.0" LABEL "com.github.actions.name"="ssh-scp-ssh-pipelines" LABEL "com.github.actions.description"="Pipeline: ssh -> scp -> ssh" @@ -16,7 +16,6 @@ COPY requirements.txt /requirements.txt RUN pip3 install -r /requirements.txt RUN mkdir -p /opt/tools -WORKDIR /opt/tools COPY entrypoint.sh /opt/tools/entrypoint.sh RUN chmod +x /opt/tools/entrypoint.sh diff --git a/README.md b/README.md index 59484fe..9014ba4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ [Github actions](https://help.github.com/en/actions/creating-actions/creating-a-docker-container-action) -Credit to [SSH SCP Action of Ali Najafizadeh](https://github.com/alinz/ssh-scp-action) +[SSH action](https://github.com/cross-the-world/ssh-pipeline) + +[SCP action](https://github.com/cross-the-world/scp-pipeline) This action allows doing in order 1. ssh if defined diff --git a/app.py b/app.py index 31313d6..cd27f63 100644 --- a/app.py +++ b/app.py @@ -37,12 +37,12 @@ def convert_to_seconds(s): strips = [" ", "\"", " ", "'", " "] -def strip_path(p): +def strip_and_parse_envs(p): if not p: return None for c in strips: p = p.strip(c) - return p + return path.expandvars(p) def connect(callback=None): @@ -79,16 +79,19 @@ def ssh_process(ssh, input_ssh): stdin, stdout, stderr = ssh.exec_command(command_str) - err = "".join(stderr.readlines()) - err = err.strip() if err is not None else None - if err: - print(f"Error: \n{err}") - out = "".join(stdout.readlines()) out = out.strip() if out is not None else None if out: print(f"Success: \n{out}") + err = "".join(stderr.readlines()) + err = err.strip() if err is not None else None + if err: + if out is None: + raise Exception(err) + else: + print(f"Error: \n{err}") + pass @@ -99,8 +102,8 @@ def scp_process(ssh, input_scp): continue l2r = c.split("=>") if len(l2r) == 2: - local = strip_path(l2r[0]) - remote = strip_path(l2r[1]) + local = strip_and_parse_envs(l2r[0]) + remote = strip_and_parse_envs(l2r[1]) if local and remote: copy_list.append({"l": local, "r": remote}) continue