.github/workflows/service_test2.yml #28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
workflow_dispatch: | |
inputs: | |
service_test1: | |
description: 'service_test1' | |
type: boolean | |
required: false | |
default: false | |
service_test2: | |
description: 'service_test2' | |
type: boolean | |
required: false | |
default: false | |
service_test3: | |
description: "service_test3" | |
type: boolean | |
required: false | |
default: false | |
jobs: | |
build-deploy-production: | |
runs-on: ubuntu-latest | |
environment: production | |
if: ${{ startsWith(github.ref, 'refs/heads/master') && contains('["tainguyenbp"]', github.actor) }} | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
- name: Pre-check step, build & deploy service to the production environments | |
if: ${{ github.event.ref == 'refs/heads/master' }} | |
run: | | |
BRANCH='master' | |
ORG='tanguyenbp' | |
REPO='prometheus-grafana' | |
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/${DESC}.yml/dispatches \ | |
--data "{\"ref\": \"$BRANCH\"}" | |
fi | |
done |