-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (80 loc) · 3.3 KB
/
cpanel-git-deployment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: cPanel Git Deployment
on:
workflow_call:
inputs:
branch:
type: string
description: "The Git branch to deploy and push to the remote repository."
required: true
debug:
type: string
description: "Set to `true` to enable debug logging (default: `false`)."
required: false
default: "false"
secrets:
remote-url:
description: "The Git+SSH URL of the remote repository (e.g. `git@hostname:user/repo.git`, `ssh://user@hostname:port/repo.git`)."
required: true
rsync-dest-dir:
description: "Reserving this for future use, unused for now."
required: true
ssh-private-key:
description: "The SSH private key used to authenticate with the remote repository."
required: true
outputs:
deployment-id:
description: "The deployment ID generated after a git push with new changes."
value: ${{ jobs.deploy-to-cpanel-host.outputs.deployment-id }}
jobs:
deploy-to-cpanel-host:
name: Deploy to cPanel host
runs-on: ubuntu-latest
outputs:
deployment-id: ${{ steps.process-deployment.outputs.deployment-id }}
steps:
- name: Checkout source repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ inputs.branch }}
- name: Parse Git+SSH URL
id: parse-url
uses: drkibitz/github/actions/parse-git-ssh-url@main
with:
url: ${{ secrets.remote-url }}
- name: Setup SSH agent
uses: drkibitz/github/actions/setup-ssh-agent@main
with:
port: ${{ steps.parse-url.outputs.port }}
username: ${{ steps.parse-url.outputs.username }}
hostname: ${{ steps.parse-url.outputs.hostname }}
ssh-private-key: ${{ secrets.ssh-private-key }}
- name: Git push
id: git-push
uses: drkibitz/github/actions/git-push@main
with:
debug: ${{ inputs.debug }}
# This is a deployment repo, we are ok with rewriting history on it.
push-options: --force
remote-url: ${{ secrets.remote-url }}
- name: Process deployment
id: process-deployment
run: |
deployment_id=$(grep -Eo "deploy_id: [0-9]+" "${{ steps.git-push.outputs.push-log }}" | cut -d ' ' -f2)
if [ -z "${deployment_id}" ]; then
echo "::notice::No 'deploy_id' found in Git push log, which just means that a deployment did not happen."
else
echo "::notice::Found remote deployment ID: $deployment_id)"
echo "deployment-id=$deployment_id" >> "$GITHUB_OUTPUT"
remote_log_path=$(grep -Eo "log_path: [^ ]+" "${{ steps.git-push.outputs.push-log }}" | awk '{print $2}')
if [ -z "${remote_log_path}" ]; then
echo "::error::No 'log_path' found in Git push log with a deployment, this is unexpected!"
exit 1
fi
echo "::notice::Found remote deployment log:"
ssh -o BatchMode=yes -p ${{ steps.parse-url.outputs.port }} ${{ steps.parse-url.outputs.username }}@${{ steps.parse-url.outputs.hostname }} \
"cat $remote_log_path | sed 's/^/[remote] /'"
fi
- name: Teardown SSH agent
uses: drkibitz/github/actions/teardown-ssh-agent@main
if: always()