|
| 1 | +name: main |
| 2 | +on: [push] |
| 3 | + |
| 4 | +jobs: |
| 5 | + build: |
| 6 | + name: Build vinta_schedule_api |
| 7 | + strategy: |
| 8 | + matrix: |
| 9 | + python: [3.13] |
| 10 | + env: |
| 11 | + DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/vinta_schedule_test" |
| 12 | + REDIS_URL: "redis://localhost:6379" |
| 13 | + runs-on: ubuntu-latest |
| 14 | + services: |
| 15 | + postgres: |
| 16 | + image: postgres:15 |
| 17 | + env: |
| 18 | + POSTGRES_PASSWORD: postgres |
| 19 | + POSTGRES_USER: postgres |
| 20 | + POSTGRES_DB: vinta_schedule_test |
| 21 | + ports: |
| 22 | + - 5432:5432 |
| 23 | + options: >- |
| 24 | + --health-cmd pg_isready |
| 25 | + --health-interval 10s |
| 26 | + --health-timeout 5s |
| 27 | + --health-retries 5 |
| 28 | + redis: |
| 29 | + image: redis:7 |
| 30 | + ports: |
| 31 | + - 6379:6379 |
| 32 | + options: >- |
| 33 | + --health-cmd "redis-cli ping" |
| 34 | + --health-interval 10s |
| 35 | + --health-timeout 5s |
| 36 | + --health-retries 5 |
| 37 | + steps: |
| 38 | + - name: Checkout code |
| 39 | + uses: actions/checkout@v4 |
| 40 | + - name: Store branch and latest SHA |
| 41 | + run: | |
| 42 | + echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" |
| 43 | + echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" |
| 44 | + id: git |
| 45 | + - name: Setup Python ${{ matrix.python }} |
| 46 | + uses: actions/setup-python@v5 |
| 47 | + with: |
| 48 | + python-version: ${{ matrix.python }} |
| 49 | + - name: Cache pip |
| 50 | + uses: actions/cache@v4 |
| 51 | + env: |
| 52 | + cache_name: pip-cache |
| 53 | + with: |
| 54 | + path: ~/.cache/pip |
| 55 | + key: build-${{ env.cache_name }}-${{ steps.git.outputs.branch }}-${{ steps.git.outputs.sha_short }} |
| 56 | + restore-keys: | |
| 57 | + build-${{ env.cache_name }}-${{ steps.git.outputs.branch }}-${{ steps.git.outputs.sha_short }} |
| 58 | + build-${{ env.cache_name }}-${{ steps.git.outputs.branch }} |
| 59 | + build-${{ env.cache_name }} |
| 60 | + - run: python -m pip install --upgrade pip |
| 61 | + - run: python -m pip install poetry==2.1.3 |
| 62 | + - run: curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash |
| 63 | + - run: sudo apt-get install git-lfs --upgrade |
| 64 | + - name: Install PostgreSQL client |
| 65 | + run: sudo apt-get update && sudo apt-get install -y postgresql-client |
| 66 | + - run: poetry install --with dev --no-root --no-interaction --no-ansi |
| 67 | + - name: Generate secret key |
| 68 | + run: echo '::set-output name=SECRET_KEY::`python -c "import uuid; print(uuid.uuid4().hex + uuid.uuid4().hex)"`' |
| 69 | + id: secret_id_generator |
| 70 | + - name: Linting |
| 71 | + run: poetry run ruff check ./ |
| 72 | + env: |
| 73 | + DJANGO_SETTINGS_MODULE: "vinta_schedule_api.settings.test" |
| 74 | + SECRET_KEY: ${{ steps.secret_id_generator.outputs.SECRET_KEY }} |
| 75 | + DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/vinta_schedule_test" |
| 76 | + ALLOWED_HOSTS: ".example.com" |
| 77 | + SMTP_HOST: 'example.com' |
| 78 | + SMTP_USERNAME: "test" |
| 79 | + SMTP_PASSWORD: "test" |
| 80 | + REDIS_URL: "redis://localhost:6379" |
| 81 | + SITE_DOMAIN: 'example.com' |
| 82 | + API_DOMAIN: 'api.example.com' |
| 83 | + DEFAULT_BCC_EMAILS: 'hugo@example.com' |
| 84 | + AWS_STATIC_BUCKET_NAME: 'example-static' |
| 85 | + AWS_ACCESS_KEY_ID: 'test' |
| 86 | + AWS_SECRET_ACCESS_KEY: 'test' |
| 87 | + AWS_S3_ACCESS_KEY_ID: 'test' |
| 88 | + AWS_S3_SECRET_ACCESS_KEY: 'test' |
| 89 | + AWS_MEDIA_BUCKET_NAME: 'example-media' |
| 90 | + AWS_MEDIA_LOCATION: 'media' |
| 91 | + AWS_MEDIA_S3_CUSTOM_DOMAIN: 'example.com' |
| 92 | + AWS_MEDIA_S3_ENDPOINT_URL: 'https://example.com' |
| 93 | + AWS_S3_REGION_NAME: 'us-east-1' |
| 94 | + AWS_CLOUDFRONT_KEY_ID: 'test' |
| 95 | + AWS_CLOUDFRONT_KEY: 'test' |
| 96 | + SALT_KEY: 'test_salt_key_123' |
| 97 | + TWILLIO_ACCOUNT_SID: 'FAKE_ACCOUNT_SID' |
| 98 | + TWILIO_AUTH_TOKEN: 'FAKE_ACCOUNT_SID' |
| 99 | + TWILIO_NUMBER: '+12345678901' |
| 100 | + TWILLIO_DEFAULT_BROADCAST_NUMBERS: '+12345678901,+10987654321' |
| 101 | + |
| 102 | + |
| 103 | + - run: poetry run pre-commit run --all-files |
| 104 | + env: |
| 105 | + SKIP: ruff,eslint,missing-migrations,backend-schema |
| 106 | + - run: poetry run python manage.py makemigrations --check --dry-run |
| 107 | + env: |
| 108 | + DJANGO_SETTINGS_MODULE: "vinta_schedule_api.settings.production" |
| 109 | + SECRET_KEY: ${{ steps.secret_id_generator.outputs.SECRET_KEY }} |
| 110 | + DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/vinta_schedule_test" |
| 111 | + ALLOWED_HOSTS: ".example.org" |
| 112 | + SMTP_HOST: 'example.org' |
| 113 | + SMTP_USERNAME: "test" |
| 114 | + SMTP_PASSWORD: "test" |
| 115 | + REDIS_URL: "redis://localhost:6379" |
| 116 | + SITE_DOMAIN: 'example.com' |
| 117 | + API_DOMAIN: 'api.example.com' |
| 118 | + DEFAULT_BCC_EMAILS: 'hugo@example.com' |
| 119 | + AWS_STATIC_BUCKET_NAME: 'example-static' |
| 120 | + AWS_ACCESS_KEY_ID: 'test' |
| 121 | + AWS_SECRET_ACCESS_KEY: 'test' |
| 122 | + AWS_S3_ACCESS_KEY_ID: 'test' |
| 123 | + AWS_S3_SECRET_ACCESS_KEY: 'test' |
| 124 | + AWS_MEDIA_BUCKET_NAME: 'example-media' |
| 125 | + AWS_MEDIA_LOCATION: 'media' |
| 126 | + AWS_MEDIA_S3_CUSTOM_DOMAIN: 'example.com' |
| 127 | + AWS_MEDIA_S3_ENDPOINT_URL: 'https://example.com' |
| 128 | + AWS_S3_REGION_NAME: 'us-east-1' |
| 129 | + AWS_CLOUDFRONT_KEY_ID: 'test' |
| 130 | + AWS_CLOUDFRONT_KEY: 'test' |
| 131 | + SALT_KEY: 'test_salt_key_123' |
| 132 | + TWILLIO_ACCOUNT_SID: 'FAKE_ACCOUNT_SID' |
| 133 | + TWILIO_AUTH_TOKEN: 'FAKE_ACCOUNT_SID' |
| 134 | + TWILIO_NUMBER: '+12345678901' |
| 135 | + TWILLIO_DEFAULT_BROADCAST_NUMBERS: '+12345678901,+10987654321' |
| 136 | + - run: poetry run python manage.py check --deploy |
| 137 | + env: |
| 138 | + DJANGO_SETTINGS_MODULE: "vinta_schedule_api.settings.production" |
| 139 | + SECRET_KEY: ${{ steps.secret_id_generator.outputs.SECRET_KEY }} |
| 140 | + DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/vinta_schedule_test" |
| 141 | + ALLOWED_HOSTS: ".example.org" |
| 142 | + SMTP_HOST: 'example.org' |
| 143 | + SMTP_USERNAME: "test" |
| 144 | + SMTP_PASSWORD: "test" |
| 145 | + REDIS_URL: "redis://localhost:6379" |
| 146 | + SITE_DOMAIN: 'example.com' |
| 147 | + API_DOMAIN: 'api.example.com' |
| 148 | + DEFAULT_BCC_EMAILS: 'hugo@example.com' |
| 149 | + AWS_STATIC_BUCKET_NAME: 'example-static' |
| 150 | + AWS_ACCESS_KEY_ID: 'test' |
| 151 | + AWS_SECRET_ACCESS_KEY: 'test' |
| 152 | + AWS_S3_ACCESS_KEY_ID: 'test' |
| 153 | + AWS_S3_SECRET_ACCESS_KEY: 'test' |
| 154 | + AWS_MEDIA_BUCKET_NAME: 'example-media' |
| 155 | + AWS_MEDIA_LOCATION: 'media' |
| 156 | + AWS_MEDIA_S3_CUSTOM_DOMAIN: 'example.com' |
| 157 | + AWS_MEDIA_S3_ENDPOINT_URL: 'https://example.com' |
| 158 | + AWS_S3_REGION_NAME: 'us-east-1' |
| 159 | + AWS_CLOUDFRONT_KEY_ID: 'test' |
| 160 | + AWS_CLOUDFRONT_KEY: 'test' |
| 161 | + SALT_KEY: 'test_salt_key_123' |
| 162 | + TWILLIO_ACCOUNT_SID: 'FAKE_ACCOUNT_SID' |
| 163 | + TWILIO_AUTH_TOKEN: 'FAKE_ACCOUNT_SID' |
| 164 | + TWILIO_NUMBER: '+12345678901' |
| 165 | + TWILLIO_DEFAULT_BROADCAST_NUMBERS: '+12345678901,+10987654321' |
| 166 | + - run: | |
| 167 | + poetry run pytest $(ARG) -vs -n auto --no-header --cov=. --cov-report=xml:junit/test-results.xml --junitxml=junit.xml -o junit_family=legacy |
| 168 | + env: |
| 169 | + DJANGO_SETTINGS_MODULE: "vinta_schedule_api.settings.test" |
| 170 | + SECRET_KEY: ${{ steps.secret_id_generator.outputs.SECRET_KEY }} |
| 171 | + DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/vinta_schedule_test" |
| 172 | + ALLOWED_HOSTS: ".example.com" |
| 173 | + SMTP_HOST: 'example.com' |
| 174 | + SMTP_USERNAME: "test" |
| 175 | + SMTP_PASSWORD: "test" |
| 176 | + REDIS_URL: "redis://localhost:6379" |
| 177 | + SITE_DOMAIN: 'example.com' |
| 178 | + API_DOMAIN: 'api.example.com' |
| 179 | + DEFAULT_BCC_EMAILS: 'hugo@example.com' |
| 180 | + AWS_STATIC_BUCKET_NAME: 'example-static' |
| 181 | + AWS_ACCESS_KEY_ID: 'test' |
| 182 | + AWS_SECRET_ACCESS_KEY: 'test' |
| 183 | + AWS_S3_ACCESS_KEY_ID: 'test' |
| 184 | + AWS_S3_SECRET_ACCESS_KEY: 'test' |
| 185 | + AWS_MEDIA_BUCKET_NAME: 'example-media' |
| 186 | + AWS_MEDIA_LOCATION: 'media' |
| 187 | + AWS_MEDIA_S3_CUSTOM_DOMAIN: 'example.com' |
| 188 | + AWS_MEDIA_S3_ENDPOINT_URL: 'https://example.com' |
| 189 | + AWS_S3_REGION_NAME: 'us-east-1' |
| 190 | + AWS_CLOUDFRONT_KEY_ID: 'test' |
| 191 | + AWS_CLOUDFRONT_KEY: 'test' |
| 192 | + SALT_KEY: 'test_salt_key_123' |
| 193 | + TWILLIO_ACCOUNT_SID: 'FAKE_ACCOUNT_SID' |
| 194 | + TWILIO_AUTH_TOKEN: 'FAKE_ACCOUNT_SID' |
| 195 | + TWILIO_NUMBER: '+12345678901' |
| 196 | + TWILLIO_DEFAULT_BROADCAST_NUMBERS: '+12345678901,+10987654321' |
| 197 | +
|
| 198 | + - name: Archive code coverage results |
| 199 | + uses: actions/upload-artifact@v4 |
| 200 | + with: |
| 201 | + name: code-coverage-report |
| 202 | + path: junit/test-results.xml |
| 203 | + |
| 204 | + - name: Upload coverage to Codecov |
| 205 | + uses: codecov/codecov-action@v4 |
| 206 | + with: |
| 207 | + env_vars: OS,PYTHON |
| 208 | + fail_ci_if_error: true |
| 209 | + files: ./junit/test-results.xml |
| 210 | + flags: unittests |
| 211 | + name: codecov-umbrella |
| 212 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 213 | + verbose: true |
| 214 | + env: |
| 215 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 216 | + |
| 217 | + - name: Upload test results to Codecov |
| 218 | + if: ${{ !cancelled() }} |
| 219 | + uses: codecov/test-results-action@v1 |
| 220 | + with: |
| 221 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 222 | + env: |
| 223 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
0 commit comments