Skip to content

Commit

Permalink
chore: Update golang.yml workflow to copy golang-build-deploy.sh from…
Browse files Browse the repository at this point in the history
… the correct directory
  • Loading branch information
tanjilbhuiyan committed May 16, 2024
1 parent a836d4a commit 4ea38c8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
52 changes: 36 additions & 16 deletions .github/scripts/golang-build-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,31 @@ while read line; do
# Remove starting and ending square brackets using parameter expansion
line="${line#\[}" # Remove starting square bracket
line="${line%\]}" # Remove ending square bracket

printf '%s\n' "$line"
IFS=',' read -ra parts <<< "$line"

# Iterate over the split parts and echo each one
for part in "${parts[@]}"; do
# Remove any leading or trailing spaces
directory_path=$(echo "$part" | tr -d '[:space:]' | sed 's/"//g' | sed 's#^github/##;s#/main\.go$##')
printf '%s\n' "$directory_path"

# Extract the path without the filename and the initial 'lambda/' part
zip_name=$(dirname "$directory_path" | sed 's|^lambda/||')

# Determine if the last segment is 'src' or not
last_segment=$(basename "$zip_name")

if [ "$last_segment" = "src" ]; then
# Remove the last segment if it is 'src'
zip_name =$(dirname "$zip_name")
fi

# Replace '/' with '_'
result=$(echo "$zip_name" | tr '/' '_')

printf '%s\n' "$result"


# Check if the directory exists
if [ -d "$directory_path" ]; then
Expand All @@ -26,23 +44,25 @@ while read line; do
# Run the build command in the directory
echo "Building in directory $directory_path:"
# Run the build command in the directory and capture the output
# build_output=$(GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o bootstrap 2>&1)
build_output=$(GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o bootstrap 2>&1)
# zip_name=$(echo "$directory_path" | awk -F'/' '{print $2}')

# # Check the exit status of the build command
# if [ $? -eq 0 ]; then
# echo "Build in directory $directory_path succeeded:"
# echo "$build_output"
# # Zip the bootstrap file
# zip -q "$zip_name.zip" bootstrap
# echo "Bootstrap file zipped as bootstrap.zip"
# echo "Uploading to AWS S3"
# aws s3 cp "$zip_name.zip" "s3://$S3_BUCKET_NAME/$zip_name.zip"

# else
# echo "Build in directory $directory_path failed:"
# echo "$build_output"
# fi
# Check the exit status of the build command
if [ $? -eq 0 ]; then
echo "Build in directory $directory_path succeeded:"
echo "$build_output"
# Zip the bootstrap file
zip -q "$result.zip" bootstrap
ls -la
pwd
echo "Bootstrap file zipped as bootstrap.zip"
echo "Uploading to AWS S3"
aws s3 cp "$result.zip" "s3://$S3_BUCKET_NAME/$result.zip"

else
echo "Build in directory $directory_path failed:"
echo "$build_output"
fi

# Return to the original directory
cd "$current_dir"
Expand Down
2 changes: 1 addition & 1 deletion lambda/github-lambda-test-1/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ func handler(ctx context.Context) (string, error) {

func main() {
lambda.Start(handler)
}
}
2 changes: 1 addition & 1 deletion lambda/github-lambda-test-2/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ func handler(ctx context.Context) (string, error) {

func main() {
lambda.Start(handler)
}
}
2 changes: 1 addition & 1 deletion lambda/payments/gateways/stripe/confirm/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ func handler(ctx context.Context) (string, error) {

func main() {
lambda.Start(handler)
}
}

0 comments on commit 4ea38c8

Please sign in to comment.