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

Add feature branch deploy + feature branch init jobs #11

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .github/workflows/feature-branch-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
# Export RELEASE_NAME as an output
echo "::set-output name=RELEASE_NAME::$RELEASE_NAME"

# Get feature branch table name
export DATABASE_NAME=${RELEASE_NAME}

yarn build
env:
PR_NUMBER: ${{ steps.pr.outputs.pull_request_number }}
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/feature-branch-init.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Feature Branch Init Workflow (Called on PR Open)
on:
workflow_call:
inputs:
# Mandatory inputs
githubRef:
required: true
type: string
gitSha:
required: true
type: string
secrets:
AWS_ACCOUNT_ID:
required: true
GH_AWS_ACCESS_KEY_ID:
required: true
GH_AWS_SECRET_ACCESS_KEY:
required: true
jobs:
feature-branch-init:
runs-on: ubuntu-latest
if: startsWith(${{ inputs.githubRef }}, 'refs/heads/feat/') == true
steps:
- uses: actions/checkout@v2
- name: Get Pull Request Metadata
id: pr
run: |-
echo "::set-output name=pull_request_number::$(gh pr view --json number -q .number || echo "")"
echo "::set-output name=pull_request_closed::$(gh pr view --json closed -q .closed || echo "")"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Feature Branch Table (on AWS RDS) with PR number
if: (steps.pr.outputs.pull_request_number) && (steps.pr.outputs.pull_request_closed == 'false')
run: |-
# Get repo name (by removing owner/organization)
export RELEASE_NAME=${REPOSITORY#*/}-pr-${{ steps.pr.outputs.pull_request_number }}
# Create table
aws rds-data execute-statement \
--resource-arn arn:aws:rds:us-east-1:${AWS_ACCOUNT_ID}:cluster:$RELEASE_NAME \
--secret-arn arn:aws:secretsmanager:us-east-1:${AWS_ACCOUNT_ID}:secret:$RELEASE_NAME \
--sql "CREATE DATABASE $RELEASE_NAME"
env:
DATABASE_NAME: staging
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
10 changes: 9 additions & 1 deletion .github/workflows/feature-branch-nuke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ jobs:
GIT_SHA: ${{ inputs.gitSha }}
REPOSITORY: ${{ github.repository }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
- name: Nuke
- name: Nuke Database Feature Branch Database (on AWS RDS) with PR number.
run: |-
export RELEASE_NAME=${{ steps.synth.outputs.RELEASE_NAME }}
# Create table
aws rds-data execute-statement \
--resource-arn arn:aws:rds:us-east-1:${AWS_ACCOUNT_ID}:cluster:$RELEASE_NAME \
--secret-arn arn:aws:secretsmanager:us-east-1:${AWS_ACCOUNT_ID}:secret:$RELEASE_NAME \
--sql "DROP DATABASE $RELEASE_NAME"
- name: Nuke Deployment
run: |-
aws eks --region us-east-1 update-kubeconfig --name production --role-arn arn:aws:iam::${AWS_ACCOUNT_ID}:role/kubectl
# Get repo name from synth step
Expand Down