|
| 1 | +name: ci |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - "**" |
| 9 | + |
| 10 | +env: |
| 11 | + TERRAFORM_VERSION: "1.4.2" |
| 12 | + |
| 13 | +jobs: |
| 14 | + frontend: |
| 15 | + runs-on: ubuntu-22.04 |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + id-token: write |
| 19 | + steps: |
| 20 | + - name: Clone repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Install Deno |
| 24 | + uses: denoland/setup-deno@v1 |
| 25 | + with: |
| 26 | + deno-version: 1.x |
| 27 | + |
| 28 | + - name: Check license headers |
| 29 | + run: deno task lint:license |
| 30 | + |
| 31 | + - name: Format |
| 32 | + run: deno fmt --check |
| 33 | + working-directory: frontend |
| 34 | + |
| 35 | + - name: Lint |
| 36 | + run: deno lint |
| 37 | + working-directory: frontend |
| 38 | + |
| 39 | + - name: Typecheck |
| 40 | + run: deno check main.ts |
| 41 | + working-directory: frontend |
| 42 | + |
| 43 | + - name: Build Fresh |
| 44 | + run: deno task build |
| 45 | + working-directory: frontend |
| 46 | + |
| 47 | + test: |
| 48 | + runs-on: ubuntu-22.04 |
| 49 | + steps: |
| 50 | + - name: Clone repository |
| 51 | + uses: actions/checkout@v4 |
| 52 | + |
| 53 | + - name: Install Rust |
| 54 | + uses: dsherret/rust-toolchain-file@v1 |
| 55 | + |
| 56 | + - uses: Swatinem/rust-cache@v2 |
| 57 | + |
| 58 | + - name: Setup postgres for tests |
| 59 | + run: docker-compose up -d |
| 60 | + |
| 61 | + - name: Build |
| 62 | + run: cargo build --all-targets --tests |
| 63 | + working-directory: api |
| 64 | + |
| 65 | + - name: Test |
| 66 | + run: cargo test |
| 67 | + working-directory: api |
| 68 | + |
| 69 | + - uses: taiki-e/cache-cargo-install-action@v1 |
| 70 | + with: |
| 71 | + |
| 72 | + |
| 73 | + # If it's not up to date, run `cargo sqlx prepare` locally and commit the |
| 74 | + # changes. You may have to run `cargo install sqlx-cli` first. |
| 75 | + - name: Check sqlx metadata is up to date |
| 76 | + run: | |
| 77 | + cargo sqlx migrate run |
| 78 | + cargo sqlx prepare --check |
| 79 | + working-directory: api |
| 80 | + env: |
| 81 | + DATABASE_URL: postgres://user:password@localhost/registry |
| 82 | + |
| 83 | + - name: Lint |
| 84 | + run: cargo clippy --all-targets --all-features -- -D warnings |
| 85 | + working-directory: api |
| 86 | + |
| 87 | + - name: Format |
| 88 | + run: cargo fmt --all -- --check |
| 89 | + working-directory: api |
| 90 | + |
| 91 | + docker-images: |
| 92 | + runs-on: ubuntu-22.04 |
| 93 | + permissions: |
| 94 | + contents: read |
| 95 | + id-token: write |
| 96 | + env: |
| 97 | + API_IMAGE_ID_BASE: us-central1-docker.pkg.dev/deno-registry3-infra/registry/api |
| 98 | + FRONTEND_IMAGE_ID_BASE: us-central1-docker.pkg.dev/deno-registry3-infra/registry/frontend |
| 99 | + outputs: |
| 100 | + api_image_id: ${{ steps.api_image_id.outputs.image_id }} |
| 101 | + frontend_image_id: ${{ steps.frontend_image_id.outputs.image_id }} |
| 102 | + steps: |
| 103 | + - name: Clone repository |
| 104 | + uses: actions/checkout@v4 |
| 105 | + |
| 106 | + - name: Authenticate with GCP |
| 107 | + id: gcp_auth |
| 108 | + uses: google-github-actions/auth@v2 |
| 109 | + with: |
| 110 | + project_id: deno-registry3-infra |
| 111 | + token_format: access_token |
| 112 | + workload_identity_provider: projects/289615555261/locations/global/workloadIdentityPools/github-actions/providers/github-actions |
| 113 | + service_account: [email protected] |
| 114 | + |
| 115 | + - uses: docker/login-action@v3 |
| 116 | + with: |
| 117 | + registry: us-central1-docker.pkg.dev |
| 118 | + username: oauth2accesstoken |
| 119 | + password: ${{ steps.gcp_auth.outputs.access_token }} |
| 120 | + |
| 121 | + - name: Set up docker buildx |
| 122 | + uses: docker/setup-buildx-action@v3 |
| 123 | + |
| 124 | + - name: Copy Cargo.lock |
| 125 | + run: cp Cargo.lock api/Cargo.lock |
| 126 | + |
| 127 | + - name: Build and push api docker image |
| 128 | + uses: docker/build-push-action@v5 |
| 129 | + id: api_push |
| 130 | + with: |
| 131 | + context: api |
| 132 | + push: true |
| 133 | + tags: ${{ env.API_IMAGE_ID_BASE }}:${{ github.sha }} |
| 134 | + cache-from: type=gha,scope=docker-api |
| 135 | + cache-to: type=gha,mode=max,scope=docker-api |
| 136 | + |
| 137 | + - name: Build and push frontend docker image |
| 138 | + uses: docker/build-push-action@v5 |
| 139 | + id: frontend_push |
| 140 | + with: |
| 141 | + context: frontend |
| 142 | + push: true |
| 143 | + tags: ${{ env.FRONTEND_IMAGE_ID_BASE }}:${{ github.sha }} |
| 144 | + cache-from: type=gha,scope=docker-frontend |
| 145 | + cache-to: type=gha,mode=max,scope=docker-frontend |
| 146 | + |
| 147 | + - name: Set api_image_id output |
| 148 | + id: api_image_id |
| 149 | + run: echo "image_id=${{ env.API_IMAGE_ID_BASE }}@${{ steps.api_push.outputs.imageid }}" >> $GITHUB_OUTPUT |
| 150 | + |
| 151 | + - name: Set frontend_image_id output |
| 152 | + id: frontend_image_id |
| 153 | + run: echo "image_id=${{ env.FRONTEND_IMAGE_ID_BASE }}@${{ steps.frontend_push.outputs.imageid }}" >> $GITHUB_OUTPUT |
| 154 | + |
| 155 | + staging: |
| 156 | + runs-on: ubuntu-22.04 |
| 157 | + needs: docker-images |
| 158 | + environment: |
| 159 | + name: staging |
| 160 | + url: https://deno-registry-staging.net |
| 161 | + permissions: |
| 162 | + contents: read |
| 163 | + id-token: write |
| 164 | + steps: |
| 165 | + - name: Clone repository |
| 166 | + uses: actions/checkout@v4 |
| 167 | + |
| 168 | + - name: Install terraform |
| 169 | + uses: hashicorp/setup-terraform@v3 |
| 170 | + with: |
| 171 | + terraform_version: ${{ env.TERRAFORM_VERSION }} |
| 172 | + |
| 173 | + - name: Authenticate with GCP |
| 174 | + id: gcp_auth |
| 175 | + uses: google-github-actions/auth@v2 |
| 176 | + with: |
| 177 | + project_id: deno-registry3-staging |
| 178 | + workload_identity_provider: projects/1067420915575/locations/global/workloadIdentityPools/github-actions/providers/github-actions |
| 179 | + service_account: [email protected] |
| 180 | + |
| 181 | + - name: terraform plan |
| 182 | + run: | |
| 183 | + make staging-init |
| 184 | + terraform version |
| 185 | + make staging-plan |
| 186 | + env: |
| 187 | + API_IMAGE_ID: ${{ needs.docker-images.outputs.api_image_id }} |
| 188 | + FRONTEND_IMAGE_ID: ${{ needs.docker-images.outputs.frontend_image_id }} |
| 189 | + GH_CLIENT_ID: ${{ secrets.GH_CLIENT_ID }} |
| 190 | + GH_CLIENT_SECRET: ${{ secrets.GH_CLIENT_SECRET }} |
| 191 | + POSTMARK_TOKEN: ${{ secrets.POSTMARK_TOKEN }} |
| 192 | + ORAMA_PRIVATE_API_KEY: ${{ secrets.ORAMA_PRIVATE_API_KEY }} |
| 193 | + ORAMA_INDEX_ID: ${{ secrets.ORAMA_INDEX_ID }} |
| 194 | + |
| 195 | + - name: terraform apply |
| 196 | + if: github.event.pull_request.draft == false |
| 197 | + run: make staging-apply |
| 198 | + |
| 199 | + prod: |
| 200 | + if: github.ref == 'refs/heads/main' |
| 201 | + runs-on: ubuntu-22.04 |
| 202 | + needs: docker-images |
| 203 | + environment: |
| 204 | + name: prod |
| 205 | + url: https://jsr.io |
| 206 | + permissions: |
| 207 | + contents: read |
| 208 | + id-token: write |
| 209 | + steps: |
| 210 | + - name: Clone repository |
| 211 | + uses: actions/checkout@v4 |
| 212 | + |
| 213 | + - name: Install terraform |
| 214 | + uses: hashicorp/setup-terraform@v3 |
| 215 | + with: |
| 216 | + terraform_version: ${{ env.TERRAFORM_VERSION }} |
| 217 | + |
| 218 | + - name: Authenticate with GCP |
| 219 | + id: gcp_auth |
| 220 | + uses: google-github-actions/auth@v2 |
| 221 | + with: |
| 222 | + project_id: deno-registry3-prod |
| 223 | + workload_identity_provider: projects/614736529383/locations/global/workloadIdentityPools/github-actions/providers/github-actions |
| 224 | + service_account: [email protected] |
| 225 | + |
| 226 | + - name: terraform plan |
| 227 | + run: | |
| 228 | + make prod-init |
| 229 | + terraform version |
| 230 | + make prod-plan |
| 231 | + env: |
| 232 | + API_IMAGE_ID: ${{ needs.docker-images.outputs.api_image_id }} |
| 233 | + FRONTEND_IMAGE_ID: ${{ needs.docker-images.outputs.frontend_image_id }} |
| 234 | + GH_CLIENT_ID: ${{ secrets.GH_CLIENT_ID }} |
| 235 | + GH_CLIENT_SECRET: ${{ secrets.GH_CLIENT_SECRET }} |
| 236 | + POSTMARK_TOKEN: ${{ secrets.POSTMARK_TOKEN }} |
| 237 | + ORAMA_PRIVATE_API_KEY: ${{ secrets.ORAMA_PRIVATE_API_KEY }} |
| 238 | + ORAMA_INDEX_ID: ${{ secrets.ORAMA_INDEX_ID }} |
| 239 | + |
| 240 | + - name: terraform apply |
| 241 | + run: make prod-apply |
0 commit comments