From 688359dcc78851bd5b8ca8d84a8cf4808f4fdd42 Mon Sep 17 00:00:00 2001 From: Michal Kleszcz Date: Wed, 11 Sep 2024 13:45:20 +0200 Subject: [PATCH] feat: #661 Update bitbucket pipelines config --- bitbucket-pipelines.yml | 36 +++++++++++++------ .../tools/scripts/clean-codebuild-branches.sh | 17 --------- 2 files changed, 25 insertions(+), 28 deletions(-) delete mode 100755 packages/internal/tools/scripts/clean-codebuild-branches.sh diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 2ca9260da..c0b35f3b1 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -51,14 +51,25 @@ definitions: --filter=webapp... steps: - - step: &codecommitPush - name: Push code to CodeCommit + - step: &deploy-current-branch + name: Deploy environment + trigger: manual clone: depth: full script: - - git remote add codecommit "$CODE_COMMIT_REPO" - - git push --force -u codecommit "$BITBUCKET_BRANCH" - - git push codecommit --tags --force + - | + response=$(curl -s -w "%{http_code}" -o response_body.txt -X POST "${SB_DEPLOY_TRIGGER_URL}?secret=$(echo -n '${SB_DEPLOY_TRIGGER_SECRET}' | jq -sRr @uri)" \ + -H "Content-Type: application/json" \ + -d '{ + "referenceName": "'"${BITBUCKET_COMMIT}"'", + "deployTarget": "'"${BITBUCKET_DEPLOYMENT_ENVIRONMENT}"'" + }') + status_code=$(tail -n1 <<< "$response") + if [ "$status_code" -ne 200 ]; then + echo "Deployment trigger failed with status code $status_code" + cat response_body.txt + exit 1 + fi - step: &webappTest name: 'webapp: Lint & test' @@ -544,7 +555,14 @@ pipelines: branches: master: - parallel: - - step: *codecommitPush + - step: + <<: *deploy-current-branch + name: Deploy to Production env + deployment: production + - step: + <<: *deploy-current-branch + name: Deploy to QA env + deployment: qa - step: *webappTest - step: *webappBuild @@ -570,8 +588,4 @@ pipelines: - step: *internalDocsBuild - step: *internalStatusDashboardBuild - - step: *internalToolsBuild - - step: - name: Delete unused branches from CodeCommit - script: - - /bin/bash packages/internal/tools/scripts/clean-codebuild-branches.sh + - step: *internalToolsBuild \ No newline at end of file diff --git a/packages/internal/tools/scripts/clean-codebuild-branches.sh b/packages/internal/tools/scripts/clean-codebuild-branches.sh deleted file mode 100755 index 0a643fd5f..000000000 --- a/packages/internal/tools/scripts/clean-codebuild-branches.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -eu - -git remote add codecommit "$CODE_COMMIT_REPO" - -git ls-remote codecommit --heads 'refs/heads/*' | while read line; do - branch_name=$(echo "${line}" | awk '{print $2}' | sed s/"refs\/heads\/"//) - origin_branch=$(git ls-remote origin --heads "refs/heads/${branch_name}") - - if [ -z "${origin_branch}" ] ; then - echo "Deleting branch: $branch_name" - git branch -D codecommit "$branch_name" - else - echo "Keeping branch: $branch_name" - fi -done