From 3e8794afe7e0ad79315a88feb31e555b77232855 Mon Sep 17 00:00:00 2001 From: "Bo-Yi.Wu" Date: Sun, 9 Apr 2023 17:32:03 +0800 Subject: [PATCH] ci: add automated deployment for changed files - Add a new job `changes` to the `ci.yml` file - Copy changed files to a server in the `changes` job - Add a YAML code block to the `README.md` file - Add `foobar` to `c.txt` and `d.txt` in the `tests` folder Signed-off-by: Bo-Yi.Wu --- .github/workflows/ci.yml | 29 +++++++++++++++++++++++++++++ README.md | 33 +++++++++++++++++++++++++++++++++ tests/c.txt | 2 ++ tests/d.txt | 2 ++ 4 files changed, 66 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56839fd..211cf45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -113,3 +113,32 @@ jobs: port: ${{ secrets.PORT }} source: distfiles/* target: test + + changes: + name: test changed-files + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v35 + with: + since_last_remote_commit: true + + - name: List all changed files + run: | + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do + echo "$file was changed" + done + + - name: copy file to server + uses: ./ + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.KEY }} + port: ${{ secrets.PORT }} + source: ${{ join(steps.changed-files.outputs.all_changed_files, ',') }} + target: test diff --git a/README.md b/README.md index 55b1d3d..a5a884c 100644 --- a/README.md +++ b/README.md @@ -251,6 +251,39 @@ Remove the specified number of leading path elements: strip_components: 1 ``` +Only copy files that are newer than the corresponding destination files: + +```yaml + changes: + name: test changed-files + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v35 + with: + since_last_remote_commit: true + + - name: List all changed files + run: | + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do + echo "$file was changed" + done + + - name: copy file to server + uses: ./ + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.KEY }} + port: ${{ secrets.PORT }} + source: ${{ join(steps.changed-files.outputs.all_changed_files, ',') }} + target: test +``` + Old target structure: ```sh diff --git a/tests/c.txt b/tests/c.txt index f2ad6c7..06cab46 100644 --- a/tests/c.txt +++ b/tests/c.txt @@ -1 +1,3 @@ c +foobar +test1234 diff --git a/tests/d.txt b/tests/d.txt index 4bcfe98..13a80d9 100644 --- a/tests/d.txt +++ b/tests/d.txt @@ -1 +1,3 @@ d +foobar +foobar