|
1 | 1 | version: 2.1 |
2 | 2 |
|
3 | | -# Shared setup steps via CircleCI reusable command. |
4 | | -# Both jobs need their own Docker environment (CircleCI jobs can't share Docker). |
5 | | -commands: |
6 | | - setup_docker: |
| 3 | +jobs: |
| 4 | + build: |
| 5 | + machine: |
| 6 | + image: ubuntu-2204:current |
| 7 | + resource_class: large |
| 8 | + environment: |
| 9 | + - TZ: "UTC" |
| 10 | + |
7 | 11 | steps: |
8 | 12 | - checkout |
9 | | - |
| 13 | + |
| 14 | + # Install Task |
10 | 15 | - run: |
11 | 16 | name: Install Task |
12 | 17 | command: | |
13 | 18 | sudo sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin |
14 | 19 | task --version |
15 | 20 |
|
| 21 | + # Set up environment file |
16 | 22 | - run: |
17 | 23 | name: Setup environment |
18 | 24 | command: | |
19 | 25 | cp .env.example .env |
| 26 | + |
| 27 | + # Configure for Docker Compose setup |
20 | 28 | sed -i 's/DB_HOST=.*$/DB_HOST=restarters_db/g' .env |
21 | 29 | sed -i 's/DB_DATABASE=.*$/DB_DATABASE=restarters_db_test/g' .env |
22 | 30 | sed -i 's/DB_USERNAME=.*$/DB_USERNAME=restarters/g' .env |
23 | 31 | sed -i 's/DB_PASSWORD=.*$/DB_PASSWORD=s3cr3t/g' .env |
| 32 | + |
| 33 | + # Configure Discourse integration |
24 | 34 | sed -i 's/FEATURE__DISCOURSE_INTEGRATION=.*$/FEATURE__DISCOURSE_INTEGRATION=true/g' .env |
25 | 35 | sed -i 's/DISCOURSE_URL=.*$/DISCOURSE_URL=http:\/\/restarters_discourse/g' .env |
26 | 36 | sed -i 's/DISCOURSE_APIKEY=.*$/DISCOURSE_APIKEY=fb71f38ca2b8b7cd6a041e57fd8202c9937088f0ecae7db40722bd758dda92fc/g' .env |
27 | 37 | sed -i 's/DISCOURSE_APIUSER=.*$/DISCOURSE_APIUSER=someuser/g' .env |
| 38 | + |
| 39 | + # Configure for testing |
28 | 40 | sed -i 's/APP_DEBUG=.*$/APP_DEBUG=false/g' .env |
29 | 41 | sed -i 's/SESSION_DOMAIN=.*$/SESSION_DOMAIN=localhost/g' .env |
30 | 42 | sed -i 's/HONEYPOT_DISABLE=.*$/HONEYPOT_DISABLE=TRUE/g' .env |
31 | 43 | sed -i 's/APP_URL=.*$/APP_URL=http:\/\/localhost:8001/g' .env |
| 44 | + |
| 45 | + # Add environment variables from CircleCI |
32 | 46 | echo "" >> .env |
33 | 47 | echo "GOOGLE_API_CONSOLE_KEY=$GOOGLE_API_CONSOLE_KEY" >> .env |
34 | 48 | echo "MAPBOX_TOKEN=$MAPBOX_TOKEN" >> .env |
35 | 49 |
|
36 | | - - restore_cache: |
37 | | - keys: |
38 | | - - composer-v2-{{ checksum "composer.lock" }} |
39 | | - - composer-v2- |
40 | | - |
41 | | - - restore_cache: |
42 | | - keys: |
43 | | - - node-modules-v1-{{ checksum "package-lock.json" }} |
44 | | - - node-modules-v1- |
45 | | - |
46 | | - - run: |
47 | | - name: Build frontend assets |
48 | | - command: | |
49 | | - npm install --legacy-peer-deps |
50 | | - npm run build |
51 | | - no_output_timeout: 15m |
52 | | - |
53 | | - - save_cache: |
54 | | - key: node-modules-v1-{{ checksum "package-lock.json" }} |
55 | | - paths: |
56 | | - - node_modules |
57 | | - |
| 50 | + # Start Docker services using Task |
58 | 51 | - run: |
59 | 52 | name: Start Docker services |
60 | 53 | command: | |
| 54 | + # Set environment variable for CircleCI detection |
61 | 55 | export CIRCLECI=true |
| 56 | + # Enable Docker Compose bake for build optimization |
62 | 57 | export COMPOSE_BAKE=true |
| 58 | + # Start all services using Task |
63 | 59 | task docker:up-all |
64 | 60 | no_output_timeout: 10m |
65 | 61 |
|
| 62 | + # Wait for services to be ready (includes build completion and restart detection) |
66 | 63 | - run: |
67 | 64 | name: Wait for services |
68 | 65 | command: | |
69 | 66 | task docker:wait-for-services-all |
70 | 67 |
|
71 | | - - save_cache: |
72 | | - key: composer-v2-{{ checksum "composer.lock" }} |
73 | | - paths: |
74 | | - - vendor |
75 | | - |
| 68 | + # Setup database and application |
76 | 69 | - run: |
77 | 70 | name: Setup application |
78 | 71 | command: | |
| 72 | + # Grant timezone access - run directly on MySQL container |
79 | 73 | docker exec restarters_db mysql -u root -ps3cr3t -e "GRANT SELECT ON mysql.time_zone_name TO 'restarters'@'%';" |
| 74 | +
|
| 75 | + # Setup additional configuration needed for CI (most setup already done by docker_run.sh) |
| 76 | + # Set MySQL function creators using session variable (compatible with MySQL 5.7) |
80 | 77 | docker exec restarters_db mysql -u root -ps3cr3t -e "SET GLOBAL log_bin_trust_function_creators = 1;" |
| 78 | +
|
| 79 | + # Disable ONLY_FULL_GROUP_BY for compatibility with getItemTypes() query |
81 | 80 | docker exec restarters_db mysql -u root -ps3cr3t -e "SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));" |
| 81 | +
|
| 82 | + # Generate additional Laravel artifacts for testing |
82 | 83 | docker exec restarters php artisan l5-swagger:generate |
83 | 84 |
|
| 85 | + # Setup Discourse API |
84 | 86 | - run: |
85 | 87 | name: Setup Discourse |
86 | 88 | command: | |
| 89 | + # Add API key to Discourse - run directly on PostgreSQL container |
87 | 90 | docker exec postgresql psql -U postgres -c "INSERT INTO api_keys (id, user_id, created_by_id, created_at, updated_at, allowed_ips, hidden, last_used_at, revoked_at, description, key_hash, truncated_key) VALUES (1, NULL, 1, '2021-10-25 13:56:20.033338', '2021-10-25 13:56:20.033338', NULL, false, NULL, NULL, 'Restarters', 'd89e9dfacfb611fbaf004807648187ce7ed474df44dcb0ada230fab5c8dd6a5b', '9fd7');" bitnami_discourse |
| 91 | + |
| 92 | + # Configure Discourse settings |
88 | 93 | docker exec restarters php artisan discourse:setting personal_message_enabled_groups 10 |
89 | 94 |
|
90 | | -jobs: |
91 | | - test-php: |
92 | | - machine: |
93 | | - image: ubuntu-2204:current |
94 | | - resource_class: large |
95 | | - environment: |
96 | | - - TZ: "UTC" |
97 | | - |
98 | | - steps: |
99 | | - - setup_docker |
100 | | - |
| 95 | + # Run PHPUnit tests |
101 | 96 | - run: |
102 | 97 | name: Run PHPUnit tests |
103 | 98 | command: | |
104 | | - mkdir -p /tmp/test-results/phpunit |
| 99 | + # Run PHPUnit tests using Task for consistency with local development |
105 | 100 | task docker:test:phpunit |
| 101 | + # Copy test results to host |
106 | 102 | docker cp restarters:/tmp/phpunit-results.xml /tmp/test-results/phpunit/results.xml |
107 | 103 | no_output_timeout: 45m |
108 | 104 |
|
| 105 | + # Run Jest tests |
109 | 106 | - run: |
110 | 107 | name: Run Jest tests |
111 | 108 | command: | |
112 | | - mkdir -p /tmp/test-results/jest |
| 109 | + # Run Jest tests using Task for consistency with local development |
113 | 110 | task docker:test:jest |
| 111 | + # Copy test results to host if they exist |
114 | 112 | docker cp restarters:/tmp/test-results/junit.xml /tmp/test-results/jest/junit.xml || echo "Jest results not found, skipping" |
115 | 113 |
|
116 | | - - store_artifacts: |
117 | | - path: /tmp/test-results |
118 | | - destination: test-results-php |
119 | | - |
120 | | - - store_test_results: |
121 | | - path: /tmp/test-results |
122 | | - |
123 | | - test-playwright: |
124 | | - machine: |
125 | | - image: ubuntu-2204:current |
126 | | - resource_class: large |
127 | | - environment: |
128 | | - - TZ: "UTC" |
129 | | - |
130 | | - steps: |
131 | | - - setup_docker |
132 | | - |
| 114 | + # Run main Playwright tests (excluding autocomplete) |
133 | 115 | - run: |
134 | 116 | name: Run main Playwright tests |
135 | 117 | command: | |
136 | | - mkdir -p /tmp/test-results/playwright /tmp/test-results/logs |
137 | | - ( while true; do sleep 60; echo "[ci-keepalive] $(date -u +%H:%M:%S)"; done ) & |
138 | | - KEEPALIVE_PID=$! |
139 | | - trap "kill $KEEPALIVE_PID 2>/dev/null || true" EXIT |
| 118 | + # Run Playwright tests using Task for consistency with local development |
140 | 119 | task docker:test:playwright |
141 | | - EXIT_CODE=$? |
142 | | - kill $KEEPALIVE_PID 2>/dev/null || true |
143 | | - exit $EXIT_CODE |
144 | | - no_output_timeout: 30m |
| 120 | + no_output_timeout: 10m |
145 | 121 |
|
| 122 | + # Copy test results and artifacts |
146 | 123 | - run: |
147 | 124 | name: Copy Playwright artifacts |
148 | 125 | command: | |
149 | | - mkdir -p /tmp/test-results/playwright /tmp/test-results/logs |
| 126 | + # Create test results directory on host |
| 127 | + mkdir -p /tmp/test-results/playwright |
| 128 | + mkdir -p /tmp/test-results/logs |
| 129 | +
|
| 130 | + # List what's available in the playwright container |
150 | 131 | docker exec restarters_playwright bash -c "ls -la /tmp/test-results/* || echo 'No playwright directories found'" |
151 | | - docker cp restarters_playwright:/tmp/test-results/. /tmp/test-results/playwright/ || echo "Playwright results not found" |
| 132 | +
|
| 133 | + # Copy test results and artifacts from playwright container to host |
| 134 | + docker cp restarters_playwright:/tmp/test-results/. /tmp/test-results/playwright/ || echo "Playwright HTML report not found" |
| 135 | +
|
| 136 | + # Copy Vite log from restarters container for debugging |
152 | 137 | docker cp restarters:/tmp/vite.log /tmp/test-results/logs/vite.log || echo "Vite log not found" |
153 | | - docker logs restarters > /tmp/test-results/logs/restarters.log 2>&1 || echo "Could not capture restarters logs" |
154 | | - docker exec restarters bash -c "tail -300 /var/www/storage/logs/laravel.log 2>/dev/null" > /tmp/test-results/logs/laravel.log || echo "No laravel log found" |
155 | 138 | when: always |
156 | 139 |
|
| 140 | + # Store artifacts |
157 | 141 | - store_artifacts: |
158 | 142 | path: /tmp/test-results |
159 | 143 | destination: playwright-test-results |
160 | | - |
| 144 | + |
161 | 145 | - store_test_results: |
162 | 146 | path: /tmp/test-results |
163 | 147 |
|
@@ -198,18 +182,13 @@ jobs: |
198 | 182 | workflows: |
199 | 183 | build-and-deploy: |
200 | 184 | jobs: |
201 | | - - test-php: |
202 | | - filters: |
203 | | - branches: |
204 | | - ignore: production |
205 | | - - test-playwright: |
| 185 | + - build: |
206 | 186 | filters: |
207 | 187 | branches: |
208 | 188 | ignore: production |
209 | 189 | - deploy-fly-dev: |
210 | 190 | requires: |
211 | | - - test-php |
212 | | - - test-playwright |
| 191 | + - build |
213 | 192 | filters: |
214 | 193 | branches: |
215 | 194 | only: develop |
|
0 commit comments