-
Notifications
You must be signed in to change notification settings - Fork 1.5k
133 lines (125 loc) · 4.29 KB
/
ali.yaml
File metadata and controls
133 lines (125 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Deploy my Lambda Function
# trigger on all push events to main branch
on:
push:
branches:
- main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install linting libraries
run: |
cd function
pip install flake8
- name: Lint with flake8
run: |
# Select identifies which errors should cause the job to fail
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# The exit zero flag will show errors as warnings and not fail the run
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
build:
runs-on: ubuntu-latest
needs: lint
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install libraries
run: |
cd function
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt -t .; fi
- name: Create zip bundle
run: |
cd function
zip -r ../${{ github.sha }}.zip .
- name: Archive artifact
uses: actions/upload-artifact@v2
with:
name: zipped-bundle
path: ${{ github.sha }}.zip
upload:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: zipped-bundle
- 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: us-east-1
- name: Upload to S3
run: aws s3 cp ${{ github.sha }}.zip s3://<YOUR BUCKET NAME HERE>/${{ github.repository }}/${{ github.sha }}.zip
nonprod:
runs-on: ubuntu-latest
needs: upload
strategy:
matrix:
input: ["Hello", "Hi"]
steps:
- 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: us-east-1
- name: Create test function
run: |
aws lambda create-function --function-name ali-${{ matrix.input }} \
--code S3Bucket=aliahmad-git-test,S3Key=${{ github.repository }}/${{ github.sha }}.zip \
--handler lambda_function.lambda_handler --runtime python3.8 \
--role arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/<YOUR ROLE NAME HERE>
- name: Invoke test function
run: |
aws lambda invoke --function-name test-function-${{ matrix.input }} \
--payload $(echo "{\"input\": \"${{ matrix.input }}\"}" | base64) \
--output json out
if grep -q "Error" out; then
exit1
fi
- name: Destroy test function
if: ${{ always() }}
run: |
aws lambda delete-function --function-name test-function-${{ matrix.input }}
deploy:
runs-on: ubuntu-latest
needs: upload
steps:
- 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: us-east-1
- name: Update function code
run: |
aws lambda update-function-code \
--function-name <YOUR FUNCTION NAME HERE> \
--s3-bucket aliahmad-git-test \
--s3-key ${{ github.repository }}/${{ github.sha }}.zip \
--publish
docs:
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Deploy docs
uses: mhausenblas/mkdocs-deploy-gh-pages@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CONFIG_FILE: mkdocs.yaml