Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract pull request feature #17

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: 18.x
- run: npm ci
Expand Down
45 changes: 45 additions & 0 deletions 3a
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build

on:
push:
branches:
- main
pull_request:
branches:
- main

defaults:
run:
working-directory: transcript-orchestration

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
- run: npm ci
- run: npm run audit
- run: npm test
env:
AWS_REGION: "eu-west-1"
- name: Coveralls Parallel
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: run-node-18
parallel: true
path-to-lcov: transcript-orchestration/coverage/lcov.info
finish:
needs: build
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
path-to-lcov: transcript-orchestration/coverage/lcov.info
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@ This project uses:
- AWS Lambda for:
- Merging the Whisper and Transcribe results
- Substituting commonly 'misheard' words/proper nouns
- Creating a GitHub Pull Request against the podcast's website repository with the generated transcript (this is an optional step)
- ...and Step Functions to orchestrate the whole process!

This project consists of a few components, each with their own CloudFormation Stack:

1. 👂 [whisper-image](./whisper-image), for creating an ECR container image repository where we store the SageMaker container to run the Whisper model
2. 🪣 [data-resources](./data-resources) for shared data stores, namely an S3 Bucket
3. 🧠 [sagemaker-resources](./sagemaker-resources) for the SageMaker model and IAM role
4. 🎙 [transcript-orchestration](./transcript-orchestration), for orchestration, custom transcript processing and creating the transcript pull request
4. 🎙 [transcript-orchestration](./transcript-orchestration), for orchestration and transcript merging

This project uses AWS SAM with nested stacks to deploy all but the first of these components. That first component is special, since we need to create the container image respository with [Amazon ECR](https://aws.amazon.com/ecr/) where we can push our custom Whisper container image. That makes the image available to be loaded by the SageMaker resources we can then create.

## Prerequisites

You will need the following build tooling installed.
- Node.js 16.x and NPM 8.x
- Node.js 18.x and NPM 8.x
- Docker, or other tooling that can build a container image from a `Dockerfile` and push it to a repository.
- [AWS SAM](https://aws.amazon.com/serverless/sam/), used to build and deploy most of the application
- The [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
- esbuild
- SLIC Watch: By default, the target AWS account should have the [SLIC Watch](https://github.com/fourTheorem/slic-watch) SAR Application installed. It can be installed by going to _[this page](https://serverlessrepo.aws.amazon.com/applications/eu-west-1/949339270388/slic-watch-app) in the AWS Console. SLIC Watch is used to create alarms and dashboards for our transcription application. If you want to skip this option, just remove the single line referring to the `SlicWatch-v2` macro from the relevant template, [transcript-orchestration/template.yaml](https://github.com/fourTheorem/podwhisperer/blob/cc73c5d4d52dc01f2249a032a9e2186012e24201/transcript-orchestration/template.yaml#L4).

By default, the target AWS account should have the [SLIC Watch](https://github.com/fourTheorem/slic-watch) SAR Application installed. It can be installed by going to _[this page](https://serverlessrepo.aws.amazon.com/applications/eu-west-1/949339270388/slic-watch-app) in the AWS Console. SLIC Watch is used to create alarms and dashboards for our transcription application. If you want to skip this option, just remove the single line referring to the `SlicWatch-v2` macro from the relevant template, [transcript-orchestration/template.yaml](https://github.com/fourTheorem/podwhisperer/blob/cc73c5d4d52dc01f2249a032a9e2186012e24201/transcript-orchestration/template.yaml#L4).

## Getting Started

Expand Down Expand Up @@ -96,11 +95,6 @@ aws s3 cp sample-audio/sample1.mp3 s3://pod-transcription-${AWS_ACCOUNT_ID}-${AW

That S3 object upload will create an EventBridge event to trigger the transcription Step Function. You can watch its progress in the Step Functions Console.

## Configuration

By default, the transcription workflow will attempt to create a Pull Request against a static website's GitHub repository. The GitHub repository is configured in the Pull Request Lambda Function's [environment variables](https://github.com/fourTheorem/podwhisperer/blob/cc73c5d4d52dc01f2249a032a9e2186012e24201/transcript-orchestration/template.yaml#L230). You can modify this, and the [pull request creation code](https://github.com/fourTheorem/podwhisperer/blob/main/transcript-orchestration/functions/pull-request/app.ts) if you want to have PRs with new transcripts created as part of the workflow.
If you want to turn this feature off altogether, you can simply change the `createPR` default value in the Step Function's inputs from `true` to `false` [here](https://github.com/fourTheorem/podwhisperer/blob/cc73c5d4d52dc01f2249a032a9e2186012e24201/transcript-orchestration/statemachine/transcription-step-function.asl.json#L12).

### Step function architecture

To have a better feeling for what the process looks like you can check out the following picture for a visualization of the Step Function definition:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { writeFile } from 'node:fs/promises'
import { resolve } from 'node:path'

import { mockClient } from 'aws-sdk-client-mock'
import { sdkStreamMixin } from '@aws-sdk/util-stream-node'
import { sdkStreamMixin } from '@smithy/util-stream'
import { S3Client, PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3'
import { mockedContext } from '../../../mock-utils/lambda-context'
import { test, expect, vi } from 'vitest'
process.env.BUCKET_NAME = 'test-bucket'

import * as app from '../../app'
import * as transcode from '../../transcode'

Expand Down
2 changes: 1 addition & 1 deletion transcript-orchestration/functions/lib/envs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface Environment {
* This eliminates the need to check the existence of each environment variable where it is used.
*/
const envProxy: Environment = new Proxy({}, {
get(target: Record<string, string>, name: string): string {
get(_target: Record<string, string>, name: string): string {
const value = process.env[name]
if (!value) {
throw new Error(`Environment variable ${name} is not set`)
Expand Down
108 changes: 0 additions & 108 deletions transcript-orchestration/functions/pull-request/app.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { test, expect } from 'vitest'
import { handleEvent, S3KeysEvent } from '../../app'

process.env.BUCKET_NAME = 'test-bucket'

const testState: { options?: S3KeysEvent } = {}

test('constructs keys from audio input key', async (t) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { Readable } from 'node:stream'
import { resolve } from 'node:path'

import { mockClient } from 'aws-sdk-client-mock'
import { sdkStreamMixin } from '@aws-sdk/util-stream-node'
import { sdkStreamMixin } from '@smithy/util-stream'
import { S3Client, PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3'
import { test, assert } from 'vitest'

import { VocabularySubstitutions } from '../../vocabulary'
import { MergedTranscript } from '../../types'

process.env.BUCKET_NAME = 'test-bucket'
import { handleEvent } from '../../app'

const mockS3 = mockClient(S3Client)
Expand Down
Loading