-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
68 lines (56 loc) · 1.95 KB
/
action.yaml
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
name: Deploy Golang AWS Lambda
description: This action allows users o deploy golang lambda applications on push
author: Victoria Luquet
branding:
icon: "box"
color: "green"
on:
push:
branches:
- main
env:
AWS_REGION: us-east-1 # Change to yours
ENTRY_FILE: main.go # Change to yours
FUNCTION_NAME: ${GITHUB_REPOSITORY#*/} # Change to yours
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Config AWS credentials
uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.x'
- name: Install dependencies
run: go get .
- name: Building Code
run: |
GOOS=linux GOARCH=amd64 go build -o bootstrap ${{ env.ENTRY_FILE }}
chmod +x bootstrap
zip deploy.zip bootstrap
- name: Check if lambda exists
id: lambda_status
continue-on-error: true
run: aws lambda get-function --function-name ${{ env.FUNCTION_NAME }} > /dev/null 2>&1
- name: Create Function
if: steps.lambda_status.outcome != 'success'
run: |
aws lambda create-function \
--function-name ${{ env.FUNCTION_NAME }} \
--zip-file fileb://deploy.zip \
--handler bootstrap \
--runtime provided.al2023 \
--role ${{ secrets.AWS_ROLE }} > /dev/null 2>&1
- name: Update Function
if: steps.lambda_status.outcome == 'success'
run: aws lambda update-function-code --function-name ${{ env.FUNCTION_NAME }} --zip-file fileb://deploy.zip > /dev/null 2>&1