Skip to content

Commit a29d546

Browse files
Simplify code structure
1 parent 1587fdc commit a29d546

150 files changed

Lines changed: 1361 additions & 3706 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gcloudignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
service: [api-full, api-simulation, api-tagger]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.13'
23+
24+
- name: Install uv
25+
uses: astral-sh/setup-uv@v3
26+
with:
27+
enable-cache: true
28+
29+
- name: Install dependencies
30+
run: |
31+
cd projects/policyengine-${{ matrix.service }}
32+
uv sync --extra test
33+
34+
- name: Run tests
35+
run: |
36+
cd projects/policyengine-${{ matrix.service }}
37+
uv run pytest tests/ -v --cov=src --cov-report=xml
38+
39+
- name: Upload coverage
40+
uses: codecov/codecov-action@v4
41+
with:
42+
file: ./projects/policyengine-${{ matrix.service }}/coverage.xml
43+
flags: ${{ matrix.service }}
44+
name: ${{ matrix.service }}
45+
fail_ci_if_error: false
46+
47+
lint:
48+
runs-on: ubuntu-latest
49+
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- name: Set up Python
54+
uses: actions/setup-python@v5
55+
with:
56+
python-version: '3.13'
57+
58+
- name: Install uv
59+
uses: astral-sh/setup-uv@v3
60+
61+
- name: Install ruff
62+
run: uv tool install ruff
63+
64+
- name: Run ruff format check
65+
run: |
66+
for dir in projects/*/src libs/*/src; do
67+
if [ -d "$dir" ]; then
68+
echo "Checking format in $dir..."
69+
uv run ruff format --check $dir
70+
fi
71+
done
72+
73+
- name: Run ruff lint
74+
run: |
75+
for dir in projects/*/src libs/*/src; do
76+
if [ -d "$dir" ]; then
77+
echo "Linting $dir..."
78+
uv run ruff check $dir
79+
fi
80+
done
81+
82+
docker-build:
83+
runs-on: ubuntu-latest
84+
strategy:
85+
matrix:
86+
service: [api-full, api-simulation, api-tagger]
87+
88+
steps:
89+
- uses: actions/checkout@v4
90+
91+
- name: Set up Docker Buildx
92+
uses: docker/setup-buildx-action@v3
93+
94+
- name: Build Docker image
95+
run: |
96+
docker build -f projects/policyengine-${{ matrix.service }}/Dockerfile \
97+
-t policyengine-${{ matrix.service }}:test \
98+
--build-arg BUILDKIT_INLINE_CACHE=1 \
99+
--cache-from type=gha \
100+
--cache-to type=gha,mode=max \
101+
.

.github/workflows/dependency-updater.yml

Lines changed: 0 additions & 75 deletions
This file was deleted.

.github/workflows/deploy.yml

Lines changed: 119 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,126 @@
1-
name: Deploy
1+
name: Deploy to GCP
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [main]
6+
workflow_dispatch:
7+
inputs:
8+
environment:
9+
description: 'Environment to deploy to'
10+
required: true
11+
default: 'dev'
12+
type: choice
13+
options:
14+
- dev
15+
- staging
16+
- prod
717

818
concurrency:
9-
group: deploy-main
19+
group: deploy-${{ github.ref }}
20+
cancel-in-progress: false
21+
22+
env:
23+
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
24+
REGION: us-central1
25+
REPO: api-v2
1026

