Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Claude-GP authored Jan 25, 2024
0 parents commit 68407bd
Show file tree
Hide file tree
Showing 25 changed files with 1,990 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Release

on:
release:
types: [published]

env:
UPLOAD_LAMBDA: false

jobs:
test:
name: Test lambda function
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: yarn install

- name: Test
run: yarn test

build-and-upload:
name: Build GitHub action and AWS lambda function
needs: test
if: "false" # To be removed
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: yarn install

- name: Build lambda distribution
run: yarn dist

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Upload new build to AWS lambda
run: |
aws lambda update-function-code --function-name "$FUNCTION_ARN" --zip-file "fileb://$(pwd)/out/lambda.zip"
env:
FUNCTION_ARN: ${{ secrets.LAMBDA_FUNCTION_ARN }}

test-new-version:
name: Test uploaded lambda
needs: build-and-upload
if: "false" # To be removed
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: yarn install

- name: Integration tests
run: yarn test
env:
LAMBDA_URL: ${{ secrets.LAMBDA_URL }}
61 changes: 61 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Tests

on:
push:
branches:
- main
pull_request:

jobs:
terraform:
name: Validate Terraform code
runs-on: ubuntu-latest

env:
TERRAFORM_VERSION: 0.13.5
TERRAFORM_WORK_DIR: ./terraform

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}

- name: Terraform Init
working-directory: ${{ env.TERRAFORM_WORK_DIR }}
run: terraform init

- name: Terraform Validate
working-directory: ${{ env.TERRAFORM_WORK_DIR }}
run: terraform validate
env:
AWS_DEFAULT_REGION: ca-central-1 # https://github.com/hashicorp/terraform/issues/21408#issuecomment-495746582

test:
name: Test lambda function
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: yarn install

- name: Test
run: yarn test

build:
name: Build lambda function
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: yarn install

- name: Build lambda distribution
run: yarn dist
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
/dist
/out
.terraform
yarn-error.log
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"arrowParens": "avoid",
"printWidth": 120,
"singleQuote": false,
"quoteProps": "consistent"
}
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", "hashicorp.terraform", "annsk.alignment"]
}
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha Current File",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": ["--no-timeouts", "--colors", "${file}", "--require", "ts-node/register"],
"console": "integratedTerminal",
"sourceMaps": true,
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "Debug File",
"program": "${workspaceFolder}/node_modules/.bin/ts-node",
"args": ["${file}"]
}
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.trimAutoWhitespace": true
}
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Contributing

## Testing

```bash
yarn install
yarn test
```

## Publish a new release

- Bump [`package.json`](./package.json) version (ie.: 1.0.0)
- Create a new release (ie.: v1.0.0)
- A GitHub workflow will automatically run, build and upload the new code to AWS Lambda.

## Note about `aws-sdk`

`aws-sdk` is placed as a devDependency in the projet in order to build smaller zip file for the distribution.

From the [Building Lambda functions with Node.js](https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html) documentation:

> Your code runs in an environment that includes the AWS SDK for JavaScript, with credentials from an AWS Identity and Access Management (IAM) role that you manage.
Loading

0 comments on commit 68407bd

Please sign in to comment.