-
Notifications
You must be signed in to change notification settings - Fork 99
164 lines (130 loc) · 5.76 KB
/
Copy pathpreprod_integration_tests.yml
File metadata and controls
164 lines (130 loc) · 5.76 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
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
name: Preprod Integration Tests
on:
pull_request:
branches: [master, 'prepare-*', 'chore/prepare-*']
workflow_dispatch:
permissions:
contents: write
pages: write
id-token: write
pull-requests: write
env:
# Path to the cardano-graphql repo on the self-hosted runner VM
REPO_PATH: /home/integration/git/cardano-graphql
jobs:
integration-tests:
runs-on: [self-hosted]
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- name: Update local repository
run: |
cd ${{ env.REPO_PATH }}
git fetch origin
git checkout master
git pull origin master
if [ "${{ github.event_name }}" = "pull_request" ]; then
git branch -D pr-${{ github.event.pull_request.number }} 2>/dev/null || true
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }}
git checkout pr-${{ github.event.pull_request.number }}
else
git checkout ${{ github.ref_name }}
git reset --hard origin/${{ github.ref_name }}
fi
- name: Install dependencies
run: |
cd ${{ env.REPO_PATH }}
yarn install --frozen-lockfile --non-interactive
- name: Build packages
run: |
cd ${{ env.REPO_PATH }}
yarn workspace @cardano-graphql/util build
yarn workspace @cardano-graphql/util-dev build
- name: Stop all services
run: |
cd ${{ env.REPO_PATH }}
docker compose --env-file .env.docker-compose-preprod down || true
- name: Build and start all services
run: |
cd ${{ env.REPO_PATH }}
docker compose --env-file .env.docker-compose-preprod up -d --build
- name: Wait for GraphQL API to be ready
timeout-minutes: 5
run: |
echo "Waiting for GraphQL API to start..."
API_PORT=$(grep '^API_PORT=' ${{ env.REPO_PATH }}/.env.docker-compose-preprod | cut -d= -f2)
API_URL="http://localhost:${API_PORT}/graphql"
echo "API URL: ${API_URL}"
for i in {1..30}; do
RESPONSE=$(curl -sf -X POST "${API_URL}" \
-H 'Content-Type: application/json' \
-d '{"query": "{ cardanoDbMeta { initialized syncPercentage }}"}' 2>/dev/null) || true
INITIALIZED=$(echo "$RESPONSE" | jq -r '.data.cardanoDbMeta.initialized' 2>/dev/null || echo "false")
SYNC=$(echo "$RESPONSE" | jq -r '.data.cardanoDbMeta.syncPercentage' 2>/dev/null || echo "0")
if [ "$INITIALIZED" = "true" ]; then
echo "✓ API is initialized and ready (sync: ${SYNC}%)"
break
fi
if [ "$i" -eq 30 ]; then
echo "❌ API failed to initialize after 5 minutes"
docker compose --env-file ${{ env.REPO_PATH }}/.env.docker-compose-preprod logs server
exit 1
fi
echo "Waiting... initialized=${INITIALIZED}, sync=${SYNC}% ($i/30)"
sleep 10
done
- name: Run integration tests
id: tests
run: |
cd ${{ env.REPO_PATH }}
API_PORT=$(grep '^API_PORT=' .env.docker-compose-preprod | cut -d= -f2)
GRAPHQL_URL="http://localhost:${API_PORT}" \
yarn workspace @cardano-graphql/api-cardano-db-hasura test \
--testPathPattern="(delegations|paymentAddress|delegationVotes|blocks|epochs|transactions|stakePool|rewards|withdrawals|activeStake|utxos|ada|cardano|genesis|stakeRegistrations|stakeDeregistrations|tokenMints|scripts|redeemers|collateralInputs|collateralOutputs|govActionProposals|voteProcedures|epochParams|drepRegistrations).query.test" \
--forceExit \
2>&1 | tee /tmp/test-output.txt
TEST_EXIT_CODE=${PIPESTATUS[0]}
echo "test_exit_code=${TEST_EXIT_CODE}" >> $GITHUB_OUTPUT
exit ${TEST_EXIT_CODE}
- name: Comment PR with results
if: always() && github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const prNumber = context.issue.number;
const testExitCode = '${{ steps.tests.outputs.test_exit_code }}';
const testsSkipped = '${{ steps.tests.outcome }}' === 'skipped';
let emoji, status;
if (testsSkipped) {
emoji = '💥';
status = 'DEPLOYMENT FAILED';
} else {
const passed = testExitCode === '0';
emoji = passed ? '✅' : '❌';
status = passed ? 'PASSED' : 'FAILED';
}
let comment = `## ${emoji} Preprod Integration Tests: ${status}\n\n`;
comment += `🔗 [Action Run #${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})\n\n`;
comment += `_GraphQL integration tests run against live preprod blockchain data_`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: comment
});
- name: Restore stable version on failure
if: failure() && steps.tests.outcome == 'failure'
run: |
cd ${{ env.REPO_PATH }}
LAST_TAG=$(git tag --sort=-version:refname | head -1)
echo "⚠️ Tests failed — rolling back to ${LAST_TAG}"
git checkout -f "${LAST_TAG}"
docker compose \
--env-file .env.docker-compose-preprod \
up -d --build
echo "✅ Rolled back to ${LAST_TAG}"
- name: Restore env file
if: always()
run: |
cd ${{ env.REPO_PATH }}
git restore .env.docker-compose-preprod 2>/dev/null || true