Skip to content

Commit 73a65ec

Browse files
committed
feat: Add multi source and multi target support
1 parent 98ee38d commit 73a65ec

File tree

9 files changed

+227
-70
lines changed

9 files changed

+227
-70
lines changed

.github/workflows/e2e-manual.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: e2e Manual Test
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ARGS:
7+
description: 'ARGS'
8+
required: true
9+
default: '-rltgoDzvO --delete --chmod=ugo+rwX --progress'
10+
EXCLUDE:
11+
description: 'EXCLUDE'
12+
required: true
13+
default: 'skip_dir/, /node_modules/'
14+
SSH_CMD_ARGS:
15+
description: 'SSH_CMD_ARGS'
16+
required: true
17+
default: '-o StrictHostKeyChecking=no, -o UserKnownHostsFile=/dev/null'
18+
19+
20+
env:
21+
TEST_HOST_DOCKER: ./test
22+
TEST_USER: test
23+
24+
jobs:
25+
e2e-manual:
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v3
31+
32+
# #################################################################
33+
# START [E2E Test Specific] steps
34+
# #################################################################
35+
36+
- name: [E2E Test Specific] Clean up old test files
37+
run: |
38+
docker stop ssh-host-container || true && docker rm ssh-host-container || true
39+
40+
- name: [E2E Test Specific] Create ssh keys
41+
run: |
42+
echo $HOME
43+
ls -la $HOME
44+
ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N ""
45+
eval `ssh-agent -s`
46+
ssh-add "$HOME/.ssh/id_rsa"
47+
ssh-add -l
48+
echo "SSH_PRIVATE_KEY<<EOF" >> $GITHUB_ENV
49+
cat $HOME/.ssh/id_rsa >> $GITHUB_ENV
50+
echo "EOF" >> $GITHUB_ENV
51+
52+
- name: [E2E Test Specific] Build Host Server Image
53+
working-directory: ${{ env.TEST_HOST_DOCKER }}
54+
run: |
55+
docker build \
56+
-t ssh-host-image . \
57+
--build-arg SSH_PUB_KEY="$(cat $HOME/.ssh/id_rsa.pub)"
58+
docker run -d -p 8822:22 --name=ssh-host-container ssh-host-image
59+
docker exec ssh-host-container sh -c "hostname --ip-address" > ip.txt
60+
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
61+
cat ip.txt >> $GITHUB_ENV
62+
echo "EOF" >> $GITHUB_ENV
63+
shell: bash
64+
65+
- name: [E2E Test Specific] Create project file
66+
run: |
67+
mkdir test_project2 && cd "$_"
68+
truncate -s 5MB info2.txt
69+
cd ../
70+
mkdir test_project && cd "$_"
71+
touch index.html
72+
date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html
73+
truncate -s 50MB image.svg
74+
truncate -s 5MB info.txt
75+
truncate -s 500MB big_file.txt
76+
mkdir skip_dir && cd "$_"
77+
truncate -s 5MB text_in_skip_dir.txt
78+
cd ../
79+
cat index.html
80+
echo "test_project:" && ls -lR
81+
echo "skip_dir:" && ls -lR skip_dir
82+
83+
# #################################################################
84+
# END [E2E Test Specific] steps
85+
# #################################################################
86+
87+
- name: e2e Test ssh-deploy action
88+
uses: easingthemes/ssh-deploy@feature/multi-src
89+
env:
90+
# ENV Vars created in previous steps:
91+
# SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY
92+
# REMOTE_HOST: $EXAMPLE_REMOTE_HOST
93+
REMOTE_USER: ${{ env.TEST_USER }}
94+
ARGS: ${{ github.event.inputs.ARGS }}
95+
SSH_CMD_ARGS: ${{ github.event.inputs.SSH_CMD_ARGS }}
96+
SOURCE: test_project/ test_project2/
97+
TARGET: /var/www/html/
98+
EXCLUDE: ${{ github.event.inputs.EXCLUDE }}
99+
SCRIPT_BEFORE: |
100+
whoami
101+
ls -lR /var/www/html/
102+
SCRIPT_AFTER: |
103+
ls -lR /var/www/html/
104+
echo $RSYNC_STDOUT

.github/workflows/e2e.yml

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,11 @@ name: e2e Test
33
on:
44
push:
55
branches: [ 'feature/multi-src' ]
6-
workflow_dispatch:
7-
inputs:
8-
ARGS:
9-
description: 'ARGS'
10-
required: true
11-
default: '-rltgoDzvO --delete --chmod=ugo=rwX --progress'
12-
EXCLUDE:
13-
description: 'EXCLUDE'
14-
required: true
15-
default: 'skip_dir/, /node_modules/'
16-
SSH_CMD_ARGS:
17-
description: 'SSH_CMD_ARGS'
18-
required: true
19-
default: '-o StrictHostKeyChecking=no, -o UserKnownHostsFile=/dev/null'
20-
216

227
env:
238
TEST_HOST_DOCKER: ./test
249
TEST_USER: test
10+
TEST_USER2: test2
2511

