name: CI on: push: pull_request: env: REGISTRY_IMAGE: registry.neko-piranha.ts.net/astral/gcsim DEPLOY_NAMESPACE: gcsim KUBE_API_SERVER: https://100.112.189.33:6443/ jobs: verify: runs-on: ubuntu-latest timeout-minutes: 20 steps: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v2 with: bun-version: 1.3.14 - run: bun install --frozen-lockfile - run: bun run test - run: bun run typecheck - run: bun run lint - uses: azure/setup-kubectl@v4 - run: kubectl kustomize k8s/ >/dev/null build-and-deploy: needs: verify if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main' && vars.DEPLOY_ENABLED == 'true' runs-on: ubuntu-latest timeout-minutes: 45 steps: - uses: actions/checkout@v4 - name: Build and push immutable image run: | docker build --target app --build-arg NEXT_DEPLOYMENT_ID=${{ gitea.sha }} --tag ${{ env.REGISTRY_IMAGE }}:${{ gitea.sha }} . docker push ${{ env.REGISTRY_IMAGE }}:${{ gitea.sha }} - uses: azure/setup-kubectl@v4 - name: Configure kubectl env: KUBE_CONFIG_B64: ${{ secrets.KUBE_CONFIG_B64 }} run: | set -Eeuo pipefail test -n "$KUBE_CONFIG_B64" kube_dir="$RUNNER_TEMP/gcsim-kube" mkdir -p "$kube_dir" chmod 700 "$kube_dir" export KUBECONFIG="$kube_dir/config" printf '%s' "$KUBE_CONFIG_B64" | base64 --decode >"$KUBECONFIG" chmod 600 "$KUBECONFIG" cluster_name="$(kubectl config view --minify -o jsonpath='{.clusters[0].name}')" kubectl config set-cluster "$cluster_name" --server "$KUBE_API_SERVER" --insecure-skip-tls-verify=true >/dev/null printf '%s\n' "KUBECONFIG=$KUBECONFIG" >> "${GITEA_ENV_FILE:-$GITHUB_ENV}" - name: Roll out env: REVISION: ${{ gitea.sha }} run: | set -Eeuo pipefail app_dir="$RUNNER_TEMP/gcsim-app-${REVISION:0:12}" cp -R k8s "$app_dir" kubectl apply -f k8s/namespace.yaml sed -i "s#newName: .*#newName: $REGISTRY_IMAGE#" "$app_dir/kustomization.yaml" sed -i "s/newTag: .*/newTag: $REVISION/" "$app_dir/kustomization.yaml" kubectl --namespace "$DEPLOY_NAMESPACE" apply -k "$app_dir" kubectl --namespace "$DEPLOY_NAMESPACE" patch configmap gcsim-config --type=merge --patch "{\"data\":{\"NEXT_DEPLOYMENT_ID\":\"$REVISION\"}}" kubectl --namespace "$DEPLOY_NAMESPACE" rollout status deployment/gcsim --timeout=10m