-
Notifications
You must be signed in to change notification settings - Fork 33
181 lines (178 loc) · 7.57 KB
/
ci.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
name: Main CI Workflow
on:
push:
branches:
- master
- main
- develop
- 'hotfix/**'
- 'release/**'
- 'feature/**'
- 'prototype/**'
tags:
- '*'
pull_request:
# Only run one instance of this workflow at a time per branch.
concurrency:
group: ${{ github.ref_name }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
build:
name: Build, Test and Upload Artifacts
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:
- name: Setup variables
id: set_vars
run: |
## PUSH
if [ "${{ github.event_name }}" == "push" ]; then
BUILD_NAME=$(sed -E 's/refs\/(heads|tags)\///; s/\//__/g;' <<< $GITHUB_REF)
BRANCH_NAME=$(sed -E 's/refs\/(heads|tags)\///;' <<< $GITHUB_REF)
COMMIT_HASH=$(echo "${GITHUB_SHA}")
## PULL_REQUEST
elif [ "${{ github.event_name }}" == "pull_request" ]; then
BUILD_NAME=$(echo "pr-${{ github.event.pull_request.number }}")
BRANCH_NAME=$(echo "pr-${{ github.event.pull_request.number }}")
COMMIT_HASH=$(echo "${{ github.event.pull_request.head.sha }}")
else
## ERROR
exit 1
fi
## For step checks and artifact deployment path.
## Same for push and PR
export REPO_FULL=${{ github.repository }}
export REPO_RE='([^/]+)/(.*)'
[[ "$REPO_FULL" =~ $REPO_RE ]]
REPO_OWNER=$(echo "${BASH_REMATCH[1]}")
REPO_NAME=$(echo "${BASH_REMATCH[2]}")
## Set step outputs for later use
echo "build_name=${BUILD_NAME}" >> $GITHUB_OUTPUT
echo "branch_name=${BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "commit_hash=${COMMIT_HASH}" >> $GITHUB_OUTPUT
echo "repo_owner=${REPO_OWNER}" >> $GITHUB_OUTPUT
echo "repo_name=${REPO_NAME}" >> $GITHUB_OUTPUT
## This clones and checks out.
- name: Checkout branch from Github
uses: actions/checkout@v3
## Setup node and npm caching.
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '16.13.0'
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
registry-url: https://npm.pkg.github.com
scope: '@nciocpl'
- name: Install NPM 8
run: |
npm install -g npm@8.19.4
## 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: Validate
run: |
blt validate --define drush.alias='${drush.aliases.ci}' --ansi --verbose --no-interaction
- name: Setup App
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
## The setup app script cannot create build.json as we are in the NCIOCPL origin.
blt setup --define drush.alias='${drush.aliases.ci}' --environment=ci --no-interaction --ansi --verbose
- name: Run Front-end Tests
run: |
blt tests:frontend:run --define drush.alias='${drush.aliases.ci}' --define tests.run-server=false --environment=ci --ansi --verbose --no-interaction
- name: Behavioral Tests
timeout-minutes: 120
run: |
echo "TODO: Add Cypress tests here"
- name: PHP Unit Tests
timeout-minutes: 120
run: |
## Setup Simpletest info for kernel & functional tests
export SIMPLETEST_BASE_URL=http://127.0.0.1:8888
## This URI should be good until GitHub changes to use IPV6 or something stupid.
export SIMPLETEST_DB=mysql://simpletest:simpletest@127.0.0.1:3306/simpletest
## PHP Unit tests do not start the server
## drush rs is equivelent to blt tests:server:start, except it allows us to bind to all ips on the box.
## blt was not letting us bind to those IPs we wanted.
drush rs 0.0.0.0:8888 &
blt custom:paratest --define drush.alias='${drush.aliases.ci}' --environment=ci --define tests.run-server=true -D behat.web-driver=chrome --ansi --verbose
blt tests:server:kill --define drush.alias='${drush.aliases.ci}' --environment=ci --define tests.run-server=true -D behat.web-driver=chrome --ansi --verbose
- name: Build Artifact
env:
NEW_BUILD_DIR: ${{ format('{0}{1}', runner.temp, '/artifact') }}
run: |
blt deploy:check-dirty --ansi --verbose --no-interaction
blt artifact:build -D deploy.dir=${NEW_BUILD_DIR} -D deploy.docroot=${NEW_BUILD_DIR}/docroot --ansi --verbose --no-interaction
- name: Create Build Information
env:
BUILD_INFO: ${{ toJson(steps.set_vars.outputs) }}
NEW_BUILD_DIR: ${{ format('{0}{1}', runner.temp, '/artifact') }}
run: |
echo $BUILD_INFO
echo $BUILD_INFO > ${NEW_BUILD_DIR}/build.json
- name: Setup SSH Keys and known_hosts
run: |
mkdir -p $HOME/.ssh
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.ACE_SSH_KEY }}"
echo ${{ secrets.ACE_KNOWN_HOST }} >> $HOME/.ssh/known_hosts
- name: Setup Git User Name
run: |
git config --global user.name "Github Actions"
git config --global user.email "webcommauto@users.noreply.github.com"
- name: Push Artifact to Acquia
run: ./.github/scripts/push_acquia_git.sh
shell: bash
env:
ACE_GIT_SUBSCRIPTION: ${{ secrets.ACE_GIT_SUBSCRIPTION }}
ACE_GIT_HOST: ${{ secrets.ACE_GIT_HOST }}
ARTIFACT_GIT_DIR: ${{ format('{0}{1}', runner.temp, '/artifact-git') }}
ACE_BRANCH_NAME: ${{ format('gh-build-{0}', steps.set_vars.outputs.build_name) }}
NEW_BUILD_DIR: ${{ format('{0}{1}', runner.temp, '/artifact') }}
## This also uses available envs:
## - GITHUB_REF
## - GITHUB_RUN_ID
## - GITHUB_RUN_NUMBER