Skip to content

Commit

Permalink
ci(task-nr): improve conditions expressions to be reusable (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: André Caiado da Silva <[email protected]>
  • Loading branch information
andrecaiado and acaiado authored Mar 7, 2024
1 parent 0822ed8 commit ad7f275
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/CI-CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
push_image: ${{ steps.set-push-image.outputs.PUSH_IMAGE }}
deploy: ${{ steps.set-deploy.outputs.DEPLOY }}
environment: ${{ steps.set-deploy.outputs.ENVIRONMENT }}
env:
pr_merged: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == 'true' }}
release_published: ${{ github.event_name == 'release' && github.event.action == 'published' }}
steps:
- name: Validate release target branch
if: ${{ github.event_name == 'release' }}
Expand All @@ -43,8 +46,7 @@ jobs:
id: set-push-image
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]] ||
[[ "${{ github.event_name }}" == "release" && "${{ github.event.action }}" == "published" ]]; then
if [[ ${{env.pr_merged}} == true || ${{env.release_published}} == true ]]; then
echo "Setting PUSH_IMAGE to true"
echo "PUSH_IMAGE=true" >> "$GITHUB_OUTPUT"
else
Expand All @@ -55,12 +57,12 @@ jobs:
id: set-deploy
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
if [[ ${{env.pr_merged}} == true ]]; then
echo "Setting DEPLOY to true"
echo "Setting ENVIRONMENT to staging"
echo "DEPLOY=true" >> "$GITHUB_OUTPUT"
echo "ENVIRONMENT=STAGING" >> "$GITHUB_OUTPUT"
elif [[ "${{ github.event_name }}" == "release" && "${{ github.event.action }}" == "published" ]]; then
elif [[ ${{env.release_published}} == true ]]; then
echo "Setting DEPLOY to true"
echo "Setting ENVIRONMENT to production"
echo "DEPLOY=true" >> "$GITHUB_OUTPUT"
Expand Down

0 comments on commit ad7f275

Please sign in to comment.