Skip to content

Commit 46a472a

Browse files
committed
feat: Add pull request workflow with SSH host validation and deployment checks
- Created `.github/workflows/pull_request.yml` to handle pull request events on the `main` branch. - Integrated matrix strategy to test across macOS, Ubuntu, and Windows platforms. - Added `check.sh` to verify the existence of a populated `known_hosts` file before deployment. - Added `post_check.sh` to ensure the `known_hosts` file is removed after the job for security. - Included test deployment of a `whoami` container to validate Docker host setup. - Utilized `pyTooling/Actions/with-post-step` to streamline pre- and post-check scripts. - Added support for private SSH keys and `known_hosts` configuration using the custom SSH action.
1 parent 1fa032f commit 46a472a

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

.github/workflows/pull_request.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- main
5+
jobs:
6+
test:
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
os:
11+
- macos-15
12+
- ubuntu-24.04
13+
- windows-2025
14+
runs-on: ${{ matrix.os }}
15+
steps:
16+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
- name: Setup SSH key
18+
uses: ./
19+
with:
20+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
21+
ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
22+
log-public-key: false
23+
- name: Check known hosts
24+
uses: pyTooling/Actions/with-post-step@9ceefdbf5dceae8c441fc393ed82344c7ca8bbdb # v3.1.1
25+
with:
26+
main: |
27+
./check.sh
28+
post: |
29+
./post_check.sh
30+
- name: Deploy over SSH
31+
shell: bash
32+
env:
33+
DOCKER_HOST: ${{ secrets.DOCKER_HOST }}
34+
run: |
35+
# renovate: datasource=docker depname=traefik/whoami versioning=docker
36+
WHOAMI_VERSION="v1.10"
37+
docker run -d -P --name whoami traefik/whoami:v1.10
38+
docker stop whoami
39+
docker rm whoami

check.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
if [ ! -s ~/.ssh/known_hosts ]; then
4+
echo "::error file=$(basename "$0"),line=${LINENO},endLine=${LINENO},title=Assertion Error::\
5+
~/.ssh/known_hosts is missing or empty."
6+
exit 1
7+
fi

post_check.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
if [ -s ~/.ssh/known_hosts ]; then
4+
echo "::error file=$(basename "$0"),line=${LINENO},endLine=${LINENO},title=Assertion Error::\
5+
~/.ssh/known_hosts file should not exist after the job."
6+
exit 1
7+
fi

0 commit comments

Comments
 (0)