Skip to content

Commit

Permalink
add some content to deploy action
Browse files Browse the repository at this point in the history
  • Loading branch information
soilking committed Aug 30, 2024
1 parent 1b5737e commit 6624312
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Deploy

on:
push:
branches:
- main
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment (prod/dev)'
required: true
branch:
description: 'Branch name'
required: true

jobs:
validation:
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.check_env.outputs.environment }}
branch: ${{ steps.check_env.outputs.branch }}
steps:
- name: Set defaults for push event
id: set_defaults
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
echo "ENVIRONMENT=prod" >> $GITHUB_ENV
echo "BRANCH=main" >> $GITHUB_ENV
else
echo "ENVIRONMENT=${{ github.event.inputs.environment }}" >> $GITHUB_ENV
echo "BRANCH=${{ github.event.inputs.branch }}" >> $GITHUB_ENV
fi
- name: Validate environment input
id: check_env
run: |
# Check if the environment is either 'prod' or 'dev'
if [[ "$ENVIRONMENT" != "prod" && "$ENVIRONMENT" != "dev" ]]; then
echo "Error: Environment must be 'prod' or 'dev'."
exit 1
fi
# Additional check for 'prod' deployment to be from 'main' branch only
if [[ "$ENVIRONMENT" == "prod" && "$BRANCH" != "main" ]]; then
echo "Error: Production deployments can only be made from the 'main' branch."
exit 1
fi
# Output for use in the subsequent job
echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT
echo "branch=$BRANCH" >> $GITHUB_OUTPUT

0 comments on commit 6624312

Please sign in to comment.