2612
jobs:
2713
e2e:
@@ -31,11 +17,15 @@ jobs:
3117
- name: Checkout
3218
uses: actions/checkout@v3
3319

34-
- name: Clean up old test files
20+
# #################################################################
21+
# START [E2E Test Specific] steps
22+
# #################################################################
23+
24+
- name: [E2E Test Specific] Clean up old test files
3525
run: |
3626
docker stop ssh-host-container || true && docker rm ssh-host-container || true
3727
38-
- name: Create ssh keys
28+
- name: [E2E Test Specific] Create ssh keys
3929
run: |
4030
echo $HOME
4131
ls -la $HOME
@@ -47,21 +37,20 @@ jobs:
4737
cat $HOME/.ssh/id_rsa >> $GITHUB_ENV
4838
echo "EOF" >> $GITHUB_ENV
4939
50-
- name: Build Host Server Image
40+
- name: [E2E Test Specific] Build Host Server Image
5141
working-directory: ${{ env.TEST_HOST_DOCKER }}
5242
run: |
5343
docker build \
5444
-t ssh-host-image . \
55-
--build-arg SSH_PUB_KEY="$(cat $HOME/.ssh/id_rsa.pub)" \
56-
--build-arg ssh_user="${{ env.TEST_USER }}"
45+
--build-arg SSH_PUB_KEY="$(cat $HOME/.ssh/id_rsa.pub)"
5746
docker run -d -p 8822:22 --name=ssh-host-container ssh-host-image
5847
docker exec ssh-host-container sh -c "hostname --ip-address" > ip.txt
5948
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
6049
cat ip.txt >> $GITHUB_ENV
6150
echo "EOF" >> $GITHUB_ENV
6251
shell: bash
6352

64-
- name: Create project file
53+
- name: [E2E Test Specific] Create project file
6554
run: |
6655
mkdir test_project2 && cd "$_"
6756
truncate -s 5MB info2.txt
@@ -76,24 +65,38 @@ jobs:
7665
truncate -s 5MB text_in_skip_dir.txt
7766
cd ../
7867
cat index.html
79-
echo "test_project:" && ls -l
80-
echo "skip_dir:" && ls -l skip_dir
68+
echo "test_project:" && ls -lR
69+
echo "skip_dir:" && ls -lR skip_dir
70+
71+
# #################################################################
72+
# END [E2E Test Specific] steps
73+
# #################################################################
74+
75+
- name: set shared ENV variables for multi target deployment
76+
run: |
77+
echo "ARGS=-rltgoDzvOR --delete --chmod=ugo+rwX --progress" >> $GITHUB_ENV
78+
echo "SSH_CMD_ARGS=-o StrictHostKeyChecking=no, -o UserKnownHostsFile=/dev/null" >> $GITHUB_ENV
79+
echo "SOURCE=test_project/ test_project2/" >> $GITHUB_ENV
80+
echo "EXCLUDE=skip_dir/, /node_modules/" >> $GITHUB_ENV
81+
echo "SCRIPT_BEFORE<<EOF" >> $GITHUB_ENV
82+
echo "whoami" >> $GITHUB_ENV
83+
echo "ls -lR /var/www/html/" >> $GITHUB_ENV
84+
echo "EOF" >> $GITHUB_ENV
85+
echo "SCRIPT_AFTER<<EOF" >> $GITHUB_ENV
86+
echo $RSYNC_STDOUT >> $GITHUB_ENV
87+
echo "ls -lR /var/www/html/" >> $GITHUB_ENV
88+
echo "EOF" >> $GITHUB_ENV
8189
82-
- name: e2e Test published ssh-deploy action
90+
- name: e2e Test ssh-deploy action - Target 1
8391
uses: easingthemes/ssh-deploy@feature/multi-src
8492
env:
85-
# ENV Vars created in previous steps:
86-
# SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY
87-
# REMOTE_HOST: $EXAMPLE_REMOTE_HOST
93+
# Shared ENV Vars created in previous steps
8894
REMOTE_USER: ${{ env.TEST_USER }}
89-
ARGS: ${{ github.event.inputs.ARGS || '-rltgoDzvO --delete --chmod=ugo=rwX --progress' }}
90-
SSH_CMD_ARGS: ${{ github.event.inputs.SSH_CMD_ARGS || '-o StrictHostKeyChecking=no, -o UserKnownHostsFile=/dev/null' }}
91-
SOURCE: ["test_project/, test_project2/"]
92-
TARGET: "/var/www/html/"
93-
EXCLUDE: ${{ github.event.inputs.EXCLUDE || 'skip_dir/, /node_modules/' }}
94-
SCRIPT_BEFORE: |
95-
whoami
96-
ls -al /var/www/html/
97-
SCRIPT_AFTER: |
98-
ls -al /var/www/html/
99-
echo $RSYNC_STDOUT
95+
TARGET: /var/www/html/${{ env.TEST_USER }}
96+
97+
- name: e2e Test ssh-deploy action - Target 2
98+
uses: easingthemes/ssh-deploy@feature/multi-src
99+
env:
100+
# Shared ENV Vars created in previous steps
101+
REMOTE_USER: ${{ env.TEST_USER2 }}
102+
TARGET: /var/www/html/${{ env.TEST_USER2 }}

