Skip to content

Commit

Permalink
Testing External PR (Github App) (#1064)
Browse files Browse the repository at this point in the history
* Initial testing setup for external prs

* updates to load priv key from base64

* attempt to setup local supabase

* fix

* more supabase testing

* fix

* update ignore

* fix

* Add inline docs

* additional testing for external-prs lib

* add CODEOWNERS
  • Loading branch information
ravenac95 authored Mar 15, 2024
1 parent e8040be commit 736f3f7
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 112 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Any changes to .github should trigger require one of the ops team to review
.github/* @opensource-observer/ops
ops/* @opensource-observer/ops
11 changes: 11 additions & 0 deletions .github/scripts/run-supabase-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -euo pipefail

cd "$1"

pnpm supabase start
export $(pnpm supabase status -o env | xargs)
echo "SUPABASE_SERVICE_KEY=$SERVICE_ROLE_KEY" >> $GITHUB_ENV
echo "SUPABASE_JWT_SECRET=$JWT_SECRET" >> $GITHUB_ENV
echo "NEXT_PUBLIC_SUPABASE_URL=$API_URL" >> $GITHUB_ENV
echo "NEXT_PUBLIC_SUPABASE_ANON_KEY=$ANON_KEY" >> $GITHUB_ENV
13 changes: 7 additions & 6 deletions .github/workflows/ci-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ env:
NEXT_PUBLIC_DOMAIN: ${{ vars.NEXT_PUBLIC_DOMAIN }}
NEXT_PUBLIC_DB_GRAPHQL_URL: ${{ vars.NEXT_PUBLIC_DB_GRAPHQL_URL }}
OSO_API_KEY: ${{ secrets.OSO_API_KEY }}
NEXT_PUBLIC_SUPABASE_URL: ${{ vars.NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
SUPABASE_SERVICE_KEY: ${{ secrets.SUPABASE_SERVICE_KEY }}
SUPABASE_JWT_SECRET: ${{ secrets.SUPABASE_JWT_SECRET }}
NEXT_PUBLIC_ALGOLIA_APPLICATION_ID: ${{ vars.NEXT_PUBLIC_ALGOLIA_APPLICATION_ID }}}
NEXT_PUBLIC_ALGOLIA_APPLICATION_ID: ${{ vars.NEXT_PUBLIC_ALGOLIA_APPLICATION_ID }}
NEXT_PUBLIC_ALGOLIA_API_KEY: ${{ secrets.NEXT_PUBLIC_ALGOLIA_API_KEY }}
NEXT_PUBLIC_ALGOLIA_INDEX: ${{ vars.NEXT_PUBLIC_ALGOLIA_INDEX }}
NEXT_PUBLIC_FEEDBACK_FARM_ID: ${{ vars.NEXT_PUBLIC_FEEDBACK_FARM_ID }}
# Indexer variables
DB_APPLICATION_NAME: oso-ci
X_GITHUB_GRAPHQL_API: ${{ vars.X_GITHUB_GRAPHQL_API }}
X_GITHUB_TOKEN: ${{ secrets.X_GITHUB_TOKEN }}
GOOGLE_PROJECT_ID: "opensource-observer"

# should not be set to a legitimate value for testing. This will use up API
Expand Down Expand Up @@ -99,6 +96,10 @@ jobs:
run: |
bash .github/scripts/create-dbt-profile.sh ${GOOGLE_APPLICATION_CREDENTIALS}
- name: Run supabase local
run: |
bash .github/scripts/run-supabase-local.sh apps/frontend
- name: Build
run: |
pnpm build
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ dbt_packages/

# Python
*.pyc

supabase/.temp/
**/supabase/.temp/
*/**/supabase/.temp/
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
--- Creates an auth hook to insert hasura custom claims into JWT tokens
--- See https://supabase.com/docs/guides/auth/auth-hooks?language=add-admin-role#hook-custom-access-token

-- This command is required for local supabase which we use on our github
-- actions. The local supabase doesn't automatically enable the plv8 extension.
create extension if not exists plv8;

create or replace function public.hasura_token_hook(event jsonb)
returns jsonb
language plv8
Expand Down
7 changes: 7 additions & 0 deletions ops/external-prs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": ["../../.eslintrc.js"],
"root": false,
"parserOptions": {
"project": ["./ops/external-prs/tsconfig.json"]
}
}
5 changes: 5 additions & 0 deletions ops/external-prs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# External PRs

A Github App that allows us to accept external PRs by enabling PR checks by an
out of band process. We need this because some of the checks require _some_ form
of authentication.
35 changes: 35 additions & 0 deletions ops/external-prs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@opensource-observer/ops-external-prs",
"version": "0.0.1",
"description": "External PRs github app for OSO",
"author": "Kariba Labs",
"license": "Apache-2.0",
"private": true,
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/opensource-observer/oso.git"
},
"engines": {
"node": ">=20"
},
"scripts": {
"build": "tsc",
"lint": "tsc --noEmit && pnpm lint:eslint && pnpm lint:prettier",
"lint:eslint": "eslint --ignore-path ../../.gitignore --max-warnings 0 .",
"lint:prettier": "prettier --ignore-path ../../.gitignore --log-level warn --check **/*.{js,jsx,ts,tsx,sol,md,json}"
},
"keywords": [],
"devDependencies": {
"@types/node": "^20.11.17",
"dotenv": "^16.4.1",
"ts-node": "^10.9.1",
"typescript": "^5.3.3"
},
"dependencies": {
"octokit": "^3.1.0",
"yaml": "^2.3.1"
}
}
52 changes: 52 additions & 0 deletions ops/external-prs/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { App } from "octokit";
import dotenv from "dotenv";

dotenv.config();

async function main() {
const APP_TO_CHECK = process.env.APP_TO_CHECK;
const SHA_TO_CHECK = process.env.SHA_TO_CHECK;

const buf = Buffer.from(process.env.APP_PRIVATE_KEY!, "base64"); // Ta-da

const app = new App({
appId: process.env.APP_ID!,
privateKey: buf.toString("utf-8"),
});

const { data } = await app.octokit.request("/app");
console.log(`Authenticated as ${data.name}`);

for await (const { installation } of app.eachInstallation.iterator()) {
for await (const { octokit, repository } of app.eachRepository.iterator({
installationId: installation.id,
})) {
console.log(repository.name);
if (repository.name !== APP_TO_CHECK) {
continue;
}
const resp = await octokit.request(
"POST /repos/{owner}/{repo}/check-runs",
{
owner: repository.owner.login,
repo: repository.name,
data: {
name: "test-deployment2",
head_sha: SHA_TO_CHECK,
status: "completed",
conclusion: "success",
output: {
title: "test-deployment2",
summary: "This is some summary",
},
},
},
);
console.log(resp);
}
}
}

main().catch((e) => {
console.log(e);
});
21 changes: 21 additions & 0 deletions ops/external-prs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"outDir": "dist",
"target": "ES6",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"strictNullChecks": true,
"strictPropertyInitialization": false,
},
"exclude": ["node_modules"],
"include": ["./src/*.ts", "./src/**/*.ts", "./test"],
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"scripts": {
"build": "turbo run build --concurrency=100%",
"build:cloudquery": "turbo run build --filter=@opensource-observer/cloudquery-*",
"build:ops": "turbo run build --filter=@opensource-observer/ops-*",
"build:docs": "turbo run build --filter=@opensource-observer/docs",
"build:frontend": "turbo run build --filter=@opensource-observer/frontend",
"build:hasura": "turbo run build --filter=@opensource-observer/hasura",
Expand Down
Loading

0 comments on commit 736f3f7

Please sign in to comment.