-
Notifications
You must be signed in to change notification settings - Fork 33
170 lines (144 loc) · 5.83 KB
/
test-deployability.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
name: Test Ability to Deploy
on:
push:
branches:
- master
- main
- develop
- 'hotfix/**'
- 'release/**'
- 'feature/**'
- 'prototype/**'
tags:
- '*'
paths:
# IMPORTANT: Changes to these file specs must, Must, MUST be reflected in the file specs
# for pull_request and the check_for_past_run job.
- '**/config/install/*.yml'
- '**/modules/custom/*/*.install'
- '.github/workflows/test-deployability.yml'
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
paths:
# IMPORTANT: Changes to these file specs must, Must, MUST be reflected in the file specs
# for push and the check_for_past_run job.
- '**/config/install/*.yml'
- '**/modules/custom/*/*.install'
- '.github/workflows/test-deployability.yml'
# Only run one instance of this workflow at a time per branch.
concurrency:
group: ${{ github.ref_name }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
test_update:
name: Test ability to update
# Check whether the config and install files have changed since the last successful run.
# If not, there's no need to run this job.
needs: check_for_past_run
if: needs.check_for_past_run.outputs.changed == 'true'
runs-on: ubuntu-20.04
services:
## Ubuntu 20 comes with mysql 8, so we need a separate service
mysql:
image: mysql:5.7
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: drupal
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
steps:
## Checkout the master branch since that is what is currently on production.
- name: Checkout master branch from Github
uses: actions/checkout@v3
with:
ref: master
## Setup PHP and Composer Caching
- name: Setup PHP with tools
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
## This list of extensions matches those we install with our docker file, then I removed
## cli, common, fpm cause they would not install, then I removed xdebug cause why?
extensions: bz2, curl, gd, mbstring, memcached, mysql, oauth, opcache, readline, sqlite3, soap, xml
tools: composer:v2
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Composer install
run: |
composer install
- name: Put BLT, Drush, etc. on the path.
run: |
echo "$PWD/vendor/bin" >> $GITHUB_PATH
- name: Setup Env
run: |
## The mynci service creates the drupal DB, we need to make the
## simpletest DB for the phpunit tests by hand here.
mysql -u root -proot --protocol=TCP -e "CREATE DATABASE IF NOT EXISTS simpletest"
mysql -u root -proot --protocol=TCP -e "GRANT ALL ON simpletest.* to 'simpletest'@'%' IDENTIFIED BY 'simpletest'"
## We don't set git info for right now as we are in the NCIOCPL origin right now.
- name: Install Drupal (current production)
run: |
# Install with content
blt blt:init:settings --define drush.alias='${drush.aliases.ci}' --environment=ci --no-interaction --ansi --verbose
blt cgov:reinstall --define drush.alias='${drush.aliases.ci}' --environment=ci --no-interaction --ansi --verbose
- name: Switch to the branch from the pull request.
uses: actions/checkout@v3
- name: Install new code and run update.
run: |
composer cgov-clean && composer install
drush cr
blt drupal:update --define drush.alias='${drush.aliases.ci}' --environment=ci --no-interaction --ansi --verbose
# Jobs past this point are responsible for determining whether any of the .yaml or .install files have changed since
# the last successful run. The details of how this is done are unimportant to the overall task of checking whether
# the code will break deployment.
check_for_past_run:
name: Check for past successful run
runs-on: ubuntu-20.04
outputs:
changed: ${{ steps.record_change.outputs.changed }}
key: ${{ steps.install_files_hash.outputs.key }}
steps:
## Checks out the branch being tested.
- name: Checkout branch from Github
uses: actions/checkout@v3
- name: Generate install files hash
id: install_files_hash
run: |
echo "key=${{ runner.os }}-install-hash-$(find . -type f \( -path "*/modules/custom/*/*.install" -o -path "*/config/install/*.yml" -o -path ./.github/workflows/test-deployability.yml \) -exec md5sum {} + | sort | awk '{print $NF}' | tr -d '\n' | md5sum)" >> "$GITHUB_OUTPUT"
- name: Locate Cache
uses: actions/cache/restore@v3
id: retrieve_files_hash
with:
path: dummy.txt
key: ${{ steps.install_files_hash.outputs.key }}
lookup-only: true
- name: Record a change to the install files
id: record_change
if: steps.retrieve_files_hash.outputs.cache-hit != 'true'
run: |
echo "changed=true" >> "$GITHUB_OUTPUT"
save_successful_run:
name: Save install files hash
needs: [check_for_past_run, test_update]
runs-on: ubuntu-20.04
steps:
- name: Dummy file
run: |
touch dummy.txt
- name: Save install files cache
uses: actions/cache/save@v3
with:
path: dummy.txt
key: ${{ needs.check_for_past_run.outputs.key }}