-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
103 lines (93 loc) · 3.47 KB
/
action.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: 'Static Site Preview (SSP)'
description: 'Deploy static site previews via ssh.'
author: 'Dafnik'
branding:
icon: 'truck'
color: 'purple'
inputs:
source:
required: true
description: 'Path to the files which should be deployed'
target:
required: true
description: 'Preview server target path, must be a directory path.'
host:
required: true
description: 'Preview server domain'
port:
description: 'Preview server ssh port'
default: '22'
username:
required: true
description: 'Preview server ssh username'
key:
description: 'Preview server ssh key content of private key. ex raw content of ~/.ssh/id_rsa'
strip_components:
description: 'remove the specified number of leading path elements'
default: '0'
delete_threshold_days:
default: '30'
description: 'Number of days after inactive previews are deleted'
runs:
using: 'composite'
steps:
- name: Check if run from pull request
shell: bash
if: github.event_name != 'pull_request'
run: |
echo "SSP can only be run from pull requests, stopping..."
echo "Check for pull request in the action step like this"
echo "if: github.event_name == 'pull_request'"
exit 1
- id: setup
shell: bash
name: Setup hash identifier & date
run: |
echo "name=${{ github.event.repository.name }}-${{ github.event.number }}" >> "$GITHUB_OUTPUT"
current_date=$(date '+%Y-%m-%d %H:%M:%S (%Z)')
echo "current_date=$current_date" >> "$GITHUB_OUTPUT"
future_date=$(date -d "+${{ inputs.delete_threshold_days }} days" '+%Y-%m-%d')
echo "future_date=$future_date" >> "$GITHUB_OUTPUT"
- id: hash
shell: bash
name: Create hash
run: |
echo Hash identifier: "${{ steps.setup.outputs.name }}"
hash=$(echo -n "${{ steps.setup.outputs.name }}" | md5sum | awk '{print $1}')
short_hash=${hash:0:10}
echo "md5=$short_hash" >> "$GITHUB_OUTPUT"
echo "url=https://$short_hash.${{ inputs.host }}" >> "$GITHUB_OUTPUT"
- name: Check if hash is empty
shell: bash
run: |
if [ -z "${{ steps.hash.outputs.md5 }}" ]; then
echo "MD5 hash generation failed, stopping..."
exit 1
else
echo "MD5 hash: ${{ steps.hash.outputs.md5 }}"
fi
- name: Copy source files to target server
uses: appleboy/[email protected]
with:
overwrite: true
host: ${{ inputs.host }}
username: ${{ inputs.username }}
key: ${{ inputs.key }}
port: ${{ inputs.port }}
source: ${{ inputs.source }}
target: '${{ inputs.target }}/${{ steps.hash.outputs.md5 }}'
strip_components: ${{ inputs.strip_components }}
- name: Create or update sticky pull request comment
uses: marocchino/sticky-pull-request-comment@v2
with:
message: |
This pull request has been automatically deployed using Dafnik's static site preview (SSP) action.
[Learn more](https://github.com/Dafnik/ssp).
🔎 **Commit:** ${{ github.sha }}
📅 **Updated at:** ${{ steps.setup.outputs.current_date }}
✅ **Preview URL:** <${{ steps.hash.outputs.url }}>
**Note:** If there is no further activity, this preview will be deleted **${{ inputs.delete_threshold_days }} day(s) from now** on ${{ steps.setup.outputs.future_date }}.
outputs:
url:
description: Deployment url
value: ${{ steps.hash.outputs.url }}