|
9 | 9 | jobs: |
10 | 10 | build: |
11 | 11 | runs-on: ubuntu-24.04 |
12 | | - services: |
13 | | - postgres: |
14 | | - image: postgres:16 |
15 | | - env: |
16 | | - POSTGRES_PASSWORD: postgres |
17 | | - ports: |
18 | | - - 5432:5432 |
19 | | - options: >- |
20 | | - --health-cmd pg_isready |
21 | | - --health-interval 10s |
22 | | - --health-timeout 5s |
23 | | - --health-retries 5 |
| 12 | + # Use your self-built image as container for the entire job |
| 13 | + container: ghcr.io/${{ github.repository }}/ci-base:latest |
24 | 14 | steps: |
25 | 15 | - uses: actions/checkout@v4 |
| 16 | + - name: Start PostgreSQL |
| 17 | + run: | |
| 18 | + sudo service postgresql start |
| 19 | + |
26 | 20 | - name: Set up Python ${{ matrix.python-version }} |
| 21 | + id: setup-python |
27 | 22 | uses: actions/setup-python@v5 |
28 | 23 | with: |
29 | 24 | python-version: '3.12' |
30 | | - - name: Setup Node |
31 | | - uses: actions/setup-node@v4 |
32 | | - with: |
33 | | - node-version: '20.x' |
34 | | - - name: Setup Postgres |
35 | | - env: |
36 | | - PGPASSWORD: postgres |
37 | | - PGHOSTADDR: 127.0.0.1 |
38 | | - run: | |
39 | | - psql -c 'create database django;' -U postgres |
40 | | - psql -c 'create database django_test;' -U postgres |
41 | | - - name: Cache node modules |
| 25 | + |
| 26 | + - name: Cache node packages |
42 | 27 | uses: actions/cache@v4 |
43 | 28 | env: |
44 | | - cache-name: cache-node-modules |
| 29 | + cache-name: cache-node-packages |
45 | 30 | with: |
46 | 31 | path: ~/.npm |
47 | 32 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }} |
48 | 33 | restore-keys: | |
49 | 34 | ${{ runner.os }}-build-${{ env.cache-name }}- |
50 | 35 | ${{ runner.os }}-build- |
51 | 36 | ${{ runner.os }}- |
52 | | - - name: Cache pip packages |
| 37 | + - name: Cache node Modules |
| 38 | + id: cache-node-modules |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + path: node_modules |
| 42 | + key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }} |
| 43 | + restore-keys: | |
| 44 | + ${{ runner.os }}-node_modules- |
| 45 | +
|
| 46 | + - name: Cache uv packages |
53 | 47 | uses: actions/cache@v4 |
54 | 48 | env: |
55 | | - cache-name: cache-pip-packages |
| 49 | + cache-name: cache-uv-packages |
56 | 50 | with: |
57 | | - path: ~/.cache/pip |
| 51 | + path: ~/.cache/uv |
58 | 52 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/requirements/dev.txt') }} |
59 | 53 | restore-keys: | |
60 | 54 | ${{ runner.os }}-build-${{ env.cache-name }}- |
61 | 55 | ${{ runner.os }}-build- |
62 | 56 | ${{ runner.os }}- |
63 | | - - name: check a4 hashes equal |
| 57 | +
|
| 58 | + - name: Cache testmon data |
| 59 | + id: cache-testmon |
| 60 | + uses: actions/cache@v4 |
| 61 | + with: |
| 62 | + path: .testmondata |
| 63 | + key: ${{ runner.os }}-testmon-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/requirements/dev.txt', 'adhocracy-plus/config/settings/*.py', 'pytest.ini') }} |
| 64 | + restore-keys: | |
| 65 | + ${{ runner.os }}-testmon-${{ steps.setup-python.outputs.python-version }}- |
| 66 | +
|
| 67 | + - name: Checks |
64 | 68 | run: | |
| 69 | + echo "node_modules cache hit: ${{ steps.cache-node-modules.outputs.cache-hit }}" |
| 70 | + ls -la node_modules 2>/dev/null || echo "node_modules directory does not exist" |
| 71 | + echo "testmon cache hit: ${{ steps.cache-testmon.outputs.cache-hit }}" |
| 72 | + ls -la .testmondata || true |
65 | 73 | ./scripts/a4-check.sh |
66 | | - - name: Install Dependencies |
| 74 | +
|
| 75 | + - name: Install Python Dependencies |
67 | 76 | run: | |
68 | | - npm install |
69 | | - npm run build |
70 | | - pip install -r requirements/dev.txt |
71 | | - pip install coveralls |
| 77 | + uv pip install -r requirements/dev.txt --system |
| 78 | + uv pip install coveralls --system |
| 79 | +
|
72 | 80 | - name: Run Tests |
73 | 81 | env: |
74 | 82 | PGPASSWORD: postgres |
75 | 83 | PGHOSTADDR: 127.0.0.1 |
76 | 84 | run: | |
77 | 85 | python manage.py collectstatic > /dev/null |
78 | | - DJANGO_SETTINGS_MODULE='adhocracy-plus.config.settings.travis' py.test --cov |
79 | 86 | isort --diff -c adhocracy-plus tests |
80 | 87 | python manage.py makemigrations --dry-run --check --noinput |
81 | 88 | flake8 adhocracy-plus tests --exclude migrations,settings |
| 89 | + |
| 90 | + if [ "${{ github.ref }}" = "refs/heads/main" ] && [ "${{ github.event_name }}" = "push" ]; then |
| 91 | + py.test --ds=adhocracy-plus.config.settings.travis --cov |
| 92 | + elif [ "${{ github.event_name }}" = "pull_request" ]; then |
| 93 | + py.test --ds=adhocracy-plus.config.settings.travis --testmon --cov |
| 94 | + fi |
| 95 | +
|
82 | 96 | - name: Coveralls |
83 | 97 | env: |
| 98 | + COVERALLS_SERVICE_NAME: github-actions |
84 | 99 | GITHUB_TOKEN: ${{ secrets.COV }} |
85 | 100 | run: | |
| 101 | + git config --global --add safe.directory /__w/adhocracy-plus/adhocracy-plus |
| 102 | + git config --global user.name "GitHub Actions" |
| 103 | + git config --global user.email "actions@github.com" |
86 | 104 | coveralls |
| 105 | +
|
| 106 | + - name: Install NPM Dependencies |
| 107 | + run: | |
| 108 | + if [ -d node_modules ] && [ -f package-lock.json ]; then |
| 109 | + echo "node_modules cache hit - skipping npm ci" |
| 110 | + else |
| 111 | + echo "node_modules cache miss - running npm ci" |
| 112 | + npm ci --prefer-offline --no-audit --no-fund |
| 113 | + fi |
| 114 | +
|
| 115 | + - name: Build NPM |
| 116 | + run: | |
| 117 | + npm run build |
| 118 | +
|
87 | 119 | - name: Run Frontend Tests |
88 | 120 | run: | |
89 | 121 | npm test |
90 | 122 | npm run lint |
| 123 | +
|
91 | 124 | - name: Deploy |
92 | 125 | if: github.ref == 'refs/heads/main' |
93 | 126 | env: |
|
0 commit comments