diff --git a/.github/workflows/argocd-create-app.yml b/.github/workflows/argocd-create-app.yml deleted file mode 100644 index 8f21ba68..00000000 --- a/.github/workflows/argocd-create-app.yml +++ /dev/null @@ -1,186 +0,0 @@ -name: "ArgoCD: Create Application" - -on: - workflow_call: - inputs: - docker_image_version: - required: true - type: string - branch_name: - required: true - type: string - workflow_dispatch: - inputs: - docker_image_version: - description: 'Docker image version' - required: true - type: string - branch_name: - description: 'Branch name' - required: true - type: string - -env: - INFRA_REPO: "HumanSignal/infra" - APP_BASE_NAME: "adala" - NAMESPACE: "prompt" - DOMAIN: "dev.heartex.com" - TEMPLATE_DIR: "vars/aws/dev.heartex.com/k8s/prompt/templates/adala" - APPS_DIR: "vars/aws/dev.heartex.com/k8s/prompt" - -jobs: - deploy: - if: github.event.pull_request.head.repo.fork == false - permissions: - contents: read - deployments: write - timeout-minutes: 15 - runs-on: ubuntu-latest - steps: - - uses: hmarr/debug-action@v3.0.0 - - - name: "GitHub deployment: Start" - id: github-deployment-start - uses: bobheadxi/deployments@v1 - with: - step: start - token: ${{ secrets.GIT_PAT }} - env: ${{ inputs.branch_name }} - ref: ${{ inputs.branch_name }} - - - name: Get GitHub user details - id: get-github-user - uses: actions/github-script@v7 - env: - ACTOR_USERNAME: ${{ github.event.sender.login }} - with: - github-token: ${{ secrets.GIT_PAT }} - script: | - const actor_username = process.env.ACTOR_USERNAME; - - let user_name = 'robot-ci-heartex'; - let user_email = 'robot-ci-heartex@users.noreply.github.com'; - - try { - const {data: user} = await github.rest.users.getByUsername({ - username: actor_username, - }); - user_name = user.login; - user_email = user.email; - } catch (e) { - console.log(e) - } - - core.setOutput('user_name', user_name); - core.setOutput('user_email', user_email); - - - name: Configure git - shell: bash - run: | - set -xeuo pipefail - git config --global user.name '${{ steps.get-github-user.outputs.user_name }}' - git config --global user.email '${{ steps.get-github-user.outputs.user_email }}' - - - name: Checkout - uses: actions/checkout@v4 - with: - repository: ${{ env.INFRA_REPO }} - token: ${{ secrets.GIT_PAT }} - fetch-depth: 1 - - - name: Commit - id: commit - shell: bash - env: - DOCKER_IMAGE_VERSION: ${{ inputs.docker_image_version }} - BRANCH_NAME: ${{ inputs.branch_name }} - run: | - set -xeuo pipefail - - pretty_branch_name="$(echo -n "${BRANCH_NAME#refs/heads/}" | sed 's#/#-#g' | sed 's#_#-#g'| sed 's#\.#-#g' | tr '[:upper:]' '[:lower:]')" - - APP_NAME="${pretty_branch_name}-${APP_BASE_NAME}" - APP_DIR="${APPS_DIR}/${APP_NAME}" - - export DOCKER_IMAGE_TAG="${DOCKER_IMAGE_VERSION}" - echo "DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG}" >> $GITHUB_OUTPUT - export RELEASE_NAME=$(echo "${pretty_branch_name}" | cut -c1-25) - echo "RELEASE_NAME=${RELEASE_NAME}" >> $GITHUB_OUTPUT - export HOSTNAME="${RELEASE_NAME}-${APP_BASE_NAME}.${NAMESPACE}.${DOMAIN}" - echo "HOSTNAME=${HOSTNAME}" >> $GITHUB_OUTPUT - - mkdir -p "${APP_DIR}" || true - for template_file_name in $(ls "${TEMPLATE_DIR}"); do - file_name="${template_file_name%.template}" - file_dest_path="${APP_DIR}/${file_name}" - if [[ "${template_file_name}" == *".override."* ]] && [[ -f "${file_dest_path}" ]]; then - echo "::notice::Skipping ${file_dest_path} templating" - else - envsubst < "${TEMPLATE_DIR}/${template_file_name}" > "${file_dest_path}" - fi - done - - git add "${APP_DIR}" - git status - git commit -m "${DOMAIN}: Create ${APP_NAME}@${NAMESPACE}" -m 'Workflow run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' - - - name: Push - id: push - shell: bash - run: | - set -xeuo pipefail - - attempt=0 - max_attempts=5 - while ! git push; do - attempt=$((attempt+1)) - if [ $attempt -ge $max_attempts ]; then - echo "Max attempts reached. Exiting." - exit 1 - fi - sleep_time=$((RANDOM % 10 + 1)) - echo "Push failed. Attempting retry (${attempt}/${max_attempts}) in ${sleep_time} seconds..." - sleep $sleep_time - git pull --rebase - done - - echo "commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - - name: Comment Pull Request - uses: actions/github-script@v7 - env: - PR_NUMBER: ${{ github.event.number }} - COMMIT_SHA: ${{ steps.push.outputs.commit_sha }} - with: - github-token: ${{ secrets.GIT_PAT }} - script: | - const { repo, owner } = context.repo; - const [infraOwner, infraRepo] = process.env.INFRA_REPO.split('/'); - const prNumber = process.env.PR_NUMBER; - const commit_sha = process.env.COMMIT_SHA; - - if (prNumber && commit_sha) { - const { data: commit } = await github.rest.git.getCommit({ - owner: infraOwner, - repo: infraRepo, - commit_sha: commit_sha, - }); - await github.rest.issues.createComment({ - owner: owner, - repo: repo, - issue_number: prNumber, - body: `Commit ${commit.html_url} is created.`, - }); - } - - - name: "GitHub deployment: Finish" - id: github-deployment-finish - if: always() - uses: bobheadxi/deployments@v1 - with: - step: finish - token: ${{ secrets.GIT_PAT }} - status: ${{ job.status }} - deployment_id: ${{ steps.github-deployment-start.outputs.deployment_id }} - env: ${{ steps.github-deployment-start.outputs.env }} - env_url: "https://${{ steps.commit.outputs.HOSTNAME }}" diff --git a/.github/workflows/argocd-delete-app.yml b/.github/workflows/argocd-delete-app.yml deleted file mode 100644 index c371dbcd..00000000 --- a/.github/workflows/argocd-delete-app.yml +++ /dev/null @@ -1,154 +0,0 @@ -name: "ArgoCD: Delete Application" - -on: - workflow_call: - inputs: - branch_name: - required: true - type: string - workflow_dispatch: - inputs: - branch_name: - description: 'Branch name' - required: true - type: string - pull_request_target: - types: - - closed - branches: - - master - - '**' - - -env: - INFRA_REPO: "HumanSignal/infra" - APP_BASE_NAME: "adala" - NAMESPACE: "prompt" - DOMAIN: "dev.heartex.com" - TEMPLATE_DIR: "vars/aws/dev.heartex.com/k8s/prompt/templates/adala" - APPS_DIR: "vars/aws/dev.heartex.com/k8s/prompt" - -jobs: - destroy: - if: github.event.pull_request.head.repo.fork == false - permissions: - contents: read - deployments: write - timeout-minutes: 15 - runs-on: ubuntu-latest - steps: - - uses: hmarr/debug-action@v3.0.0 - - - name: Get GitHub user details - id: get-github-user - uses: actions/github-script@v7 - env: - ACTOR_USERNAME: ${{ github.event.sender.login }} - with: - github-token: ${{ secrets.GIT_PAT }} - script: | - const actor_username = process.env.ACTOR_USERNAME; - - let user_name = 'robot-ci-heartex'; - let user_email = 'robot-ci-heartex@users.noreply.github.com'; - - try { - const {data: user} = await github.rest.users.getByUsername({ - username: actor_username, - }); - user_name = user.login; - user_email = user.email; - } catch (e) { - console.log(e) - } - - core.setOutput('user_name', user_name); - core.setOutput('user_email', user_email); - - - name: Configure git - shell: bash - run: | - set -xeuo pipefail - git config --global user.name '${{ steps.get-github-user.outputs.user_name }}' - git config --global user.email '${{ steps.get-github-user.outputs.user_email }}' - - - name: Checkout - uses: actions/checkout@v4 - with: - repository: ${{ env.INFRA_REPO }} - token: ${{ secrets.GIT_PAT }} - fetch-depth: 1 - - - name: Commit - shell: bash - env: - DOCKER_IMAGE_VERSION: ${{ inputs.docker_image_version }} - BRANCH_NAME: ${{ inputs.branch_name || github.event.pull_request.head.ref || github.ref_name }} - run: | - set -xeuo pipefail - - pretty_branch_name="$(echo -n "${BRANCH_NAME#refs/heads/}" | sed 's#/#-#g' | sed 's#_#-#g'| sed 's#\.#-#g' | tr '[:upper:]' '[:lower:]')" - - APP_NAME="${pretty_branch_name}-${APP_BASE_NAME}" - APP_DIR="${APPS_DIR}/${APP_NAME}" - - git rm -r "${APP_DIR}" - git status - git commit -m "${DOMAIN}: Delete ${APP_NAME}@${NAMESPACE}" -m 'Workflow run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' - - - name: Push - id: push - shell: bash - run: | - set -xeuo pipefail - - attempt=0 - max_attempts=5 - while ! git push; do - attempt=$((attempt+1)) - if [ $attempt -ge $max_attempts ]; then - echo "Max attempts reached. Exiting." - exit 1 - fi - sleep_time=$((RANDOM % 10 + 1)) - echo "Push failed. Attempting retry (${attempt}/${max_attempts}) in ${sleep_time} seconds..." - sleep $sleep_time - git pull --rebase - done - - echo "commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - - name: Comment Pull Request - uses: actions/github-script@v7 - env: - PR_NUMBER: ${{ github.event.number }} - COMMIT_SHA: ${{ steps.push.outputs.commit_sha }} - with: - github-token: ${{ secrets.GIT_PAT }} - script: | - const { repo, owner } = context.repo; - const [infraOwner, infraRepo] = process.env.INFRA_REPO.split('/'); - const prNumber = process.env.PR_NUMBER; - const commit_sha = process.env.COMMIT_SHA; - - if (prNumber && commit_sha) { - const { data: commit } = await github.rest.git.getCommit({ - owner: infraOwner, - repo: infraRepo, - commit_sha: commit_sha, - }); - await github.rest.issues.createComment({ - owner: owner, - repo: repo, - issue_number: prNumber, - body: `Commit ${commit.html_url} is created.`, - }); - } - - - name: "GitHub deployment: Delete" - id: github-deployment-delete - uses: bobheadxi/deployments@v1 - with: - step: delete-env - token: ${{ secrets.GIT_PAT }} - env: ${{ inputs.branch_name || github.event.pull_request.head.ref || github.ref_name }} diff --git a/.github/workflows/argocd-deploy.yml b/.github/workflows/argocd-deploy.yml new file mode 100644 index 00000000..6c3e90c8 --- /dev/null +++ b/.github/workflows/argocd-deploy.yml @@ -0,0 +1,143 @@ +name: "ArgoCD: Deploy" + +on: + workflow_call: + inputs: + docker_image_version: + required: true + type: string + app_name: + required: true + type: string + template_name: + required: false + default: "adala" + type: string + cluster: + required: false + default: "dev.heartex.com" + type: string + namespace: + required: false + default: "prompt" + type: string + workflow_dispatch: + inputs: + docker_image_version: + description: "Docker image version" + required: true + type: string + app_name: + description: "ArgoCD App name" + required: true + type: string + template_name: + description: "ArgoCD template name" + required: false + default: "adala" + type: string + cluster: + description: "Cluster name" + required: false + default: "dev.heartex.com" + type: string + namespace: + description: "Namespace" + required: false + default: "prompt" + type: string + +env: + INFRA_REPO: "HumanSignal/infra" + +jobs: + + deploy: + timeout-minutes: 15 + runs-on: ubuntu-latest + steps: + - uses: hmarr/debug-action@v3.0.0 + + - name: "GitHub deployment: Start" + id: github-deployment-start + continue-on-error: true + if: github.event.pull_request.head.ref + uses: bobheadxi/deployments@v1 + with: + step: start + token: ${{ secrets.GIT_PAT }} + env: ${{ inputs.app_name }} + ref: ${{ github.event.pull_request.head.ref }} + + - name: Get GitHub user details + id: get-github-user + uses: actions/github-script@v7 + env: + ACTOR_USERNAME: ${{ github.event.sender.login }} + with: + github-token: ${{ secrets.GIT_PAT }} + script: | + const actor_username = process.env.ACTOR_USERNAME; + + let user_name = 'robot-ci-heartex'; + let user_email = 'robot-ci-heartex@users.noreply.github.com'; + + try { + const {data: user} = await github.rest.users.getByUsername({ + username: actor_username, + }); + user_name = user.login; + user_email = user.email; + } catch (e) { + console.log(e) + } + + core.setOutput('user_name', user_name); + core.setOutput('user_email', user_email); + + - name: Checkout + uses: actions/checkout@v4 + with: + repository: ${{ env.INFRA_REPO }} + token: ${{ secrets.GIT_PAT }} + fetch-depth: 1 + + - name: Checkout Actions Hub + uses: actions/checkout@v4 + with: + token: ${{ secrets.GIT_PAT }} + repository: HumanSignal/actions-hub + path: ./.github/actions-hub + + - name: Git Configure + uses: ./.github/actions-hub/actions/git-configure + with: + username: "${{ steps.get-github-user.outputs.user_name }}" + email: "${{ steps.get-github-user.outputs.user_email }}" + + - name: Create ArgoCD App + uses: ./.github/actions-hub/actions/argocd-app-create + id: argocd-app + with: + docker_image_tag: "${{ inputs.docker_image_version }}" + app_name: "${{ inputs.app_name }}-${{ inputs.template_name }}" + template_name: "${{ inputs.template_name }}" + cluster: "${{ inputs.cluster }}" + namespace: "${{ inputs.namespace }}" + github_token: ${{ secrets.GIT_PAT }} + + - name: Git Push + id: push + uses: ./.github/actions-hub/actions/git-push + + - name: "GitHub deployment: Finish" + id: github-deployment-finish + if: always() && github.event.pull_request.head.ref + uses: bobheadxi/deployments@v1 + with: + step: finish + token: ${{ secrets.GIT_PAT }} + status: ${{ job.status }} + deployment_id: ${{ steps.github-deployment-start.outputs.deployment_id }} + env: ${{ steps.github-deployment-start.outputs.env }} + env_url: "https://${{ steps.argocd-app.outputs.url }}" diff --git a/.github/workflows/argocd-destroy.yml b/.github/workflows/argocd-destroy.yml new file mode 100644 index 00000000..f480f28d --- /dev/null +++ b/.github/workflows/argocd-destroy.yml @@ -0,0 +1,134 @@ +name: "ArgoCD: Destroy" + +on: + workflow_call: + inputs: + app_name: + required: true + type: string + template_name: + required: false + default: "adala" + type: string + cluster: + required: false + default: "dev.heartex.com" + type: string + namespace: + required: false + default: "prompt" + type: string + workflow_dispatch: + inputs: + app_name: + description: "ArgoCD App name" + required: true + type: string + template_name: + description: "ArgoCD template name" + required: false + default: "adala" + type: string + cluster: + description: "Cluster name" + required: false + default: "dev.heartex.com" + type: string + namespace: + description: "Namespace" + required: false + default: "prompt" + type: string + pull_request_target: + types: + - closed + branches: + - master + - '**' + +env: + INFRA_REPO: "HumanSignal/infra" + +jobs: + + destroy: + timeout-minutes: 15 + runs-on: ubuntu-latest + steps: + - uses: hmarr/debug-action@v3.0.0 + + - name: Get GitHub user details + id: get-github-user + uses: actions/github-script@v7 + env: + ACTOR_USERNAME: ${{ github.event.sender.login }} + with: + github-token: ${{ secrets.GIT_PAT }} + script: | + const actor_username = process.env.ACTOR_USERNAME; + + let user_name = 'robot-ci-heartex'; + let user_email = 'robot-ci-heartex@users.noreply.github.com'; + + try { + const {data: user} = await github.rest.users.getByUsername({ + username: actor_username, + }); + user_name = user.login; + user_email = user.email; + } catch (e) { + console.log(e) + } + + core.setOutput('user_name', user_name); + core.setOutput('user_email', user_email); + + - name: Checkout + uses: actions/checkout@v4 + with: + repository: ${{ env.INFRA_REPO }} + token: ${{ secrets.GIT_PAT }} + fetch-depth: 1 + + - name: Checkout Actions Hub + uses: actions/checkout@v4 + with: + token: ${{ secrets.GIT_PAT }} + repository: HumanSignal/actions-hub + path: ./.github/actions-hub + + - name: Git Configure + uses: ./.github/actions-hub/actions/git-configure + with: + username: "${{ steps.get-github-user.outputs.user_name }}" + email: "${{ steps.get-github-user.outputs.user_email }}" + + - name: Calculate version + id: version + env: + BRANCH_NAME: ${{ github.event.pull_request.head.ref || github.ref_name }} + run: | + set -x + pretty_branch_name="$(echo -n "${BRANCH_NAME#refs/heads/}" | sed 's#/#-#g' | sed 's#_#-#g'| sed 's#\.#-#g' | tr '[:upper:]' '[:lower:]' | cut -c1-25)" + echo "pretty_branch_name=$pretty_branch_name" >> $GITHUB_OUTPUT + + - name: Delete ArgoCD App + uses: ./.github/actions-hub/actions/argocd-app-delete + id: argocd-app + with: + app_name: "${{ inputs.app_name || steps.version.outputs.pretty_branch_name }}-${{ inputs.template_name || 'adala' }}" + cluster: "${{ inputs.cluster || 'dev.heartex.com' }}" + namespace: "${{ inputs.namespace || 'prompt' }}" + github_token: ${{ secrets.GIT_PAT }} + + - name: Git Push + id: push + uses: ./.github/actions-hub/actions/git-push + + - name: "GitHub deployment: Delete" + id: github-deployment-delete + uses: bobheadxi/deployments@v1 + with: + step: delete-env + token: ${{ secrets.GIT_PAT }} + env: ${{ inputs.app_name || steps.version.outputs.pretty_branch_name }} diff --git a/.github/workflows/argocd-scale-app.yml b/.github/workflows/argocd-scale-app.yml deleted file mode 100644 index ea2e1409..00000000 --- a/.github/workflows/argocd-scale-app.yml +++ /dev/null @@ -1,169 +0,0 @@ -name: "ArgoCD: Scale Application" - -on: - workflow_call: - inputs: - replicas: - required: true - type: string - branch_name: - required: true - type: string - workflow_dispatch: - inputs: - replicas: - description: 'Replicas' - required: true - type: string - branch_name: - description: 'Branch name' - required: true - type: string - pull_request_target: - types: - - converted_to_draft - branches: - - master - - '**' - -env: - INFRA_REPO: "HumanSignal/infra" - APP_BASE_NAME: "adala" - NAMESPACE: "prompt" - DOMAIN: "dev.heartex.com" - TEMPLATE_DIR: "vars/aws/dev.heartex.com/k8s/prompt/templates/adala" - APPS_DIR: "vars/aws/dev.heartex.com/k8s/prompt" - REPLICA_COUNT_VALUES_YAML_KEY: ".*.deployment.replicaCount" - -jobs: - scale: - if: github.event.pull_request.head.repo.fork == false - permissions: - contents: read - deployments: write - timeout-minutes: 15 - runs-on: ubuntu-latest - steps: - - uses: hmarr/debug-action@v3.0.0 - - - name: Get GitHub user details - id: get-github-user - uses: actions/github-script@v7 - env: - ACTOR_USERNAME: ${{ github.event.sender.login }} - with: - github-token: ${{ secrets.GIT_PAT }} - script: | - const actor_username = process.env.ACTOR_USERNAME; - - let user_name = 'robot-ci-heartex'; - let user_email = 'robot-ci-heartex@users.noreply.github.com'; - - try { - const {data: user} = await github.rest.users.getByUsername({ - username: actor_username, - }); - user_name = user.login; - user_email = user.email; - } catch (e) { - console.log(e) - } - - core.setOutput('user_name', user_name); - core.setOutput('user_email', user_email); - - - name: Configure git - shell: bash - run: | - set -xeuo pipefail - git config --global user.name '${{ steps.get-github-user.outputs.user_name }}' - git config --global user.email '${{ steps.get-github-user.outputs.user_email }}' - - - name: Checkout - uses: actions/checkout@v4 - with: - repository: ${{ env.INFRA_REPO }} - token: ${{ secrets.GIT_PAT }} - fetch-depth: 1 - - - name: Commit - shell: bash - env: - REPLICA_COUNT: ${{ inputs.replicas }} - BRANCH_NAME: ${{ inputs.branch_name || github.event.pull_request.head.ref || github.ref_name }} - run: | - set -xeuo pipefail - - pretty_branch_name="$(echo -n "${BRANCH_NAME#refs/heads/}" | sed 's#/#-#g' | sed 's#_#-#g'| sed 's#\.#-#g' | tr '[:upper:]' '[:lower:]')" - - APP_NAME="${pretty_branch_name}-${APP_BASE_NAME}" - APP_DIR="${APPS_DIR}/${APP_NAME}" - APP_VALUES_FILE="${APP_DIR}/values.yaml" - - if [[ "${{ github.event.action }}" = "converted_to_draft" ]]; then - REPLICA_COUNT=0 - fi - - yq e --inplace "${REPLICA_COUNT_VALUES_YAML_KEY} |= ${REPLICA_COUNT}" "${APP_VALUES_FILE}" - - git add "${APP_DIR}" - git status - git commit -m "${DOMAIN}: Downscale ${APP_NAME}@${NAMESPACE} to 0" -m 'Workflow run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' - - - name: Push - id: push - shell: bash - run: | - set -xeuo pipefail - - attempt=0 - max_attempts=5 - while ! git push; do - attempt=$((attempt+1)) - if [ $attempt -ge $max_attempts ]; then - echo "Max attempts reached. Exiting." - exit 1 - fi - sleep_time=$((RANDOM % 10 + 1)) - echo "Push failed. Attempting retry (${attempt}/${max_attempts}) in ${sleep_time} seconds..." - sleep $sleep_time - git pull --rebase - done - - echo "commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - - name: Comment Pull Request - uses: actions/github-script@v7 - env: - PR_NUMBER: ${{ github.event.number }} - COMMIT_SHA: ${{ steps.push.outputs.commit_sha }} - with: - github-token: ${{ secrets.GIT_PAT }} - script: | - const { repo, owner } = context.repo; - const [infraOwner, infraRepo] = process.env.INFRA_REPO.split('/'); - const prNumber = process.env.PR_NUMBER; - const commit_sha = process.env.COMMIT_SHA; - - if (prNumber && commit_sha) { - const { data: commit } = await github.rest.git.getCommit({ - owner: infraOwner, - repo: infraRepo, - commit_sha: commit_sha, - }); - await github.rest.issues.createComment({ - owner: owner, - repo: repo, - issue_number: prNumber, - body: `Commit ${commit.html_url} is created.`, - }); - } - - - name: "GitHub deployment: Deactivate" - id: github-deployment-deactivate - uses: bobheadxi/deployments@v1 - with: - step: deactivate-env - token: ${{ secrets.GIT_PAT }} - env: ${{ inputs.branch_name || github.event.pull_request.head.ref || github.ref_name }} - desc: "Environment was scaled down to 0" diff --git a/.github/workflows/argocd-scaledown.yml b/.github/workflows/argocd-scaledown.yml new file mode 100644 index 00000000..51acfe60 --- /dev/null +++ b/.github/workflows/argocd-scaledown.yml @@ -0,0 +1,135 @@ +name: "ArgoCD: Scaledown" + +on: + workflow_call: + inputs: + app_name: + required: true + type: string + template_name: + required: false + default: "label-studio-enterprise" + type: string + cluster: + required: false + default: "dev.heartex.com" + type: string + namespace: + required: false + default: "prompt" + type: string + workflow_dispatch: + inputs: + app_name: + description: "ArgoCD App name" + required: true + type: string + template_name: + description: "ArgoCD template name" + required: false + default: "label-studio-enterprise" + type: string + cluster: + description: "Cluster name" + required: false + default: "dev.heartex.com" + type: string + namespace: + description: "Namespace" + required: false + default: "prompt" + type: string + pull_request_target: + types: + - converted_to_draft + branches: + - master + - '**' + +env: + INFRA_REPO: "HumanSignal/infra" + +jobs: + + scale: + timeout-minutes: 15 + runs-on: ubuntu-latest + steps: + - uses: hmarr/debug-action@v3.0.0 + + - name: Get GitHub user details + id: get-github-user + uses: actions/github-script@v7 + env: + ACTOR_USERNAME: ${{ github.event.sender.login }} + with: + github-token: ${{ secrets.GIT_PAT }} + script: | + const actor_username = process.env.ACTOR_USERNAME; + + let user_name = 'robot-ci-heartex'; + let user_email = 'robot-ci-heartex@users.noreply.github.com'; + + try { + const {data: user} = await github.rest.users.getByUsername({ + username: actor_username, + }); + user_name = user.login; + user_email = user.email; + } catch (e) { + console.log(e) + } + + core.setOutput('user_name', user_name); + core.setOutput('user_email', user_email); + + - name: Checkout + uses: actions/checkout@v4 + with: + repository: ${{ env.INFRA_REPO }} + token: ${{ secrets.GIT_PAT }} + fetch-depth: 1 + + - name: Checkout Actions Hub + uses: actions/checkout@v4 + with: + token: ${{ secrets.GIT_PAT }} + repository: HumanSignal/actions-hub + path: ./.github/actions-hub + + - name: Git Configure + uses: ./.github/actions-hub/actions/git-configure + with: + username: "${{ steps.get-github-user.outputs.user_name }}" + email: "${{ steps.get-github-user.outputs.user_email }}" + + - name: Calculate version + id: version + env: + BRANCH_NAME: ${{ github.event.pull_request.head.ref || github.ref_name }} + run: | + set -x + pretty_branch_name="$(echo -n "${BRANCH_NAME#refs/heads/}" | sed 's#/#-#g' | sed 's#_#-#g'| sed 's#\.#-#g' | tr '[:upper:]' '[:lower:]' | cut -c1-25)" + echo "pretty_branch_name=$pretty_branch_name" >> $GITHUB_OUTPUT + + - name: Scaledown ArgoCD App + uses: ./.github/actions-hub/actions/argocd-app-scaledown + id: argocd-app + with: + app_name: "${{ inputs.app_name || steps.version.outputs.pretty_branch_name }}-${{ inputs.template_name || 'adala' }}" + cluster: "${{ inputs.cluster || 'dev.heartex.com' }}" + namespace: "${{ inputs.namespace || 'prompt' }}" + github_token: ${{ secrets.GIT_PAT }} + + - name: Git Push + id: push + uses: ./.github/actions-hub/actions/git-push + + - name: "GitHub deployment: Deactivate" + id: github-deployment-deactivate + uses: bobheadxi/deployments@v1 + with: + step: deactivate-env + token: ${{ secrets.GIT_PAT }} + env: ${{ inputs.app_name || steps.version.outputs.pretty_branch_name }} + desc: "Environment was scaled down to 0" diff --git a/.github/workflows/cicd-pipeline.yml b/.github/workflows/cicd-pipeline.yml index f134c4d8..91e59b42 100644 --- a/.github/workflows/cicd-pipeline.yml +++ b/.github/workflows/cicd-pipeline.yml @@ -56,7 +56,7 @@ jobs: deploy: name: "Deploy" if: github.event_name == 'pull_request' && needs.details.outputs.membership || github.event_name == 'push' && needs.details.outputs.membership - uses: ./.github/workflows/argocd-create-app.yml + uses: ./.github/workflows/argocd-deploy.yml needs: - details - build @@ -65,5 +65,5 @@ jobs: deployments: write with: docker_image_version: ${{ needs.build.outputs.image_version }} - branch_name: ${{ github.event.pull_request.head.ref || github.ref_name }} + app_name: ${{ needs.build.outputs.pretty_branch_name }} secrets: inherit diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 1aca0cee..bf6c8352 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -13,6 +13,9 @@ on: image_version: description: "Docker tag" value: ${{ jobs.docker_build_and_push.outputs.image_version }} + pretty_branch_name: + description: "Pretty Branch Name" + value: ${{ jobs.docker_build_and_push.outputs.pretty_branch_name }} env: DOCKER_CLI_EXPERIMENTAL: enabled @@ -26,6 +29,7 @@ jobs: runs-on: ubuntu-latest outputs: image_version: ${{ steps.version.outputs.image_version }} + pretty_branch_name: ${{ steps.version.outputs.pretty_branch_name }} steps: - uses: hmarr/debug-action@v3.0.0