.github/workflows/manual-release.yml

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,72 @@ name: Manual Release
22
on:
33
workflow_dispatch:
44
inputs:
5-
dryrun:
6-
description: 'DryRUn'
5+
version:
6+
description: 'Version'
7+
type: choice
78
required: true
8-
default: 'false'
9+
default: patch
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
dryRun:
15+
description: 'DryRun'
16+
type: boolean
17+
default: true
18+
# ENV and Config
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
22+
GIT_AUTHOR_NAME: github-actions
23+
GIT_AUTHOR_EMAIL: github-actions@github.com
24+
GIT_COMMITTER_NAME: github-actions
25+
GIT_COMMITTER_EMAIL: github-actions@github.com
26+
CI: true
27+
CONFIG_NODE_VERSION: '["lts/*"]'
28+
CONFIG_OS: '["ubuntu-latest"]'
29+
# Main Job
930
jobs:
10-
release:
11-
name: Test, Build and Release
12-
runs-on: ${{ matrix.os }}
31+
config:
32+
runs-on: ubuntu-latest
33+
outputs:
34+
NODE_VERSION: ${{ steps.set-config.outputs.CONFIG_NODE_VERSION }}
35+
OS: ${{ steps.set-config.outputs.CONFIG_OS }}
36+
steps:
37+
- id: set-config
38+
run: |
39+
echo "CONFIG_NODE_VERSION=${{ toJSON(env.CONFIG_NODE_VERSION) }}" >> $GITHUB_OUTPUT
40+
echo "CONFIG_OS=${{ toJSON(env.CONFIG_OS) }}" >> $GITHUB_OUTPUT
41+
release-manual:
42+
name: Test, Build and force Release
43+
needs: config
44+
45+
runs-on: ${{ matrix.OS }}
1346
strategy:
1447
matrix:
15-
os: [ ubuntu-latest ]
16-
node-version: [ 16.x ]
48+
OS: ${{ fromJSON(needs.config.outputs.OS) }}
49+
NODE_VERSION: ${{ fromJSON(needs.config.outputs.NODE_VERSION) }}
50+
1751
steps:
18-
- name: Checkout
52+
- name: Checkout repo
1953
uses: actions/checkout@v3
20-
- name: Setup Node.js
54+
- name: Setup Node.js ${{ matrix.NODE_VERSION }}
2155
uses: actions/setup-node@v3
2256
with:
23-
node-version: ${{ matrix['node-version'] }}
57+
node-version: ${{ matrix.NODE_VERSION }}
58+
- name: Commit trigger
59+
run: |
60+
git commit --allow-empty -m "${{ github.event.inputs.version }}: Trigger Manual Release"
2461
- name: Install dependencies
2562
run: npm ci
2663
- name: Build Library
2764
run: npm run build --if-present
2865
- name: Run Tests
2966
run: npm test --if-present
30-
- name: Release
67+
- name: Publish npm package
3168
uses: cycjimmy/semantic-release-action@v3
3269
with:
33-
dry_run: ${{ github.event.inputs.dryrun == 'true' }}
70+
dry_run: ${{ github.event.inputs.dryRun == 'true' }}
3471
extra_plugins: |
3572
@semantic-release/changelog
3673
@semantic-release/git
37-
env:
38-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
40-
GIT_AUTHOR_NAME: github-actions
41-
GIT_AUTHOR_EMAIL: github-actions@github.com
42-
GIT_COMMITTER_NAME: github-actions
43-
GIT_COMMITTER_EMAIL: github-actions@github.com
44-
CI: true

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ For any initial/required rsync flags, eg: `-avzr --delete`
4747

4848
##### 6. `SOURCE` (optional, default '')
4949

50-
The source directory, path relative to `$GITHUB_WORKSPACE` root, eg: `dist/`
50+
The source directory, path relative to `$GITHUB_WORKSPACE` root, eg: `dist/`.
51+
Multiple sources should be separated by space.
5152

5253
##### 7. `TARGET` (optional, default '/home/REMOTE_USER/')
5354

@@ -148,6 +149,14 @@ Check actions tab for example.
148149

149150
More info for SSH keys: https://www.ssh.com/ssh/public-key-authentication
150151

152+
## Tips
153+
154+
- Optional ENV variables are created for simple requirements.
155+
For complex use cases, use `ARGS` and `SSH_CMD_ARGS` to fully configure `rsync` with all possible options.
156+
- If you need to use multiple steps, eg multi targets deployment, save shared ENV variables in `>> $GITHUB_ENV`.
157+
Check .github/workflows/e2e.yml for an example
158+
- For multi sources, use -R ARG to manipulate folders structure.
159+
151160

152161
## Disclaimer
153162

0 commit comments

Comments
 (0)