forked from kernelci/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 1
113 lines (99 loc) · 3.59 KB
/
deploy-staging.yaml
File metadata and controls
113 lines (99 loc) · 3.59 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
name: Deploy Staging and E2E
on:
workflow_call:
jobs:
check-migrations:
runs-on: ubuntu-latest
outputs:
has_new_migrations: ${{ steps.check.outputs.has_new_migrations }}
migration_list: ${{ steps.check.outputs.migration_list }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for new Django migrations
id: check
run: |
NEW_MIGRATIONS=$(git diff --name-only HEAD~1 HEAD -- '**/migrations/*.py' \
| grep -v '__init__.py' || true)
if [ -n "$NEW_MIGRATIONS" ]; then
echo "has_new_migrations=true" >> $GITHUB_OUTPUT
ENCODED=$(echo "$NEW_MIGRATIONS" | tr '\n' '|')
echo "migration_list=$ENCODED" >> $GITHUB_OUTPUT
echo "New migration files detected:"
echo "$NEW_MIGRATIONS"
else
echo "has_new_migrations=false" >> $GITHUB_OUTPUT
echo "migration_list=" >> $GITHUB_OUTPUT
echo "No new migration files found"
fi
notify-new-migrations:
needs: check-migrations
if: needs.check-migrations.outputs.has_new_migrations == 'true'
runs-on: ubuntu-latest
steps:
- name: Discord notification - new migrations detected
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "New Django migrations detected in this staging deployment: `${{ needs.check-migrations.outputs.migration_list }}`"
deploy-staging:
needs: check-migrations
runs-on: ubuntu-latest
steps:
- name: Configure staging host authenticity
run: |
mkdir -p ~/.ssh/ && chmod 700 ~/.ssh/
touch ~/.ssh/known_hosts && chmod 600 ~/.ssh/known_hosts
echo "$SSH_HOSTKEY" > ~/.ssh/known_hosts
env:
SSH_HOSTKEY: ${{ secrets.STAGING_HOSTKEY }}
- name: Deploy to staging
run: |
eval $(ssh-agent -s)
echo "$SSH_KEY" | ssh-add - >/dev/null
ssh "${SSH_USER}@${SSH_HOST}" "
rm -rf dashboard-staging &&
git clone --depth 1 --branch main https://github.com/kernelci/dashboard.git dashboard-staging &&
cp ~/.env-staging dashboard-staging/.env &&
cd dashboard-staging &&
git checkout ${GITHUB_SHA} &&
docker compose down &&
docker compose build --no-cache &&
docker compose up -d
"
env:
SSH_USER: ${{ secrets.STAGING_USER }}
SSH_HOST: ${{ secrets.STAGING_HOST }}
SSH_KEY: ${{ secrets.STAGING_KEY }}
e2e-tests:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: deploy-staging
steps:
- uses: actions/checkout@v4
- name: Fetch node_modules
uses: actions/cache@v4
id: fetch-node_modules
with:
key: node_modules-${{ runner.os }}-${{ hashFiles('./dashboard/pnpm-lock.yaml') }}
path: ./dashboard/node_modules
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9.15.2
- uses: actions/setup-node@v4
with:
node-version-file: './dashboard/.nvmrc'
- name: Install Playwright browsers
run: npx playwright install --with-deps
working-directory: ./dashboard
- name: Wait for staging deployment to be ready
run: sleep 180
- name: Run e2e tests against staging
run: pnpm e2e
working-directory: ./dashboard
env:
PLAYWRIGHT_TEST_BASE_URL: https://staging.dashboard.kernelci.org