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

88 lines
2.6 KiB
YAML
Raw Normal View History

2022-12-30 01:14:51 +03:00
name: e2e Test
on:
2022-12-30 17:25:45 +03:00
push:
2022-12-30 17:26:24 +03:00
branches: [ 'feature/add-tests' ]
2022-12-30 01:14:51 +03:00
env:
TEST_HOST_DOCKER: ./test
TEST_USER: kaja
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
2022-12-30 12:29:20 +03:00
- name: Clean up old test files
run: |
docker stop ssh-host-container || true && docker rm ssh-host-container || true
2022-12-30 01:14:51 +03:00
- name: 1. Create ssh keys
run: |
2022-12-30 12:29:20 +03:00
echo $HOME
ls -la $HOME
2022-12-30 01:14:51 +03:00
ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N ""
2022-12-30 18:01:47 +03:00
ssh-add "$HOME/.ssh/id_rsa"
ssh-add -l
2022-12-30 12:29:20 +03:00
echo "EXAMPLE_SSH_PRIVATE_KEY<<EOF" >> $GITHUB_ENV
cat $HOME/.ssh/id_rsa >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
2022-12-30 01:14:51 +03:00
- name: Build Host Server Image
2022-12-30 12:29:20 +03:00
working-directory: ${{ env.TEST_HOST_DOCKER }}
2022-12-30 01:14:51 +03:00
run: |
docker build \
-t ssh-host-image . \
--build-arg ssh_pub_key="$(cat $HOME/.ssh/id_rsa.pub)" \
2022-12-30 16:29:31 +03:00
--build-arg ssh_user="${{ env.TEST_USER }}"
docker run -d --name=ssh-host-container ssh-host-image
docker exec ssh-host-container sh -c "hostname --ip-address" > ip.txt
echo "EXAMPLE_REMOTE_HOST<<EOF" >> $GITHUB_ENV
cat ip.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
shell: bash
2022-12-30 01:14:51 +03:00
- name: Create project file
run: |
2022-12-30 12:29:20 +03:00
mkdir test_project
cd test_project
2022-12-30 01:14:51 +03:00
touch index.html
date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html
cat index.html
2022-12-30 01:28:40 +03:00
2022-12-30 17:59:05 +03:00
- name: e2e Test ssh
run: |
ssh ${{ env.REMOTE_USER }}@${{ env.REMOTE_HOST }}
env:
REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }}
REMOTE_USER: ${{ env.TEST_USER }}
2022-12-30 17:23:23 +03:00
- name: e2e Test local ssh-deploy action
run: |
npm ci
npm run build
2022-12-30 17:59:05 +03:00
node ./src/index.js || true
2022-12-30 01:14:51 +03:00
env:
2022-12-30 17:46:37 +03:00
SSH_PRIVATE_KEY: ${{ env.EXAMPLE_SSH_PRIVATE_KEY }}
2022-12-30 01:14:51 +03:00
ARGS: "-rltgoDzvO"
2022-12-30 12:29:20 +03:00
SOURCE: "test_project/"
2022-12-30 17:46:37 +03:00
REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }}
2022-12-30 17:44:09 +03:00
REMOTE_USER: ${{ env.TEST_USER }}
2022-12-30 01:14:51 +03:00
TARGET: "/var/www/html/"
EXCLUDE: "/dist/, /node_modules/"
2022-12-30 17:48:53 +03:00
- name: e2e Test published ssh-deploy action
uses: easingthemes/ssh-deploy@main
env:
SSH_PRIVATE_KEY: ${{ env.EXAMPLE_SSH_PRIVATE_KEY }}
ARGS: "-rltgoDzvO"
SOURCE: "test_project/"
REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }}
REMOTE_USER: ${{ env.TEST_USER }}
TARGET: "/var/www/html/"
EXCLUDE: "/dist/, /node_modules/"
2022-12-30 17:23:23 +03:00