From d0d1d820a148592ea9f9be58628db64c5eac1f92 Mon Sep 17 00:00:00 2001 From: Irene Ryu Date: Tue, 2 Apr 2024 18:32:24 +0900 Subject: [PATCH] Another trial --- .github/workflows/package-publish.yml | 3 -- .github/workflows/release-ticket-creation.yml | 36 +++++++++++-------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.github/workflows/package-publish.yml b/.github/workflows/package-publish.yml index 4d17e277c..0f95a99ce 100644 --- a/.github/workflows/package-publish.yml +++ b/.github/workflows/package-publish.yml @@ -5,9 +5,6 @@ on: version: description: 'Target version' required: true - push: - branches: - - 'feat/AC-1856' jobs: publish: diff --git a/.github/workflows/release-ticket-creation.yml b/.github/workflows/release-ticket-creation.yml index 6847fa7b4..35c830ded 100644 --- a/.github/workflows/release-ticket-creation.yml +++ b/.github/workflows/release-ticket-creation.yml @@ -5,9 +5,6 @@ on: branch_name: description: 'Type a branch name starting with `release/v`' required: true - push: - branches: - - 'feat/AC-1856' jobs: trigger-release-ticket-creation: @@ -28,17 +25,15 @@ jobs: id: check_branch run: | set -x - set -o pipefail branch_name="${{ github.event.inputs.branch_name }}" - git ls-remote --exit-code --heads origin "$branch_name" | grep -q "$branch_name" - if [[ ${PIPESTATUS[1]} -eq 0 ]]; then + if git ls-remote --exit-code --heads origin "$branch_name" | grep -q "$branch_name"; then echo "BRANCH_EXISTS=true" >> $GITHUB_ENV else echo "BRANCH_EXISTS=false" >> $GITHUB_ENV fi - name: Create branch if it doesn't exist - if: steps.check_branch.outputs.branch_exists == 1 + if: ${{ env.BRANCH_EXISTS == 'false' }} run: | branch_name="${{ github.event.inputs.branch_name }}" git checkout -b "$branch_name" @@ -58,22 +53,33 @@ jobs: } }') echo "API_RESULT: ${API_RESULT}" - CIRCLE_CI_JOB_NUMBER=$(echo "${API_RESULT}" | jq -r '.number') + PIPELINE_ID=$(echo "${API_RESULT}" | jq -r '.id') - if [[ $? -eq 0 ]]; then - HTTP_STATUS=$(echo "${API_RESULT}" | jq -r '.status') + if [[ $? -eq 0 && $PIPELINE_ID != null ]]; then + STATUS="pending" + while [[ "$STATUS" == "pending" ]]; do + sleep 10 + WORKFLOW_STATUS=$(curl --request GET \ + --url "https://circleci.com/api/v2/pipeline/$PIPELINE_ID/workflow" \ + --header "Circle-Token: ${{ secrets.CIRCLECI_API_TOKEN }}" \ + --header "content-type: application/json") + echo "WORKFLOW_STATUS: ${WORKFLOW_STATUS}" + STATUS=$(echo "${WORKFLOW_STATUS}" | jq -r '.items[0].state') + echo "Current status: $STATUS" + done - if [[ $HTTP_STATUS == "success" ]]; then - echo "CircleCI Job Triggered: $CIRCLE_CI_JOB_NUMBER" - echo "DEPLOY_COMMENT_BODY=https://app.circleci.com/pipelines/github/${{ github.repository }}/$CIRCLE_CI_JOB_NUMBER" >> $GITHUB_ENV + if [[ $STATUS == "success" ]]; then + echo "CircleCI Job Completed Successfully" + echo "DEPLOY_COMMENT_BODY=https://app.circleci.com/pipelines/github/${{ github.repository }}/$PIPELINE_ID" >> $GITHUB_ENV echo "JOB_STATUS=success" >> $GITHUB_OUTPUT else - echo "CircleCI Job Trigger Failed" + echo "CircleCI Job Failed or Cancelled" echo "JOB_STATUS=failure" >> $GITHUB_OUTPUT exit 1 fi else - echo "API request failed" + echo "API request failed or Pipeline ID is null" echo "JOB_STATUS=failure" >> $GITHUB_OUTPUT exit 1 fi +