Skip to content

Commit

Permalink
[IT-3013] Migrate to GH Actions (#15)
Browse files Browse the repository at this point in the history
Migrate to the github actions from the lambda template.
  • Loading branch information
jesusaurus authored Sep 25, 2023
1 parent 08dc36f commit 8a80d5a
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 47 deletions.
26 changes: 26 additions & 0 deletions .github/actions/sam-build/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: sam-build

runs:
# This creates a composite action to be used as a step in a job
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
using: "composite"
steps:
# Convert Pipfile.lock to requirements.txt for sam
- uses: actions/setup-python@v4
with:
python-version: 3.8
- run: pip install -U pipenv
shell: bash

# This needs to be in the 'CodeUri' directory
- run: pipenv requirements > requirements.txt
shell: bash

# Install aws-sam-cli
- uses: aws-actions/setup-sam@v2
with:
use-installer: true

# Use a lambda-like docker container to build the lambda artifact
- run: sam build --use-container
shell: bash
42 changes: 42 additions & 0 deletions .github/workflows/post-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: post-merge

on:
# Run on merges to master or tag pushes
push:
branches: [ 'master' ]
tags: [ '*' ]

concurrency:
group: ${{ github.workflow }}

jobs:
lambda-test:
uses: "./.github/workflows/test.yaml"

package-and-publish:
runs-on: ubuntu-latest
needs: lambda-test
permissions:
id-token: write
env:
BOOTSTRAP_BUCKET: bootstrap-awss3cloudformationbucket-19qromfd235z9
ESSENTIALS_BUCKET: essentials-awss3lambdaartifactsbucket-x29ftznj6pqw
steps:
- uses: actions/checkout@v3

# Install sam-cli and run "sam build"
- uses: ./.github/actions/sam-build

# authenticate with AWS via OIDC
- uses: aws-actions/configure-aws-credentials@v3
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::745159704268:role/sagebase-github-oidc-lambda-template-deploy-sageit
role-session-name: GHA-${{ github.event.repository.name }}-${{ github.run_id }} # Must not exceed 64 chars
role-duration-seconds: 900

# upload the lambda artifact to s3 and generate a cloudformation template referencing it
- run: sam package --template-file .aws-sam/build/template.yaml --s3-bucket $ESSENTIALS_BUCKET --s3-prefix ${{ github.event.repository.name }}/${{ github.ref_name }} --output-template-file .aws-sam/build/${{ github.event.repository.name }}.yaml

# upload the generated cloudformation template to s3
- run: aws s3 cp .aws-sam/build/${{ github.event.repository.name }}.yaml s3://$BOOTSTRAP_BUCKET/${{ github.event.repository.name }}/${{ github.ref_name }}/
9 changes: 9 additions & 0 deletions .github/workflows/pre-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: pre-merge

on:
# Run on open pull requests
pull_request:

jobs:
lambda-test:
uses: "./.github/workflows/test.yaml"
36 changes: 36 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: lambda-test

on:
# This is a dispatched workflow to be called as a job in other workflows
# https://docs.github.com/en/actions/using-workflows/reusing-workflows#creating-a-reusable-workflow
workflow_call:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
- uses: pre-commit/[email protected]

pytest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
- run: pip install -U pipenv
- run: pipenv install --dev
- run: pipenv run python3 -m pytest tests/ -vv

sam-build-and-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/sam-build
- run: sam validate --lint --template .aws-sam/build/template.yaml
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@ dmypy.json

# SAM
.aws-sam/

# generated dynamically from Pipfile
requirements.txt
44 changes: 0 additions & 44 deletions .travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

0 comments on commit 8a80d5a

Please sign in to comment.