From d33ed30c849567479f6a1acad3e32c62f098dfba Mon Sep 17 00:00:00 2001 From: bm8 bmFtZQ Date: Thu, 23 May 2024 16:38:35 +0700 Subject: [PATCH] Update service_test2.yml Signed-off-by: bm8 bmFtZQ --- .github/workflows/service_test2.yml | 125 +++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 3 deletions(-) diff --git a/.github/workflows/service_test2.yml b/.github/workflows/service_test2.yml index 7f31606..158cccd 100644 --- a/.github/workflows/service_test2.yml +++ b/.github/workflows/service_test2.yml @@ -16,7 +16,46 @@ on: type: boolean required: false default: false - + service_test4: + description: 'service_test1' + type: boolean + required: false + default: false + service_test5: + description: 'service_test2' + type: boolean + required: false + default: false + service_test6: + description: "service_test3" + type: boolean + required: false + default: false + service_test7: + description: 'service_test2' + type: boolean + required: false + default: false + service_test8: + description: "service_test3" + type: boolean + required: false + default: false + service_test9: + description: "service_test3" + type: boolean + required: false + default: false + service_test10: + description: "service_test3" + type: boolean + required: false + default: false + service_test11: + description: "service_test3" + type: boolean + required: false + default: false jobs: build-deploy-production: runs-on: ubuntu-latest @@ -30,8 +69,88 @@ jobs: if: ${{ github.event.ref == 'refs/heads/master' }} run: | BRANCH='master' + GITHUB_REF=${{ github.event.ref }} + ORG='tanguyenbp' + REPO='prometheus-grafana' + ORG_REPO=${GITHUB_REPOSITORY} + INPUT_JSON=$(echo '${{ toJson(github.event.inputs) }}') + echo "INPUT_JSON: $INPUT_JSON" + + INPUT_DESC=$(echo "$INPUT_JSON" | jq -r 'keys_unsorted[]') + for ITEM in $INPUT_DESC; do + + echo "ITEM is : ${ITEM}" + # Extract description and value + + WORKFLOW_NAME=$(echo "$INPUT_JSON" | jq -r --arg ITEM "$ITEM" '.[$ITEM]') + + echo "The value of $ITEM is: $WORKFLOW_NAME" + + if [[ "$WORKFLOW_NAME" == "true" ]]; then + echo "Triggering workflow run for $WORKFLOW_NAME..." + # Trigger the workflow run + curl -X POST \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: token $TOKEN" \ + https://api.github.com/repos/${ORG_REPO}/actions/workflows/${ITEM}.yml/dispatches \ + --data "{\"ref\": \"${GITHUB_REF}\"}" + fi + done + build-deploy-development: + runs-on: ubuntu-latest + environment: development + if: ${{ startsWith(github.ref, 'refs/heads/develop') && contains('["tainguyenbp"]', github.actor) }} + steps: + - name: Checkout + uses: actions/checkout@v4.1.6 + + - name: Pre-check step, build & deploy service to the production environments + if: ${{ github.event.ref == 'refs/heads/develop' }} + run: | + BRANCH='master' + GITHUB_REF=${{ github.event.ref }} + ORG='tanguyenbp' + REPO='prometheus-grafana' + ORG_REPO=${GITHUB_REPOSITORY} + INPUT_JSON=$(echo '${{ toJson(github.event.inputs) }}') + echo "INPUT_JSON: $INPUT_JSON" + + INPUT_DESC=$(echo "$INPUT_JSON" | jq -r 'keys_unsorted[]') + for ITEM in $INPUT_DESC; do + + echo "ITEM is : ${ITEM}" + # Extract description and value + + WORKFLOW_NAME=$(echo "$INPUT_JSON" | jq -r --arg ITEM "$ITEM" '.[$ITEM]') + + echo "The value of $ITEM is: $WORKFLOW_NAME" + + if [[ "$WORKFLOW_NAME" == "true" ]]; then + echo "Triggering workflow run for $WORKFLOW_NAME..." + # Trigger the workflow run + curl -X POST \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: token $TOKEN" \ + https://api.github.com/repos/${ORG_REPO}/actions/workflows/${ITEM}.yml/dispatches \ + --data "{\"ref\": \"${GITHUB_REF}\"}" + fi + done + build-deploy-staging: + runs-on: ubuntu-latest + environment: staging + if: ${{ startsWith(github.ref, 'refs/heads/staging') && contains('["tainguyenbp"]', github.actor) }} + steps: + - name: Checkout + uses: actions/checkout@v4.1.6 + + - name: Pre-check step, build & deploy service to the production environments + if: ${{ github.event.ref == 'refs/heads/staging' }} + run: | + BRANCH='master' + GITHUB_REF=${{ github.event.ref }} ORG='tanguyenbp' REPO='prometheus-grafana' + ORG_REPO=${GITHUB_REPOSITORY} INPUT_JSON=$(echo '${{ toJson(github.event.inputs) }}') echo "INPUT_JSON: $INPUT_JSON" @@ -51,7 +170,7 @@ jobs: curl -X POST \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token $TOKEN" \ - https://api.github.com/repos/${ORG}/${REPO}/actions/workflows/${DESC}.yml/dispatches \ - --data "{\"ref\": \"$BRANCH\"}" + https://api.github.com/repos/${ORG_REPO}/actions/workflows/${ITEM}.yml/dispatches \ + --data "{\"ref\": \"${GITHUB_REF}\"}" fi done