-
Notifications
You must be signed in to change notification settings - Fork 6
166 lines (136 loc) · 5.37 KB
/
ci-cd.yml
File metadata and controls
166 lines (136 loc) · 5.37 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# vim: set colorcolumn=:
name: ci-cd
on:
push:
pull_request:
workflow_dispatch:
inputs:
php_version:
description: "Specify the PHP version to use (e.g., 8.3)"
required: false
default: '8.3'
env:
PHP_VERSION: ${{ inputs.php_version || '8.3' }}
permissions:
contents: read
jobs:
linter:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Update apt cache
run: sudo apt-get update
- name: Install PHP ${{ env.PHP_VERSION }}
run: sudo apt-get install php${{ env.PHP_VERSION }}-cli php${{ env.PHP_VERSION }}-mbstring php${{ env.PHP_VERSION }}-xml
- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: lib
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install composer/vendor dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-reqs
- name: Validate PHP syntax
run: bash -c 'set -e;for file in $(find ./src ./tests -type f -regex ".*\.\(php\|phtml\)" -print); do php -e -l -f "$file"; done'
tests:
needs: [linter]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Update apt cache
run: sudo apt-get update
- name: Install PHP ${{ env.PHP_VERSION }}
run: sudo apt-get install php${{ env.PHP_VERSION }}-cli php${{ env.PHP_VERSION }}-mbstring php${{ env.PHP_VERSION }}-xml
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: lib
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install composer/vendor dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-reqs
- name: Run PHPUnit tests
run: lib/bin/phpunit --testdox
deploy:
needs: [linter, tests]
if: github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/phoenix')
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Everything
fetch-tags: true
- name: Update apt cache
run: sudo apt-get update
- name: Install PHP ${{ env.PHP_VERSION }}
run: sudo apt-get install php${{ env.PHP_VERSION }}-cli php${{ env.PHP_VERSION }}-mbstring php${{ env.PHP_VERSION }}-xml
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: lib
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install composer/vendor dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-reqs
- name: Sanitize Branch Name
run: |
CLEAN_BRANCH_NAME="${GITHUB_REF_NAME//\//_}"
echo "CLEAN_BRANCH_NAME=${CLEAN_BRANCH_NAME}" >> $GITHUB_ENV
- name: Create Config
env:
WEB_CONFIG_JSON: ${{ secrets.WEB_CONFIG_JSON }}
run: |
echo "${WEB_CONFIG_JSON}" > ./etc/config.phoenix.json
jq -c -e . ./etc/config.phoenix.json 1>/dev/null
- name: Create Version file
run: |
#!/usr/bin/env bash
set -ex -o pipefail
# Version identifier
echo "$(git describe --always --tags)" > ./etc/.rsync-version
# Version hash
echo "$(git rev-parse HEAD)" >> ./etc/.rsync-version
# Version ISO8601 timestamp
echo "$(git log -n 1 --pretty='%aI' HEAD)" >> ./etc/.rsync-version
# LICENSE version and ISO8601 timestamp
echo -n "$(git log -n 1 --pretty='%h %aI' ./LICENSE.txt)" >> ./etc/.rsync-version
- name: Deploy to Remote
env:
SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PORT: ${{ secrets.SSH_PORT }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_KEY: ${{ secrets.SSH_KEY }} # SSH private key stored as a GitHub secret
SSH_WEB_PATH: ${{ secrets.SSH_WEB_PATH }}
run: |
#!/usr/bin/env bash
set -ex -o pipefail
# Setup SSH directory, known hosts, and private key
mkdir -pv "${HOME}/.ssh"
echo "${SSH_KNOWN_HOSTS}" > "${HOME}/.ssh/known_hosts"
chmod -v 644 "${HOME}/.ssh/known_hosts"
echo "${SSH_KEY}" > "${HOME}/.ssh/id_${SSH_USER}"
chmod -v 400 "${HOME}/.ssh/id_${SSH_USER}"
# Deploy artifact to the remote
rsync -avzc --delete --delete-excluded --delete-after --progress \
--exclude-from="./etc/deploy-ignore.txt" \
--chown=${SSH_USER}:${SSH_USER} \
-e "ssh -i ${HOME}/.ssh/id_${SSH_USER} -p ${SSH_PORT}" \
"./" "${SSH_USER}@${SSH_HOST}:${SSH_WEB_PATH}/${CLEAN_BRANCH_NAME}"
# Cleanup the secret
rm -fv "${HOME}/.ssh/id_${SSH_USER}" "${HOME}/.ssh/id_${SSH_USER}.pub"
- name: Cleanup Config
run: |
rm -fv ./etc/config.phoenix.json