Skip to content

Commit b5c4647

Browse files
committed
edit workflow with function name
1 parent acca9ab commit b5c4647

2 files changed

Lines changed: 75 additions & 79 deletions

File tree

.github/workflows/test-and-deploy.yml

Lines changed: 67 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,97 +3,95 @@ name: Test & Deploy Grading Script to AWS Lambda
33
on:
44
push:
55
branches:
6-
- master
6+
- master
77
workflow_dispatch:
88

99
jobs:
10-
1110
test:
1211
name: Test
1312
runs-on: ubuntu-latest
14-
13+
1514
strategy:
1615
fail-fast: false
1716
matrix:
18-
python-version: [ 3.8 ]
19-
17+
python-version: [3.8]
18+
2019
defaults:
2120
run:
2221
working-directory: app/
2322

2423
steps:
25-
- name: Checkout
26-
uses: actions/checkout@v2
27-
28-
- name: Set up Python ${{ matrix.python-version }}
29-
uses: actions/setup-python@v2
30-
with:
31-
python-version: ${{ matrix.python-version }}
32-
33-
- name: Install dependencies
34-
run: |
35-
python -m pip install --upgrade pip
36-
python -m pip install flake8 pytest
37-
python -m pip install -r tools/tools_requirements.txt
38-
python -m pip install -r requirements.txt
39-
40-
- name: Lint with flake8
41-
run: |
42-
# stop the build if there are Python syntax errors or undefined names
43-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
44-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
45-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
46-
47-
- name: Test Handler functions
48-
run: |
49-
pytest -v tests/handling.py::TestHandlerFunction
50-
- name: Test JSON schema
51-
run: |
52-
pytest -v tests/validation.py::TestSchemaValidation
53-
- name: Test Grading functions
54-
run: |
55-
pytest -v tests/grading.py::TestGradingFunction
56-
57-
24+
- name: Checkout
25+
uses: actions/checkout@v2
26+
27+
- name: Set up Python ${{ matrix.python-version }}
28+
uses: actions/setup-python@v2
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
32+
- name: Install dependencies
33+
run: |
34+
python -m pip install --upgrade pip
35+
python -m pip install flake8 pytest
36+
python -m pip install -r tools/tools_requirements.txt
37+
python -m pip install -r requirements.txt
38+
39+
- name: Lint with flake8
40+
run: |
41+
# stop the build if there are Python syntax errors or undefined names
42+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
43+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
44+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
45+
46+
- name: Test Handler functions
47+
run: |
48+
pytest -v tests/handling.py::TestHandlerFunction
49+
- name: Test JSON schema
50+
run: |
51+
pytest -v tests/validation.py::TestSchemaValidation
52+
- name: Test Grading functions
53+
run: |
54+
pytest -v tests/grading.py::TestGradingFunction
55+
5856
deploy:
5957
name: Deploy
6058
needs: test
6159
runs-on: ubuntu-latest
6260
environment: production
61+
env:
62+
ECR_REPOSITORY: is-exact-equal
63+
LAMBDA_FUNCTION_NAME: isExactEqual
6364

6465
steps:
65-
- name: Checkout
66-
uses: actions/checkout@v2
66+
- name: Checkout
67+
uses: actions/checkout@v2
6768

68-
- name: Configure AWS credentials
69-
uses: aws-actions/configure-aws-credentials@v1
70-
with:
71-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
72-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
73-
aws-region: eu-west-2
69+
- name: Configure AWS credentials
70+
uses: aws-actions/configure-aws-credentials@v1
71+
with:
72+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
73+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
74+
aws-region: eu-west-2
7475

75-
- name: Login to Amazon ECR
76-
id: login-ecr
77-
uses: aws-actions/amazon-ecr-login@v1
76+
- name: Login to Amazon ECR
77+
id: login-ecr
78+
uses: aws-actions/amazon-ecr-login@v1
7879

79-
- name: Build, tag, and push image to Amazon ECR
80-
id: build-image
81-
env:
82-
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
83-
ECR_REPOSITORY: test-boilerplate-question-type
84-
IMAGE_TAG: latest
85-
run: |
86-
# Build docker image from algorithm, schema and requirements
87-
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG app/
88-
# Push image to ECR
89-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
90-
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
80+
- name: Build, tag, and push image to Amazon ECR
81+
id: build-image
82+
env:
83+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
84+
IMAGE_TAG: latest
85+
run: |
86+
# Build docker image from algorithm, schema and requirements
87+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG app/
88+
# Push image to ECR
89+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
90+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
9191
92-
- name: Update lambda function image
93-
env:
94-
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
95-
ECR_REPOSITORY: test-boilerplate-question-type
96-
LAMBDA_FUNCTION_NAME: test_question_type_boilerplate
97-
IMAGE_TAG: latest
98-
run: |
99-
aws lambda update-function-code --function-name $LAMBDA_FUNCTION_NAME --image-uri $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
92+
- name: Update lambda function image
93+
env:
94+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
95+
IMAGE_TAG: latest
96+
run: |
97+
aws lambda update-function-code --function-name $LAMBDA_FUNCTION_NAME --image-uri $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

app/algorithm.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@ def grading_function(body: dict) -> dict:
22
"""
33
Function used to grade a student response.
44
---
5-
The handler function passes only one argument to grading_function(),
5+
The handler function passes only one argument to grading_function(),
66
which is a dictionary of the structure of the API request body
77
deserialised from JSON.
88
9-
The output of this function is what is returned as the API response
10-
and therefore must be JSON-encodable. This is also subject to
9+
The output of this function is what is returned as the API response
10+
and therefore must be JSON-encodable. This is also subject to
1111
standard response specifications.
1212
13-
Any standard python library may be used, as well as any package
13+
Any standard python library may be used, as well as any package
1414
available on pip (provided it is added to requirements.txt).
1515
16-
The way you wish to structure you code (all in this function, or
17-
split into many) is entirely up to you. All that matters are the
18-
return types and that grading_function() is the main function used
16+
The way you wish to structure you code (all in this function, or
17+
split into many) is entirely up to you. All that matters are the
18+
return types and that grading_function() is the main function used
1919
to output the grading response.
2020
"""
2121

22-
return {
23-
"is_correct": True
24-
}
22+
return {"is_correct": True, "received_body": body}

0 commit comments

Comments
 (0)