Skip to content

Commit c5e8073

Browse files
authored
[Issue-20] Add stuff for CI (#22)
* Add stuff for CI * Fix eslint * Fix prettier lint * Edit GH action workflow file for ci * Do not pin @types/node * Add CODEOWNERS
1 parent b4725fb commit c5e8073

10 files changed

+1353
-33
lines changed

.github/CODEOWNERS

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Owner of the entire repository
2+
3+
* @deeheber

.github/workflows/ci.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: ci
2+
run-name: ${{ github.actor }} has run the ci trigger
3+
4+
on:
5+
pull_request:
6+
branches:
7+
- main
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
env:
15+
CI: true
16+
permissions:
17+
contents: read
18+
id-token: write
19+
20+
steps:
21+
- name: checkout
22+
uses: actions/checkout@v4
23+
with:
24+
ref: ${{ github.event.pull_request.head.ref }}
25+
repository: ${{ github.event.pull_request.head.repo.full_name }}
26+
27+
- name: setup Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version-file: '.nvmrc'
31+
32+
- name: install dependencies
33+
run: npm ci
34+
35+
- name: build
36+
run: npm run build
37+
38+
- name: run eslint check
39+
run: npm run lint:ci
40+
41+
- name: run prettier format check
42+
run: npm run format:ci
43+
44+
# TODO uncomment when tests are added
45+
# https://github.com/deeheber/small-talk/issues/5
46+
# - name: test
47+
# run: npm test
48+
49+
- name: configure AWS credentials from OIDC
50+
uses: aws-actions/configure-aws-credentials@v4
51+
with:
52+
# 15 minutes aka shortest time allowed
53+
role-duration-seconds: 900
54+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
55+
aws-region: us-east-1
56+
57+
- name: cdk synth
58+
run: npm run synth:quiet

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212

1313
# package-lock
1414
*/package-lock.json
15+
16+
# CODEOWNERS
17+
CODEOWNERS

.vscode/extensions.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
3+
}

.vscode/settings.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"[typescript]": {
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"editor.formatOnSave": true
5+
}
6+
}

bin/small-talk.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env node
22
import 'source-map-support/register'
3+
34
import { App } from 'aws-cdk-lib'
5+
46
import { SmallTalkStack } from '../lib/small-talk-stack'
57

68
const app = new App()

eslint.config.mjs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import path from 'node:path'
2+
import { fileURLToPath } from 'node:url'
3+
4+
import { FlatCompat } from '@eslint/eslintrc'
5+
import js from '@eslint/js'
6+
import tsParser from '@typescript-eslint/parser'
7+
import simpleImportSort from 'eslint-plugin-simple-import-sort'
8+
9+
const __filename = fileURLToPath(import.meta.url)
10+
const __dirname = path.dirname(__filename)
11+
const compat = new FlatCompat({
12+
baseDirectory: __dirname,
13+
recommendedConfig: js.configs.recommended,
14+
allConfig: js.configs.all,
15+
})
16+
17+
export default [
18+
...compat.extends('plugin:@typescript-eslint/recommended', 'prettier'),
19+
{
20+
plugins: {
21+
'simple-import-sort': simpleImportSort,
22+
},
23+
rules: {
24+
'simple-import-sort/imports': 'error',
25+
'simple-import-sort/exports': 'error',
26+
},
27+
languageOptions: {
28+
parser: tsParser,
29+
},
30+
},
31+
]

lib/small-talk-stack.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import {
66
Stack,
77
StackProps,
88
} from 'aws-cdk-lib'
9-
import { Construct } from 'constructs'
109
import {
11-
StepFunctionsIntegration,
12-
RestApi,
1310
Period,
11+
RestApi,
12+
StepFunctionsIntegration,
1413
UsagePlan,
1514
} from 'aws-cdk-lib/aws-apigateway'
1615
import {
@@ -32,9 +31,9 @@ import {
3231
TaskInput,
3332
} from 'aws-cdk-lib/aws-stepfunctions'
3433
import { HttpInvoke, LambdaInvoke } from 'aws-cdk-lib/aws-stepfunctions-tasks'
35-
36-
import { join } from 'path'
3734
import { execSync } from 'child_process'
35+
import { Construct } from 'constructs'
36+
import { join } from 'path'
3837

3938
export class SmallTalkStack extends Stack {
4039
constructor(scope: Construct, id: string, props?: StackProps) {
@@ -52,7 +51,7 @@ export class SmallTalkStack extends Stack {
5251
logGroupName: hackerNewsFunctionName,
5352
retention: RetentionDays.ONE_WEEK,
5453
removalPolicy: RemovalPolicy.DESTROY,
55-
}
54+
},
5655
)
5756
const hackerNewsFunction = new Function(this, hackerNewsFunctionName, {
5857
description:
@@ -83,8 +82,8 @@ export class SmallTalkStack extends Stack {
8382
execSync(
8483
`pip install -r ${join(
8584
hackerNewsFunctionDir,
86-
'requirements.txt'
87-
)} -t ${join(outputDir)}`
85+
'requirements.txt',
86+
)} -t ${join(outputDir)}`,
8887
)
8988
execSync(`cp -r ${hackerNewsFunctionDir}/* ${join(outputDir)}`)
9089
return true
@@ -116,11 +115,11 @@ export class SmallTalkStack extends Stack {
116115
connectionName: `${stack}`,
117116
authorization: Authorization.apiKey(
118117
'smalltalk-authorization',
119-
SecretValue.secretsManager('smalltalk-weather')
118+
SecretValue.secretsManager('smalltalk-weather'),
120119
),
121120
queryStringParameters: {
122121
appid: HttpParameter.fromSecret(
123-
SecretValue.secretsManager('smalltalk-weather')
122+
SecretValue.secretsManager('smalltalk-weather'),
124123
),
125124
},
126125
})
@@ -190,7 +189,7 @@ export class SmallTalkStack extends Stack {
190189
parallel.branch(getTechNewsBranch)
191190

192191
const definition = Chain.start(parallel).next(
193-
new Pass(this, 'Combine Results')
192+
new Pass(this, 'Combine Results'),
194193
)
195194

196195
// Step Function
@@ -202,7 +201,7 @@ export class SmallTalkStack extends Stack {
202201
logGroupName: stateMachineName,
203202
retention: RetentionDays.ONE_WEEK,
204203
removalPolicy: RemovalPolicy.DESTROY,
205-
}
204+
},
206205
)
207206
const stateMachine = new StateMachine(this, stateMachineName, {
208207
stateMachineName,
@@ -228,7 +227,7 @@ export class SmallTalkStack extends Stack {
228227
const endpoint = api.root.addResource('small-talk')
229228
endpoint.addMethod(
230229
'POST',
231-
StepFunctionsIntegration.startExecution(stateMachine)
230+
StepFunctionsIntegration.startExecution(stateMachine),
232231
)
233232

234233
const defaultUsagePlan = new UsagePlan(this, 'DefaultUsagePlan', {

0 commit comments

Comments
 (0)