Skip to content

Commit

Permalink
feat: add swift-lift-fare-calculation workflow and initial implementa…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
LokoMoloko98 committed Jan 19, 2025
1 parent 7e30fa1 commit 2ec2d68
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 1 deletion.
84 changes: 84 additions & 0 deletions .github/workflows/swift-lift-fare-calculation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: lokos-blog-crud CI-CD

on:
push:
branches:
- main
paths:
- 'swift-lift-fare-calculation/**' # Run only if changes are in swift-lift-fare-calculation directory

jobs:
release:
runs-on: ubuntu-latest

steps:
# 1. Checkout the code
- name: Checkout Code
uses: actions/checkout@v3

# 2. Read current version from versions.json
- name: Read Current Version
id: read_version
run: |
VERSION=$(jq -r '."swift-lift-fare-calculation"' versions.json)
echo "Current version: $VERSION"
echo "VERSION=${VERSION}" >> $GITHUB_ENV
# 3. Increment the patch version
- name: Increment Patch Version
id: increment_version
run: |
OLD_VERSION=${{ env.VERSION }}
IFS='.' read -r MAJOR MINOR PATCH <<< "$OLD_VERSION"
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
echo "New version: $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
# 4. Create a zip file for the directory
- name: Zip Directory
run: |
ZIP_NAME=swift-lift-fare-calculation-${{ env.NEW_VERSION }}.zip
cd swift-lift-fare-calculation
zip -r ../$ZIP_NAME ./*
echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV
# 5.1 Authenticate to AWS
- name: Authenticate to AWS
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
# 5.2 Back up release version to s3
- name: Upload File
run: |
aws s3 cp ${{ env.ZIP_NAME }} s3://mea-munera-lambda/swift-lift-fare-calculation/
# 6. Release the lambda function code
# - name: AWS CLI v2
# uses: imehedi/actions-awscli-v2@latest
# with:
# args: "lambda update-function-code \
# --function-name arn:aws:<provide your function ARN Here> \
# --zip-file fileb://code.zip"
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: "us-east-1"

# 7. Update the versions.json file in the root
- name: Update Versions JSON
run: |
jq --arg version "${{ env.NEW_VERSION }}" '."swift-lift-fare-calculation" = $version' versions.json > versions.json.tmp
mv versions.json.tmp versions.json
cat versions.json
# 8. Commit and Push the updated versions.json
- name: Commit Versions JSON
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add versions.json
git commit -m "Update swift-lift-fare-calculation version to ${{ env.NEW_VERSION }}"
git push
Empty file.
60 changes: 60 additions & 0 deletions swift-lift-fare-calculation/swift-lift-fare-calculation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

import json
import boto3
from boto3.dynamodb.conditions import Key

client = boto3.client('dynamodb')
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table('Lokos-Blok-data')
tableName = 'Lokos-Blok-data'


def lambda_handler(event, context):
print(event)
body = {}
statusCode = 200
headers = {
"Content-Type": "application/json"
}

try:
if event['routeKey'] == "DELETE /blogs/{BlogId}":
table.delete_item(KeyConditionExpression=Key('BlogId').eq(event['pathParameters']['BlogId']))
body = 'Deleted item ' + event['pathParameters']['BlogId']
# elif event['routeKey'] == "GET /blogs/{BlogId}":
# body = table.query(KeyConditionExpression=Key('BlogId').eq(event['pathParameters']['BlogId']))
# body = body["Item"]
# responseBody = [{'BlogId': body['BlogId'], 'BlogTitle': body['BlogTitle'], 'PublishedDate': body['PublishedDate']}]
# body = responseBody
# elif event['routeKey'] == "GET /items":
# body = table.scan()
# body = body["Items"]
# print("ITEMS----")
# print(body)
# responseBody = []
# for items in body:
# responseItems = [
# {'price': float(items['price']), 'BlogId': items['BlogId'], 'name': items['name']}]
# responseBody.append(responseItems)
# body = responseBody
# elif event['routeKey'] == "PUT /items":
# requestJSON = json.loads(event['body'])
# table.put_item(
# Item={
# 'BlogId': requestJSON['BlogId'],
# 'price': Decimal(str(requestJSON['price'])),
# 'name': requestJSON['name']
# })
# body = 'Put item ' + requestJSON['BlogId']
except KeyError:
statusCode = 400
body = 'Unsupported route: ' + event['routeKey']
body = json.dumps(body)
res = {
"statusCode": statusCode,
"headers": {
"Content-Type": "application/json"
},
"body": body
}
return res
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"lokos-blog-crud": "1.0.0",
"lift-club-lambda": "1.0.0"
"lift-club-lambda": "1.0.0",
"swift-lift-fare-calculation":"1.0.0"
}

0 comments on commit 2ec2d68

Please sign in to comment.