Skip to content

Commit

Permalink
feat: stepci
Browse files Browse the repository at this point in the history
  • Loading branch information
chronark committed Sep 3, 2023
1 parent 9b982e6 commit a3cf73f
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 7 deletions.
52 changes: 49 additions & 3 deletions .github/workflows/deploy-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ jobs:
tags: ${{ env.TAG }}
build-args: VERSION=${{env.VERSION}}

deploy:
name: Deploy Agent
deploy_preview:
name: Deploy Preview
runs-on: ubuntu-latest
needs:
- build
Expand Down Expand Up @@ -93,9 +93,55 @@ jobs:
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

integration_test_preview:
name: Integration Test
runs-on: ubuntu-latest
needs:
- deploy_preview
steps:
- uses: actions/checkout@v3
- name: Step CI Action
uses: stepci/stepci@main
with:
workflow: "apps/agent/e2e/workflow.yml"
envs: "baseUrl=${{ secrets.PREVIEW_BASE_URL }} apiId=${{secrets.PREVIEW_API_ID}}"
secrets: "rootKey=${{ secrets.PREVIEW_ROOT_KEY }}"


deploy_production:
name: Deploy Production
runs-on: ubuntu-latest
if: "!github.event.release.prerelease"
needs:
- build
- deploy_preview
- integration_test_preview
steps:
- uses: actions/checkout@v3

- name: Get tag
run: echo "TAG=ghcr.io/${{ github.repository }}:$(git describe --tags --always)" > $GITHUB_ENV

- name: Login to image repository
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Install flyctl
uses: superfly/flyctl-actions/setup-flyctl@master

- name: Download image
run: docker pull ${{env.TAG}}



- name: Deploy prod
if: "!github.event.release.prerelease"
run: flyctl -c="./fly.prod.toml" deploy --image=${{ env.TAG }} --strategy=canary
working-directory: apps/agent
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}



110 changes: 110 additions & 0 deletions apps/agent/e2e/workflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"version": "1.1",
"name": "Status Check",
"secrets": {
"rootKey": "from-cli"
},
"env": {
"baseUrl": "https://api.unkey.dev",
"apiId": "api_J7MXWBmycyMoTALYkts6Nz"
},
"config": {
"loadTest": {
"phases": [
{
"duration": 10,
"arrivalRate": 1
},
{
"duration": 60,
"arrivalRate": 10
}
]
}
},
"tests": {
"example": {
"steps": [
{
"name": "Create Key",
"http": {
"url": "${{env.baseUrl}}/v1/keys",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer ${{secrets.rootKey}}"
},
"json": {
"apiId": "${{env.apiId}}"
},
"check": {
"status": "/^20/",
"jsonpath": {
"$.keyId": [{ "isString": true }],
"$.key": [{ "isString": true }]
}
},
"captures": {
"key": {
"jsonpath": "$.key"
},
"keyId": {
"jsonpath": "$.keyId"
}
}
}
},
{
"name": "Verify Key",
"http": {
"url": "${{env.baseUrl}}/v1/keys/verify",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"json": {
"key": "${{captures.key}}"
},
"check": {
"status": "/^20/",
"jsonpath": {
"$.valid": true
}
}
}
},
{
"name": "Random Invalid Key",
"http": {
"url": "${{env.baseUrl}}/v1/keys/verify",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"json": {
"key": "${{ | naughtystring }}"
},
"check": {
"status": 200,
"jsonpath": {
"$.valid": false
},
"performance": {
"firstByte": [
{
"lte": 100
}
],
"total": [
{
"lte": 200
}
]
}
}
}
}
]
}
}
}
9 changes: 6 additions & 3 deletions apps/web/app/(authenticated)/(app)/app/keys/[keyId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default async function KeyPage(props: { params: { keyId: string } }) {
apiId: api.id,
keyId: key.id,
}),
getTotalUsage({ keyId: key.id }).then(res => res.data.at(0)?.totalUsage ?? 0),
getTotalUsage({ keyId: key.id }).then((res) => res.data.at(0)?.totalUsage ?? 0),
getLatestVerifications({ keyId: key.id }),
getLastUsed({ keyId: key.id }).then((res) => res.data.at(0)?.lastUsed ?? 0),
]);
Expand All @@ -62,7 +62,7 @@ export default async function KeyPage(props: { params: { keyId: string } }) {
y: value,
}));

const fmt = new Intl.NumberFormat("en-US", { notation: "compact" }).format
const fmt = new Intl.NumberFormat("en-US", { notation: "compact" }).format;
const usage30Days = usage.data.reduce((acc, { usage }) => acc + usage, 0);
return (
<div className="flex flex-col gap-8">
Expand All @@ -73,7 +73,10 @@ export default async function KeyPage(props: { params: { keyId: string } }) {
label="Expires"
value={key.expires ? ms(key.expires.getTime() - Date.now()) : <Minus />}
/>
<Stat label="Remaining" value={key.remainingRequests ? fmt(key.remainingRequests) : <Minus />} />
<Stat
label="Remaining"
value={key.remainingRequests ? fmt(key.remainingRequests) : <Minus />}
/>
<Stat
label="LastUsed"
value={lastUsed ? `${ms(Date.now() - lastUsed)} ago` : <Minus />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client";
import { Button } from "@/components/ui/button";
import React, { useState } from "react";
import { experimental_useFormStatus as useFormStatus } from "react-dom";

import { Card, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import { useToast } from "@/components/ui/use-toast";
Expand Down

0 comments on commit a3cf73f

Please sign in to comment.