easingthemes-ssh-deploy/.github/workflows/e2e.yml

76 lines
2.1 KiB
YAML
Raw Normal View History

2022-12-30 06:14:51 +08:00
name: e2e Test
on:
2022-12-30 22:25:45 +08:00
push:
2022-12-30 22:26:24 +08:00
branches: [ 'feature/add-tests' ]
2022-12-30 06:14:51 +08:00
env:
TEST_HOST_DOCKER: ./test
2022-12-31 09:43:17 +08:00
TEST_USER: test
2022-12-30 06:14:51 +08:00
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
2022-12-31 10:15:04 +08:00
- name: Set ENV var
run: |
echo "CUSTOM_VAR=IT WORKS" >> $GITHUB_ENV
2022-12-31 09:43:17 +08:00
2022-12-30 17:29:20 +08:00
- name: Clean up old test files
run: |
docker stop ssh-host-container || true && docker rm ssh-host-container || true
2022-12-31 10:15:04 +08:00
- name: Create ssh keys
2022-12-30 06:14:51 +08:00
run: |
2022-12-30 17:29:20 +08:00
echo $HOME
ls -la $HOME
2022-12-30 06:14:51 +08:00
ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N ""
2022-12-30 23:04:25 +08:00
eval `ssh-agent -s`
2022-12-30 23:01:47 +08:00
ssh-add "$HOME/.ssh/id_rsa"
ssh-add -l
2022-12-31 10:15:04 +08:00
echo "SSH_PRIVATE_KEY<<EOF" >> $GITHUB_ENV
2022-12-30 17:29:20 +08:00
cat $HOME/.ssh/id_rsa >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
2022-12-30 06:14:51 +08:00
- name: Build Host Server Image
2022-12-30 17:29:20 +08:00
working-directory: ${{ env.TEST_HOST_DOCKER }}
2022-12-30 06:14:51 +08:00
run: |
docker build \
-t ssh-host-image . \
2022-12-31 09:43:17 +08:00
--build-arg SSH_PUB_KEY="$(cat $HOME/.ssh/id_rsa.pub)" \
2022-12-30 21:29:31 +08:00
--build-arg ssh_user="${{ env.TEST_USER }}"
2022-12-31 09:43:17 +08:00
docker run -d -p 8822:22 --name=ssh-host-container ssh-host-image
2022-12-30 21:29:31 +08:00
docker exec ssh-host-container sh -c "hostname --ip-address" > ip.txt
2022-12-31 10:15:04 +08:00
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
2022-12-30 21:29:31 +08:00
cat ip.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
shell: bash
2022-12-30 06:14:51 +08:00
- name: Create project file
run: |
2022-12-30 17:29:20 +08:00
mkdir test_project
cd test_project
2022-12-30 06:14:51 +08:00
touch index.html
date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html
cat index.html
2022-12-30 06:28:40 +08:00
2022-12-31 10:15:04 +08:00
- name: e2e Test ssh
run: |
echo "$REMOTE_HOST@$REMOTE_HOST"
ssh -p 8822 $SSH_REMOTE_USER@$SSH_REMOTE_HOST 'exit'
2022-12-30 06:14:51 +08:00
2022-12-30 22:48:53 +08:00
- name: e2e Test published ssh-deploy action
2022-12-31 09:43:57 +08:00
uses: easingthemes/ssh-deploy@feature/add-tests
2022-12-31 10:15:04 +08:00
env:
# SSH_PRIVATE_KEY: $SSH_PRIVATE_KEY
# REMOTE_HOST: $REMOTE_HOST
REMOTE_USER: ${{ env.TEST_USER }}
2022-12-30 22:48:53 +08:00
ARGS: "-rltgoDzvO"
SOURCE: "test_project/"
TARGET: "/var/www/html/"
EXCLUDE: "/dist/, /node_modules/"