Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #4

Merged
merged 12 commits into from
May 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 68 additions & 48 deletions .github/workflows/calibration.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
name: Test Lambda Function Locally and Upload Artifacts

on: [pull_request]

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch: # For on demand runs
schedule:
- cron: 0 0 * * * # Scheduled run every day at midnight

jobs:
test-and-upload:
permissions:
Expand All @@ -19,7 +28,18 @@ jobs:
cd sdc_aws_processing_lambda/lambda_function
BRANCH_URL="git+https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git@${{ github.event.pull_request.head.ref }}"
echo "Branch URL: $BRANCH_URL"
sed -i "s|hermes_eea @ git+https://github.com/HERMES-SOC/hermes_eea.git|hermes_eea @ $BRANCH_URL|" requirements.txt
# Create a temporary requirements.txt file with hermes_core at the top
# echo "$BRANCH_URL" >> requirements.txt
# Define the Dockerfile path
DOCKERFILE="Dockerfile"

# Define the line to insert
LINE_TO_INSERT='RUN pip install hermes_core@git+https://github.com/alrobbertz/hermes_core.git@113-multiple-timeseries'

# Insert the line after the 'RUN pip install -r requirements.txt' line
sed -i '/RUN pip install -r requirements.txt/a\'"$LINE_TO_INSERT" "$DOCKERFILE"
cat requirements.txt
cat Dockerfile
docker build -t processing_function:latest . --network host

- name: Run Lambda Docker Container
Expand All @@ -31,54 +51,54 @@ jobs:
- name: Wait for Container to Initialize
run: sleep 5

# - name: Test Lambda Function with curl
# id: test-lambda
# run: |
# cd ../sdc_aws_processing_lambda/
# # Run curl and write the HTTP status code to a variable
# HTTP_STATUS=$(curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d @lambda_function/tests/test_data/test_eea_event.json)
# echo "HTTP Status: $HTTP_STATUS"
- name: Test Lambda Function with curl
id: test-lambda
run: |
cd ../sdc_aws_processing_lambda/
# Run curl and write the HTTP status code to a variable
HTTP_STATUS=$(curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d @lambda_function/tests/test_data/test_eea_event.json)
echo "HTTP Status: $HTTP_STATUS"

# # Grep the HTTP status code from the curl output for 200 (success)
# STATUS_CODE=$(echo $HTTP_STATUS | grep -oP '200')
# echo "Status Code: $STATUS_CODE"
# Grep the HTTP status code from the curl output for 200 (success)
STATUS_CODE=$(echo $HTTP_STATUS | grep -oP '200')
echo "Status Code: $STATUS_CODE"

# # If the HTTP status code is 200, then the test is successful
# if [ "$STATUS_CODE" == "200" ]; then
# echo "Success: HTTP status is 200"
# echo "test_success=true" >> $GITHUB_OUTPUT
# exit 0 # Exit with success
# else
# echo "Error or unexpected HTTP status: $HTTP_STATUS"
# echo "test_success=false" >> $GITHUB_OUTPUT
# exit 1 # Exit with failure
# fi
# If the HTTP status code is 200, then the test is successful
if [ "$STATUS_CODE" == "200" ]; then
echo "Success: HTTP status is 200"
echo "test_success=true" >> $GITHUB_OUTPUT
exit 0 # Exit with success
else
echo "Error or unexpected HTTP status: $HTTP_STATUS"
echo "test_success=false" >> $GITHUB_OUTPUT
exit 1 # Exit with failure
fi

# - name: Copy Processed Files from Container
# if: steps.test-lambda.outputs.test_success == 'true'
# run: |
# container_id=$(docker ps -qf "ancestor=processing_function:latest")
# # Create a directory for processed files
# mkdir processed_files
# # Copy the files from the container to the host
# docker cp $container_id:/test_data/. processed_files/
- name: Copy Processed Files from Container
if: steps.test-lambda.outputs.test_success == 'true'
run: |
container_id=$(docker ps -qf "ancestor=processing_function:latest")
# Create a directory for processed files
mkdir processed_files
# Copy the files from the container to the host
docker cp $container_id:/test_data/. processed_files/

# - name: Upload Processed Files as Artifact
# id: artifact-upload-step
# if: steps.test-lambda.outputs.test_success == 'true'
# uses: actions/upload-artifact@v4
# with:
# name: processed-files
# path: processed_files/
- name: Upload Processed Files as Artifact
id: artifact-upload-step
if: steps.test-lambda.outputs.test_success == 'true'
uses: actions/upload-artifact@v4
with:
name: processed-files
path: processed_files/

# - name: Echo Artifact URL
# if: steps.test-lambda.outputs.test_success == 'true'
# run: echo "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}"
- name: Echo Artifact URL
if: steps.test-lambda.outputs.test_success == 'true'
run: echo "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}"

# - name: Comment PR
# if: steps.test-lambda.outputs.test_success == 'true'
# uses: thollander/actions-comment-pull-request@v2
# # Only comment if triggered by a pull request target event
# with:
# message: |
# The processed files are available as an artifact: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}
- name: Comment PR
if: steps.test-lambda.outputs.test_success == 'true'
uses: thollander/actions-comment-pull-request@v2
# Only comment if triggered by a pull request target event
with:
message: |
The processed EEA test files are available as an artifact: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}
Loading