-
Notifications
You must be signed in to change notification settings - Fork 4
178 lines (157 loc) · 6.39 KB
/
test_release.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
name: Test release
on:
workflow_dispatch
env:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
TERM: dumb
ADMIN_EMAIL: ${{ secrets.ADMIN_EMAIL }}
ADMIN_PASSWORD: ${{ secrets.ADMIN_PASSWORD }}
ADMIN_USERNAME: ${{ secrets.ADMIN_USERNAME }}
GITHUB_TOKEN: ${{ github.token }}
TERMINUS_TOKEN: ${{ secrets.TERMINUS_TOKEN }}
RELEASE_SOURCE_SITE: ${{ secrets.RELEASE_SOURCE_SITE }}
TERMINUS_SITE: ${{ secrets.TERMINUS_SITE }}
CI_BRANCH: ${{ github.head_ref || github.ref_name }}
COMMIT_SHA: ${{ github.sha }}
CI_BUILD_NUMBER: ${{ github.run_number }}
DEFAULT_SITE: ${{ secrets.TERMINUS_SITE }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
GITHUB_OWNER: ${{ github.repository_owner }}
CI_PROJECT_NAME: ${{ github.repository }}
PR_NUMBER: ${{ github.event.number }}
CI_PULL_REQUEST: ${{ github.event.pull_request._links.html.href }}
TERMINUS_HIDE_GIT_MODE_WARNING: 1
defaults:
run:
shell: bash
jobs:
configure_env_vars:
name: Configure environment variables
container:
image: quay.io/pantheon-public/build-tools-ci:8.x-php8.1
options: --user root
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref || github.ref_name }}
- name: Set bash_env env var
run: echo BASH_ENV=${RUNNER_TEMP}/bash_env.txt >> $GITHUB_ENV
- name: Cache bash_env.txt
uses: actions/cache@v3
env:
cache-name: cache-bash-env
with:
path: ${{ env.BASH_ENV }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_number }}
# Set TERMINUS_ENV and related environment variables.
# https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
- name: setup-environment-vars
run: |
if [ "$CI_BRANCH" != "master" ]; then
# Test vars not set means trigger = push.
if [ -z "$PR_NUMBER" ]; then
# Var not set means trigger = push.
export PR_NUMBER=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/commits/${COMMIT_SHA}/pulls" | \
jq '.[0].number | select(.!=null)'`
fi
if [ -z "$CI_PULL_REQUEST" ]; then
export CI_PULL_REQUEST=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/commits/${COMMIT_SHA}/pulls" | \
jq '.[0].html_url | select(.!=null)'`
fi
fi
export CI_PROJECT_REPONAME=${GITHUB_REPOSITORY#*/}
export CI_PROJECT_USERNAME=${GITHUB_REPOSITORY_OWNER}
/build-tools-ci/scripts/set-environment
GITHUB_WORKFLOW_URL=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
echo "export CI_BUILD_URL='${GITHUB_WORKFLOW_URL}'" >> $BASH_ENV
echo "export CI_NODE_INDEX=0" >> $BASH_ENV
echo "export CI_REPOSITORY_URL='https://github.com/${GITHUB_REPOSITORY}'" >> $BASH_ENV
echo "export ARTIFACTS_DIR_URL='${GITHUB_WORKFLOW_URL}/#artifacts'" >> $BASH_ENV
setup-environment:
name: Set up environment
needs: configure_env_vars
runs-on: ubuntu-latest
container:
image: quay.io/pantheon-public/build-tools-ci:8.x-php8.1
options: --user root
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref || github.ref_name }}
fetch-depth: 0
- name: Set bash_env env var
run: echo BASH_ENV=${RUNNER_TEMP}/bash_env.txt >> $GITHUB_ENV
- name: Cache bash_env.txt
uses: actions/cache@v3
env:
cache-name: cache-bash-env
with:
path: ${{ env.BASH_ENV }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_number }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: unnecessary
- name: Authenticate to Terminus
run: terminus -n auth:login --machine-token="$TERMINUS_TOKEN"
- name: Create multidev
run: terminus -n multidev:create "$TERMINUS_SITE".dev pr-"$PR_NUMBER"
- name: Create backup
run: terminus backup:create $RELEASE_SOURCE_SITE.dev --keep-for=1
- name: Get backup
run: |
files_path=$(terminus backup:get $RELEASE_SOURCE_SITE.dev --element=files)
db_path=$(terminus backup:get $RELEASE_SOURCE_SITE.dev --element=database)
echo "files_path=$files_path" >> $GITHUB_ENV
echo "db_path=$db_path" >> $GITHUB_ENV
- name: Restore DB and files
run: |
terminus import:db -y "$TERMINUS_SITE.pr-$PR_NUMBER" "${{ env.db_path }}"
terminus import:files -y "$TERMINUS_SITE.pr-$PR_NUMBER" "${{ env.files_path }}"
- name: Build frontend components
env:
BRANCH: ${{ github.head_ref || github.ref_name }}
YALESITES_BUILD_TOKEN: ${{ secrets.YALESITES_BUILD_TOKEN }}
run: ./.ci/build/build_frontend
- name: Deploy to Pantheon
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: ./.ci/deploy/pantheon/dev-multidev
- name: Run cron and clear caches
run: |
terminus drush "$TERMINUS_SITE.pr-$PR_NUMBER" -- cron -v
terminus drush "$TERMINUS_SITE.pr-$PR_NUMBER" -- cr
terminus env:cc "$TERMINUS_SITE.pr-$PR_NUMBER"
- name: Setup tmate session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
percy-check:
name: Create Percy snapshots
needs: setup-environment
runs-on: ubuntu-latest
steps:
- name: Run percy
# uses: actions/setup-node@v3
# with:
# node-version: '14'
run: |
SITE_URL=$(terminus site:view "$TERMINUS_SITE.pr-$PR_NUMBER" --print)
npm install --save-dev @percy/cli
npx percy snapshot "$SITE_URL"menu-links-only/sitemap.xml
env:
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
- name: Setup tmate session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3