Skip to content

Commit

Permalink
Merge pull request #20 from dukeofgaming/dev
Browse files Browse the repository at this point in the history
Merge dev into main
  • Loading branch information
dukeofgaming authored Sep 12, 2024
2 parents b66abe6 + 4ba944e commit dcff143
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
45 changes: 38 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.set_env.outputs.environment }}
environment_json: ${{ steps.set_env.outputs.environment_json }}
branch_promoting_to: ${{ steps.set_env.outputs.branch_promoting_to }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -32,19 +34,42 @@ jobs:
../../.github/branch-environment-map.json \
)
# Check if environment name exists for this branch, otherwise fail the pipeline
if [ -z "$environment_name" ]; then
echo "Environment not found for this branch" >> $GITHUB_STEP_SUMMARY
exit 1
fi
environment_json="[\"$environment_name\"]"
# Set the output
echo "::set-output name=environment::[\"$environment_name\"]"
echo "environment=$environment_name" >> $GITHUB_OUTPUT
echo "environment_json=$environment_json" >> $GITHUB_OUTPUT
echo "Getting promotion path..."
chmod +x get-branch-promotions.sh
branch_promoting_to=$(
./get-branch-promotions.sh \
../../.github/branch-promotion-map.json \
)
echo "branch_promoting_to=$branch_promoting_to" >> $GITHUB_OUTPUT
- name: Print environment output
run: echo "${{ steps.set_env.outputs.environment }}"
run: |
echo "Environment: ${{ steps.set_env.outputs.environment }}" >> $GITHUB_STEP_SUMMARY
echo "Environment JSON: ${{ steps.set_env.outputs.environment_json }}" >> $GITHUB_STEP_SUMMARY
echo "Branch promoting to: ${{ steps.set_env.outputs.branch_promoting_to }}" >> $GITHUB_STEP_SUMMARY
BuildAndPush:
# Debugging
name: Build and Push Docker Image
needs: PrepareEnvironment
needs:
- PrepareEnvironment
runs-on: ubuntu-latest
strategy:
matrix:
environment: ${{fromJson(needs.PrepareEnvironment.outputs.environment)}}
environment: ${{fromJson(needs.PrepareEnvironment.outputs.environment_json)}}
environment: ${{ matrix.environment }}
steps:
- name: Checkout
Expand All @@ -57,6 +82,12 @@ jobs:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ecr_url: ${{ vars.ECR_URL }}

- name: Print environment output
run: |
echo "Environment: ${{ needs.PrepareEnvironment.outputs.environment }}"
echo "Environment JSON: ${{ needs.PrepareEnvironment.outputs.environment_json }}"
echo "Branch promoting to: ${{ needs.PrepareEnvironment.outputs.branch_promoting_to }}"
RunTerraform:
name: Run Terraform
Expand All @@ -66,7 +97,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
environment: ${{fromJson(needs.PrepareEnvironment.outputs.environment)}}
environment: ${{fromJson(needs.PrepareEnvironment.outputs.environment_json)}}
environment: ${{ matrix.environment }}
steps:
- name: Checkout
Expand Down Expand Up @@ -120,15 +151,15 @@ jobs:
PromotionPR:
if: ${{ needs.PrepareEnvironment.outputs.environment != '["prod"]' }}
if: ${{ needs.PrepareEnvironment.outputs.branch_promoting_to != '' }}
name: Create promotion PR
needs:
- PrepareEnvironment
- RunTerraform
runs-on: ubuntu-latest
strategy:
matrix:
environment: ${{fromJson(needs.PrepareEnvironment.outputs.environment)}}
environment: ${{fromJson(needs.PrepareEnvironment.outputs.environment_json)}}
environment: ${{ matrix.environment }}

steps:
Expand Down
4 changes: 2 additions & 2 deletions iac/scripts/get-branch-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ branch="${2:-$(git rev-parse --abbrev-ref HEAD)}" # If branch is not provided,

# Check if the JSON file exists
if [ ! -f "$json_file" ]; then
echo "Error: JSON file '$json_file' does not exist."
echo "Error: JSON file '$json_file' does not exist." >& 2
exit 1
fi

Expand All @@ -34,7 +34,7 @@ find_environment_and_workspace() {

# Check if a match was found
if [ "$env_template" = "null" ] || [ -z "$env_template" ]; then
echo "No match found for branch: $branch"
echo "No match found for branch: $branch" >& 2
return 1
fi

Expand Down
4 changes: 2 additions & 2 deletions iac/scripts/get-branch-promotions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ usage() {

# Function to handle error when no promotion branch is found
error_exit() {
echo "No promotion branch for '$1'"
echo "No promotion branch for '$1'" >& 2
exit 1
}

# Function to handle error when no branch is found for reverse lookup
error_from_exit() {
echo "No branch promotes to '$1'"
echo "Branch '$1' is not promoted from any other" >& 2
exit 1
}

Expand Down

0 comments on commit dcff143

Please sign in to comment.