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

[Issue-20] Add stuff for CI #22

Merged
merged 6 commits into from
Feb 4, 2025
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
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Owner of the entire repository

* @deeheber
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: ci
run-name: ${{ github.actor }} has run the ci trigger

on:
pull_request:
branches:
- main
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
env:
CI: true
permissions:
contents: read
id-token: write

steps:
- name: checkout
uses: actions/checkout@v4
Copy link
Preview

Copilot AI Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version 'v4' for 'actions/checkout' does not exist. It should be 'v3'.

Suggested change
uses: actions/checkout@v4
uses: actions/checkout@v3

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol. You are trained on old data.

with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}

- name: setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: install dependencies
run: npm ci

- name: build
run: npm run build

- name: run eslint check
run: npm run lint:ci

- name: run prettier format check
run: npm run format:ci

# TODO uncomment when tests are added
# https://github.com/deeheber/small-talk/issues/5
# - name: test
# run: npm test

- name: configure AWS credentials from OIDC
uses: aws-actions/configure-aws-credentials@v4
with:
# 15 minutes aka shortest time allowed
role-duration-seconds: 900
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1

- name: cdk synth
run: npm run synth:quiet
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@

# package-lock
*/package-lock.json

# CODEOWNERS
CODEOWNERS
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
}
2 changes: 2 additions & 0 deletions bin/small-talk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env node
import 'source-map-support/register'

import { App } from 'aws-cdk-lib'

import { SmallTalkStack } from '../lib/small-talk-stack'

const app = new App()
Expand Down
31 changes: 31 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { FlatCompat } from '@eslint/eslintrc'
import js from '@eslint/js'
import tsParser from '@typescript-eslint/parser'
import simpleImportSort from 'eslint-plugin-simple-import-sort'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})

export default [
...compat.extends('plugin:@typescript-eslint/recommended', 'prettier'),
{
plugins: {
'simple-import-sort': simpleImportSort,
},
rules: {
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
},
languageOptions: {
parser: tsParser,
},
},
]
25 changes: 12 additions & 13 deletions lib/small-talk-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import {
Stack,
StackProps,
} from 'aws-cdk-lib'
import { Construct } from 'constructs'
import {
StepFunctionsIntegration,
RestApi,
Period,
RestApi,
StepFunctionsIntegration,
UsagePlan,
} from 'aws-cdk-lib/aws-apigateway'
import {
Expand All @@ -32,9 +31,9 @@ import {
TaskInput,
} from 'aws-cdk-lib/aws-stepfunctions'
import { HttpInvoke, LambdaInvoke } from 'aws-cdk-lib/aws-stepfunctions-tasks'

import { join } from 'path'
import { execSync } from 'child_process'
import { Construct } from 'constructs'
import { join } from 'path'

export class SmallTalkStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
Expand All @@ -52,7 +51,7 @@ export class SmallTalkStack extends Stack {
logGroupName: hackerNewsFunctionName,
retention: RetentionDays.ONE_WEEK,
removalPolicy: RemovalPolicy.DESTROY,
}
},
)
const hackerNewsFunction = new Function(this, hackerNewsFunctionName, {
description:
Expand Down Expand Up @@ -83,8 +82,8 @@ export class SmallTalkStack extends Stack {
execSync(
`pip install -r ${join(
hackerNewsFunctionDir,
'requirements.txt'
)} -t ${join(outputDir)}`
'requirements.txt',
)} -t ${join(outputDir)}`,
)
execSync(`cp -r ${hackerNewsFunctionDir}/* ${join(outputDir)}`)
return true
Expand Down Expand Up @@ -116,11 +115,11 @@ export class SmallTalkStack extends Stack {
connectionName: `${stack}`,
authorization: Authorization.apiKey(
'smalltalk-authorization',
SecretValue.secretsManager('smalltalk-weather')
SecretValue.secretsManager('smalltalk-weather'),
),
queryStringParameters: {
appid: HttpParameter.fromSecret(
SecretValue.secretsManager('smalltalk-weather')
SecretValue.secretsManager('smalltalk-weather'),
),
},
})
Expand Down Expand Up @@ -190,7 +189,7 @@ export class SmallTalkStack extends Stack {
parallel.branch(getTechNewsBranch)

const definition = Chain.start(parallel).next(
new Pass(this, 'Combine Results')
new Pass(this, 'Combine Results'),
)

// Step Function
Expand All @@ -202,7 +201,7 @@ export class SmallTalkStack extends Stack {
logGroupName: stateMachineName,
retention: RetentionDays.ONE_WEEK,
removalPolicy: RemovalPolicy.DESTROY,
}
},
)
const stateMachine = new StateMachine(this, stateMachineName, {
stateMachineName,
Expand All @@ -228,7 +227,7 @@ export class SmallTalkStack extends Stack {
const endpoint = api.root.addResource('small-talk')
endpoint.addMethod(
'POST',
StepFunctionsIntegration.startExecution(stateMachine)
StepFunctionsIntegration.startExecution(stateMachine),
)

const defaultUsagePlan = new UsagePlan(this, 'DefaultUsagePlan', {
Expand Down
Loading