-
Notifications
You must be signed in to change notification settings - Fork 5
182 lines (181 loc) · 6.66 KB
/
sage-test.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Sage Install Tests
permissions:
pull-requests: read
contents: read
on:
pull_request:
paths:
- '.github/workflows/sage-test.yml'
- 'private/scripts/**'
types: [opened, synchronize, reopened, ready_for_review]
jobs:
apply_upstream_updates:
name: Apply Upstream Updates
runs-on: ubuntu-latest
env:
TERM: xterm-256color
defaults:
run:
shell: bash
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install SSH keys
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Get latest Terminus release
uses: pantheon-systems/terminus-github-actions@v1
with:
pantheon-machine-token: ${{ secrets.TERMINUS_TOKEN }}
- name: Validate Pantheon Host Key
run: |
echo "Host *.drush.in HostKeyAlgorithms +ssh-rsa" >> ~/.ssh/config
echo "Host *.drush.in PubkeyAcceptedKeyTypes +ssh-rsa" >> ~/.ssh/config
echo "StrictHostKeyChecking no" >> ~/.ssh/config
- name: Log into Terminus
run: |
terminus auth:login --machine-token=${{ secrets.TERMINUS_TOKEN }}
terminus upstream:updates:apply wpcm-sage-install-tests
test:
name: Sage Install Tests
env:
TERM: xterm-256color
needs: apply_upstream_updates
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
php-version: [8.1, 8.2, 8.3]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install SSH keys
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Get and Set PR number
id: pr
run: |
pr_num=${{ github.run_number }}
if [ "${pr_num}" == "" ]; then
echo "PR_NUM=rel" >> $GITHUB_ENV
else
echo "PR_NUM=${pr_num}" >> $GITHUB_ENV
fi
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: current
- name: Generate multidev name
id: generate_name
run: |
os_short=""
case "${{ matrix.os }}" in
ubuntu-latest)
os_short="nix"
;;
macos-latest)
os_short="mac"
;;
windows-latest)
os_short="win"
;;
esac
php_short=$(echo "${{ matrix.php-version }}" | tr -d '.')
echo "PR number: $PR_NUM"
echo "OS: $os_short"
echo "PHP: $php_short"
multidev_name="${os_short}-${php_short}-${PR_NUM}"
echo "Generated multidev name: $multidev_name"
echo "multidev_name=$multidev_name" >> $GITHUB_ENV
- name: Get latest Terminus release
uses: pantheon-systems/action-terminus-install@v1
with:
os: ${{ matrix.os }}
- name: Validate Pantheon Host Key
run: |
echo "Host *.drush.in HostKeyAlgorithms +ssh-rsa" >> ~/.ssh/config
echo "Host *.drush.in PubkeyAcceptedKeyTypes +ssh-rsa" >> ~/.ssh/config
echo "StrictHostKeyChecking no" >> ~/.ssh/config
- name: Log into Terminus
run: |
terminus auth:login --machine-token=${{ secrets.TERMINUS_TOKEN }}
- name: Clone site and create multidev
run: |
echo "Cloning site..."
terminus local:clone wpcm-sage-install-tests
cd ~/pantheon-local-copies/wpcm-sage-install-tests
if [[ -n $(git status --porcelain) ]]; then
echo "❌ Local clone is dirty. Exiting..."
exit 1
fi
# If sage-test exists, delete it.
if [[ -d "web/app/themes/sage-test" ]]; then
echo "Deleting existing sage-test..."
rm -rf web/app/themes/sage-test
fi
echo "Checking for existing multidev..."
multidevs=$(terminus env:list wpcm-sage-install-tests --format=json --fields=id)
# Use jq to check if the key exists in the JSON
match_exists=$(echo "$json_output" | jq --arg id "$multidev_name" 'any(.[]; .id == $id)')
if [ "$match_exists" == "true" ]; then
echo "Environment $multidev_name exists."
terminus multidev:delete --delete-branch --yes wpcm-sage-install-tests.$multidev_name
else
echo "Environment $multidev_name does not exist."
fi
terminus multidev:create wpcm-sage-install-tests.dev $multidev_name
terminus workflow:wait wpcm-sage-install-tests."$multidev_name" --quiet --max=15
echo "Checking out multidev..."
git fetch --all
git checkout $multidev_name
- name: Copy latest repository changes
run: |
# Sync the files from checked-out repo to pantheon-local-copies, excluding the .git folder
rsync -av --exclude='.git/' ${{ github.workspace }}/ ~/pantheon-local-copies/wpcm-sage-install-tests/
# Navigate to Pantheon local copies directory
cd ~/pantheon-local-copies/wpcm-sage-install-tests/
git config --global user.email "[email protected]"
git config --global user.name "Pantheon TestBot"
# Add, commit and push
git add .
git commit -m "Sync latest changes to test environment"
git push origin $multidev_name
- name: Install Composer Dependencies
run: |
cd ~/pantheon-local-copies/wpcm-sage-install-tests
composer update
- name: Run Sage Install Script
env:
SAGENAME: sage-test
SITENAME: wpcm-sage-install-tests
CI: 1
PHPVERSION: ${{ matrix.php-version }}
SITEENV: ${{ env.multidev_name }}
run: |
export SITEENV=$multidev_name
cd ~/pantheon-local-copies/$SITENAME
composer install-sage
echo "✅ Sage Install Script passed!"
- name: Delete multidev
if: always()
run: terminus multidev:delete --delete-branch --yes "wpcm-sage-install-tests.${multidev_name}"
- name: Delete the multidev build artifact
if: always()
run: |
cd ~/pantheon-local-copies/wpcm-sage-install-tests
# Allow these to fail.
git fetch --tags origin || true
git tag -d "pantheon_build_artifacts_${multidev_name}" || true
git push origin --delete "pantheon_build_artifacts_${multidev_name}" || true