Repository navigation
140 lines (129 loc) · 5.04 KB
/
Copy pathdeploy.yml
File metadata and controls
140 lines (129 loc) · 5.04 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
name: "Deploy"
on:
workflow_call:
inputs:
environment:
required: true
type: string
log_level:
required: true
type: string
ssh_config:
type: string
default: ''
ssh_known_hosts:
type: string
default: ''
run_tests:
type: boolean
default: true
description: >
Re-run composer test before deploying. Defaults to true; set false in
repos where the ref being deployed has already passed CI: Test, to skip
the test run and the npm install that only exists to feed it.
purge:
type: string
default: ''
description: >
How the deploy purges the page caches: auto, none, soft or hard (see
deployer-genero's purge.php). Empty, or `default`, keeps the mode the
repo's deploy.php sets.
secrets:
DEPLOY_SSH_PRIVATE_KEY:
required: true
NPM_FONTAWESOME_AUTH_TOKEN:
required: true
PACKAGIST_GITHUB_TOKEN:
# Optional since COMPOSER_BOT_PRIVATE_KEY arrived. Pass one or the
# other; setup fails up front if a caller passes neither.
required: false
COMPOSER_BOT_PRIVATE_KEY:
required: false
YOAST_LICENSE_TOKEN:
required: false
jobs:
build_deploy:
name: Build and deploy
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
# See the note in test.yml for the sizing rule. Deploys are the longest job
# we run, and the failure mode this bounds is a wedged SSH session or a
# stalled rsync — both hang rather than exit.
timeout-minutes: 20
steps:
# ubuntu-26.04 mounts /tmp as a RAM-backed tmpfs with a ~6 GB per-user
# quota, and deployer builds the whole release in /tmp/dep-<project>, so
# deploys die with "Disk quota exceeded". Put /tmp back on the root disk,
# as on 24.04. A no-op once the image does this itself.
# https://github.com/actions/runner-images/issues/14777
- name: Keep /tmp on the root disk
run: |
if findmnt -n -t tmpfs /tmp > /dev/null; then
sudo systemctl mask tmp.mount
sudo umount -l /tmp
sudo chmod 1777 /tmp
fi
df -h /tmp
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Start SSH agent
uses: generoi/github-actions/ssh-agent@v1
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
- name: Setup project
uses: generoi/github-actions/setup@v2
with:
npm_fontawesome_auth_token: ${{ secrets.NPM_FONTAWESOME_AUTH_TOKEN }}
packagist_github_token: ${{ secrets.PACKAGIST_GITHUB_TOKEN }}
composer_bot_private_key: ${{ secrets.COMPOSER_BOT_PRIVATE_KEY }}
yoast_license_token: ${{ secrets.YOAST_LICENSE_TOKEN }}
# With run_tests: false nothing in this job touches the workspace's
# node_modules — deployer installs in its own build_path — so the
# ~255 MB restore is dead weight.
node_modules_cache: ${{ inputs.run_tests && 'always' || 'skip' }}
# Composer is always needed — dep and robo live in vendor/bin. npm is only
# needed because composer test lints the front end, so it follows run_tests.
- name: Install Composer dependencies
run: composer install --no-interaction
# $NODE_PACKAGE_MANAGER is set by the setup action from the lockfile on
# disk, so a repo that has switched to pnpm gets pnpm here without saying
# so twice. `pnpm install` with a committed lockfile is already
# frozen-lockfile in CI, so no flag is needed to match `npm install`'s
# behaviour here.
- name: Install Node dependencies
if: inputs.run_tests
run: $NODE_PACKAGE_MANAGER install
- name: Configure SSH
if: inputs.ssh_config != ''
env:
SSH_CONFIG: ${{ inputs.ssh_config }}
run: |
mkdir -p ~/.ssh
echo "$SSH_CONFIG" >> ~/.ssh/config
chmod 600 ~/.ssh/config
- name: Add known hosts
env:
SSH_KNOWN_HOSTS: ${{ inputs.ssh_known_hosts }}
DEPLOY_ENV: ${{ inputs.environment }}
run: |
if [ -n "$SSH_KNOWN_HOSTS" ]; then
echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
else
ssh-keyscan \
-p $(yq ".env[\"@${DEPLOY_ENV}\"].port // 22" robo.yml) \
$(yq ".env[\"@${DEPLOY_ENV}\"].host" robo.yml) >> ~/.ssh/known_hosts
fi
- name: Run tests
if: inputs.run_tests
run: composer test --no-interaction
- name: Deploy
env:
DEPLOY_ENV: ${{ inputs.environment }}
LOG_LEVEL: ${{ inputs.log_level }}
PURGE: ${{ inputs.purge }}
run: |
if [ -n "$PURGE" ] && [ "$PURGE" != default ]; then
./vendor/bin/dep deploy "$DEPLOY_ENV" "$LOG_LEVEL" -o "purge=$PURGE"
else
./vendor/bin/dep deploy "$DEPLOY_ENV" "$LOG_LEVEL"
fi