Skip to content

fixed vars

fixed vars #172

Workflow file for this run

name: Build and Deploy for Dev, QA, and Stable
on:
workflow_dispatch:
inputs:
RELEASE:
required: false
type: string
description: "The name of the release you want to deploy to stable."
pull_request:
types: [opened, reopened, synchronize]
branches:
- dev
pull_request_target:
types: [closed]
branches:
- dev
release:
types: [created]
env:
ARTIFACT_NAME: actions-demo
jobs:
build_test_and_deploy_dev:
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request' && github.base_ref == 'dev' ||
(github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'dev')
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Preparing job
run: |
echo "SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
echo "IMAGE_DEV=kennyd3d/${{ env.ARTIFACT_NAME }}:$SHA_SHORT" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Run tests
run: |
echo "Fake running some test"
- name: Build Docker Image
uses: docker/build-push-action@v6
with:
context: .
push: false
tags: |
${{ env.IMAGE_DEV }}
- name: Push Docker Image if merged
if: ${{ github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'dev' }}
run: |
docker push ${{ env.IMAGE_DEV }}
- name: Deploy to Dev
if: ${{ github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'dev' }}
run: |
echo "Pretending to deploy to k8"
echo "## Successfully deployed ${{ env.IMAGE_DEV }} to Dev namespace ✅" >> $GITHUB_STEP_SUMMARY
# Build test and deploy to qa namespace when a release tag is created
build_test_and_deploy_qa:
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'created'
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Preparing job
run: |
echo "SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
echo "IMAGE_DEV=kennyd3d/${{ env.ARTIFACT_NAME }}:$SHA_SHORT" >> $GITHUB_ENV
echo "IMAGE_QA=kennyd3d/${{ env.ARTIFACT_NAME }}:${{ github.event.release.name }}" >> $GITHUB_ENV
- name: Retag and push Docker Image with Release Name
run: |
docker pull ${{ env.IMAGE_DEV }}
docker tag ${{ env.IMAGE_DEV }} ${{ env.IMAGE_QA }}
docker push ${{ env.IMAGE_QA }}
- name: Deploy to Stable k8
run: |
echo "Test to deploy to Stable k8 using image ${{ env.IMAGE_QA }}"
- name: Give possible failure hint
if: failure()
run: |
echo "# ❌ QA Failed to Deploy: Did you make sure you tagged the same commit that merged to Dev? 🤔" >> $GITHUB_STEP_SUMMARY
echo "## DEV deployment: ${{ env.IMAGE_DEV }}" >> $GITHUB_STEP_SUMMARY
echo "## QA Deployment: ${{ env.IMAGE_QA }}" >> $GITHUB_STEP_SUMMARY
- name: Run success message on successful deployment
if: success()
run: |
echo "# 🎊 Successfully deployed ${{ env.IMAGE_QA }} to QA ✅" >> $GITHUB_STEP_SUMMARY
# Manually deploy the release given the release name
deploy_stable:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' }}
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Check if release exists in remote repo
run: |
echo "IMAGE_STABLE=kennyd3d/${{ env.ARTIFACT_NAME }}:${{ github.event.inputs.INPUT_TAG }}" >> $GITHUB_ENV
if ! docker manifest inspect ${{ env.IMAGE_STABLE }} > /dev/null 2>&1; then
echo '# ❌ Failed Stable Deployment: ${{ env.IMAGE_STABLE }} not found in artifactory' >> $GITHUB_STEP_SUMMARY
exit 1
fi
- name: Deploy release to stable namespace
run: |
echo "Test to deploy to Stable k8 using image ${{ env.IMAGE_STABLE }}"
- name: Give possible failure hint
if: failure()
run: |
echo "## Stable Failed to Deploy ${{ env.IMAGE_STABLE }}: Did you type the correct release name? 🤔" >> $GITHUB_STEP_SUMMARY
- name: Run success message on successful deployment
if: success()
run: |
echo "# 🎊 Successfully deployed ${{ env.IMAGE_STABLE }} to Stable ✅" >> $GITHUB_STEP_SUMMARY