-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from theapexlab/project-setup
Project setup
- Loading branch information
Showing
20 changed files
with
1,157 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: 2 | ||
|
||
mergeable: | ||
- when: pull_request.* | ||
name: "Description check" | ||
validate: | ||
- do: description | ||
no_empty: | ||
enabled: true | ||
message: Description matter and should not be empty. Provide detail with **what** was changed, **why** it was changed, and **how** it was changed. | ||
|
||
- when: pull_request.*, pull_request_review.* | ||
name: "Title check" | ||
validate: | ||
- do: title | ||
no_empty: | ||
enabled: true | ||
message: Title should not be empty. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: PR checks | ||
|
||
on: pull_request | ||
|
||
jobs: | ||
lint-build-and-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_STAGING }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_STAGING }} | ||
aws-region: eu-central-1 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: "18" | ||
|
||
- name: Install Dependencies and Lint | ||
run: | | ||
yarn | ||
yarn lint | ||
- name: Build | ||
run: yarn build --stage pr | ||
|
||
- name: Test | ||
run: yarn test:ci | ||
|
||
- name: SIB | ||
run: yarn sib --pipeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Staging release | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
env: | ||
stage: staging | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_STAGING }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_STAGING }} | ||
aws-region: eu-central-1 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: "18" | ||
|
||
- name: Install dependencies | ||
run: yarn | ||
|
||
- name: Set secrets | ||
run: | | ||
npx sst secrets set SLACK_LOG_LEVEL "${{ secrets.SLACK_LOG_LEVEL_STAGING }}" --stage "${{ env.stage }}" | ||
npx sst secrets set SLACK_BOT_TOKEN "${{ secrets.SLACK_BOT_TOKEN_STAGING }}" --stage "${{ env.stage }}" | ||
npx sst secrets set SLACK_SIGNING_SECRET "${{ secrets.SLACK_SIGNING_SECRET_STAGING }}" --stage "${{ env.stage }}" | ||
npx sst secrets set CORE_SLACK_CHANNEL_ID "${{ secrets.CORE_SLACK_CHANNEL_ID_STAGING }}" --stage "${{ env.stage }}" | ||
npx sst secrets set RANDOM_SLACK_CHANNEL_ID "${{ secrets.RANDOM_SLACK_CHANNEL_ID_STAGING }}" --stage "${{ env.stage }}" | ||
- name: Deploy stack | ||
run: yarn deploy --stage "${{ env.stage }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { sendQueueMessage } from "@/services/sqs/sendQueueMessage"; | ||
|
||
export const handler = async () => { | ||
try { | ||
const queueUrl = process.env.processTriggerJobQueueUrl; | ||
if (!queueUrl) { | ||
throw new Error("No queue url"); | ||
} | ||
|
||
await sendQueueMessage(queueUrl, {}); | ||
|
||
return { | ||
statusCode: 200, | ||
}; | ||
} catch (error) { | ||
console.error(`Error handling trigger jobs: ${error as string}`); | ||
return { | ||
statusCode: 500, | ||
}; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { SQSHandler } from "aws-lambda"; | ||
import { Config } from "sst/node/config"; | ||
|
||
import { sendSlackMessage } from "@/services/slack/sendSlackMessage"; | ||
|
||
export const handler: SQSHandler = async () => { | ||
try { | ||
await sendSlackMessage( | ||
Config.CORE_SLACK_CHANNEL_ID, | ||
"Hello from Birthday bot!", | ||
); | ||
} catch (error) { | ||
console.error(`Error processing trigger jobs: ${error as string}`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { LogLevel } from "@slack/bolt"; | ||
import { App } from "@slack/bolt"; | ||
import { Config } from "sst/node/config"; | ||
|
||
export const createSlackApp = () => { | ||
const token = Config.SLACK_BOT_TOKEN; | ||
const signingSecret = Config.SLACK_SIGNING_SECRET; | ||
const logLevel = Config.SLACK_LOG_LEVEL as LogLevel; | ||
|
||
if (!token || !signingSecret || !logLevel) { | ||
throw new Error("Missing Slack config"); | ||
} | ||
|
||
const app = new App({ | ||
signingSecret, | ||
token, | ||
logLevel, | ||
}); | ||
|
||
return app; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createSlackApp } from "./createSlackApp"; | ||
|
||
export const getSlackChannelUsers = async (channelId: string) => { | ||
const app = createSlackApp(); | ||
|
||
const { members } = await app.client.conversations.members({ | ||
channel: channelId, | ||
}); | ||
|
||
if (!members) { | ||
throw new Error("Error while fetching channel members"); | ||
} | ||
|
||
return members; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createSlackApp } from "./createSlackApp"; | ||
|
||
export const sendSlackMessage = async (target: string, text: string) => { | ||
const app = createSlackApp(); | ||
|
||
await app.client.chat.postMessage({ | ||
channel: target, | ||
text, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { SendMessageCommand } from "@aws-sdk/client-sqs"; | ||
|
||
import { sqsClient } from "./sqsClient"; | ||
|
||
export const sendQueueMessage = async (queueUrl: string, body: object) => { | ||
const message = new SendMessageCommand({ | ||
QueueUrl: queueUrl, | ||
MessageBody: JSON.stringify(body), | ||
}); | ||
|
||
await sqsClient.send(message); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { SQSClient } from "@aws-sdk/client-sqs"; | ||
|
||
export const sqsClient = new SQSClient(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
import "../.sst/types/index"; | ||
import "../../.sst/types/index"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Config, type StackContext } from "sst/constructs"; | ||
|
||
export function ConfigStack({ stack }: StackContext) { | ||
const SLACK_LOG_LEVEL = new Config.Secret(stack, "SLACK_LOG_LEVEL"); | ||
const SLACK_BOT_TOKEN = new Config.Secret(stack, "SLACK_BOT_TOKEN"); | ||
const SLACK_SIGNING_SECRET = new Config.Secret(stack, "SLACK_SIGNING_SECRET"); | ||
const CORE_SLACK_CHANNEL_ID = new Config.Secret( | ||
stack, | ||
"CORE_SLACK_CHANNEL_ID", | ||
); | ||
const RANDOM_SLACK_CHANNEL_ID = new Config.Secret( | ||
stack, | ||
"RANDOM_SLACK_CHANNEL_ID", | ||
); | ||
|
||
return [ | ||
SLACK_LOG_LEVEL, | ||
SLACK_BOT_TOKEN, | ||
SLACK_SIGNING_SECRET, | ||
CORE_SLACK_CHANNEL_ID, | ||
RANDOM_SLACK_CHANNEL_ID, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { StackContext } from "sst/constructs"; | ||
import { Cron, use } from "sst/constructs"; | ||
|
||
import { MyStack } from "./MyStack"; | ||
|
||
export function CronStack({ stack }: StackContext) { | ||
const { stage } = stack; | ||
const isDev = stage !== "production"; | ||
const { processTriggerJob } = use(MyStack); | ||
|
||
const triggerBirthdayJob = { | ||
function: { | ||
handler: "packages/functions/cron/index.handler", | ||
bind: [processTriggerJob], | ||
environment: { | ||
processTriggerJobQueueUrl: processTriggerJob.queueUrl, | ||
isDev: isDev.toString(), | ||
}, | ||
}, | ||
}; | ||
|
||
new Cron(stack, "Birthday-dev-trigger", { | ||
schedule: `rate(1 day)`, | ||
job: triggerBirthdayJob, | ||
enabled: isDev, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
import type { StackContext } from "sst/constructs"; | ||
import { Api } from "sst/constructs"; | ||
import { Queue, use } from "sst/constructs"; | ||
|
||
export function MyStack({ stack }: StackContext): void { | ||
const api = new Api(stack, "api", { | ||
defaults: { | ||
function: {}, | ||
}, | ||
routes: { | ||
"GET /healthcheck": "packages/functions/lambdas/healthcheck.handler", | ||
import { ConfigStack } from "./ConfigStack"; | ||
|
||
export function MyStack({ stack }: StackContext) { | ||
const secrets = use(ConfigStack); | ||
|
||
const processTriggerJob = new Queue(stack, "process-trigger-job", { | ||
consumer: { | ||
function: { | ||
handler: "packages/functions/queues/process-cron-job-queue.handler", | ||
timeout: 10, | ||
bind: secrets, | ||
}, | ||
}, | ||
}); | ||
|
||
stack.addOutputs({ | ||
ApiEndpoint: api.url, | ||
}); | ||
return { | ||
processTriggerJob, | ||
}; | ||
} |
Oops, something went wrong.