1127
jobs:
12-
build_beta:
13-
name: Build beta
14-
uses: ./.github/workflows/gcp-build.reusable.yml
15-
with:
16-
environment: beta
17-
secrets: inherit
18-
build_prod:
19-
name: Build production
20-
needs: [build_beta]
21-
uses: ./.github/workflows/gcp-build.reusable.yml
22-
with:
23-
environment: prod
24-
secrets: inherit
25-
deploy_beta:
26-
name: Deploy beta
27-
needs: [build_beta]
28-
uses: ./.github/workflows/gcp-deploy.reusable.yml
29-
with:
30-
environment: beta
31-
secrets: inherit
32-
deploy_prod:
33-
name: Deploy production
34-
needs: [build_prod, deploy_beta]
35-
uses: ./.github/workflows/gcp-deploy.reusable.yml
36-
with:
37-
environment: prod
38-
secrets: inherit
28+
build-and-push:
29+
runs-on: ubuntu-latest
30+
permissions:
31+
contents: read
32+
id-token: write
33+
34+
strategy:
35+
matrix:
36+
service: [api-full, api-simulation, api-tagger]
37+
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Authenticate to Google Cloud
42+
uses: google-github-actions/auth@v2
43+
with:
44+
workload_identity_provider: ${{ secrets.WIF_PROVIDER }}
45+
service_account: ${{ secrets.WIF_SERVICE_ACCOUNT }}
46+
47+
- name: Set up Cloud SDK
48+
uses: google-github-actions/setup-gcloud@v2
49+
50+
- name: Configure Docker for Artifact Registry
51+
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
52+
53+
- name: Set up Docker Buildx
54+
uses: docker/setup-buildx-action@v3
55+
56+
- name: Build and push Docker image
57+
uses: docker/build-push-action@v5
58+
with:
59+
context: .
60+
file: projects/policyengine-${{ matrix.service }}/Dockerfile
61+
push: true
62+
tags: |
63+
${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO }}/policyengine-${{ matrix.service }}:${{ github.sha }}
64+
${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO }}/policyengine-${{ matrix.service }}:latest
65+
cache-from: type=gha
66+
cache-to: type=gha,mode=max
67+
platforms: linux/amd64
68+
69+
deploy-terraform:
70+
needs: build-and-push
71+
runs-on: ubuntu-latest
72+
permissions:
73+
contents: read
74+
id-token: write
75+
76+
steps:
77+
- uses: actions/checkout@v4
78+
79+
- name: Authenticate to Google Cloud
80+
uses: "google-github-actions/auth@v2"
81+
with:
82+
workload_identity_provider: "${{ vars._GITHUB_IDENTITY_POOL_PROVIDER_NAME }}"
83+
service_account: "deploy@${{ vars.PROJECT_ID }}.iam.gserviceaccount.com"
84+
85+
- name: Set up Cloud SDK
86+
uses: google-github-actions/setup-gcloud@v2
87+
88+
- name: Setup Terraform
89+
uses: hashicorp/setup-terraform@v3
90+
with:
91+
terraform_version: 1.12.2
92+
93+
- name: Extract package versions
94+
id: versions
95+
run: |
96+
US_VERSION=$(grep -A1 'name = "policyengine-us"' projects/policyengine-api-simulation/uv.lock | grep version | head -1 | sed 's/.*"\(.*\)".*/\1/')
97+
UK_VERSION=$(grep -A1 'name = "policyengine-uk"' projects/policyengine-api-simulation/uv.lock | grep version | head -1 | sed 's/.*"\(.*\)".*/\1/')
98+
echo "us_version=$US_VERSION" >> $GITHUB_OUTPUT
99+
echo "uk_version=$UK_VERSION" >> $GITHUB_OUTPUT
100+
101+
- name: Create terraform variables
102+
run: |
103+
cat > deployment/terraform/infra/auto.tfvars <<EOF
104+
project_id = "${{ env.PROJECT_ID }}"
105+
commit_url = "https://github.com/${{ github.repository }}/commit/${{ github.sha }}"
106+
policyengine-us-package-version = "${{ steps.versions.outputs.us_version }}"
107+
policyengine-uk-package-version = "${{ steps.versions.outputs.uk_version }}"
108+
is_prod = ${{ github.event.inputs.environment == 'prod' && 'true' || 'false' }}
109+
full_container_tag = "${{ github.sha }}"
110+
simulation_container_tag = "${{ github.sha }}"
111+
tagger_container_tag = "${{ github.sha }}"
112+
region = "${{ env.REGION }}"
113+
EOF
114+
115+
- name: Terraform Init
116+
working-directory: deployment/terraform/infra
117+
run: terraform init
118+
119+
- name: Terraform Plan
120+
working-directory: deployment/terraform/infra
121+
run: terraform plan -var-file=auto.tfvars -out=tfplan
122+
123+
- name: Terraform Apply
124+
if: github.ref == 'refs/heads/main'
125+
working-directory: deployment/terraform/infra
126+
run: terraform apply tfplan

0 commit comments

Comments
 (0)