Skip to content

Commit

Permalink
Added the public action for trigger flow
Browse files Browse the repository at this point in the history
  • Loading branch information
sangeet-joy_xero committed Sep 23, 2024
1 parent 4fe77b2 commit 2f6f784
Showing 1 changed file with 44 additions and 29 deletions.
73 changes: 44 additions & 29 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,40 @@ jobs:
const token = await getAccessToken()
return token
- name: Calling All SDK workflows
run: |
dispatchId=$((10000 + RANDOM % 90000))
echo "dispatchId: $dispatchId"
- name: Trigger All SDK workflow
uses: convictional/trigger-workflow-and-wait@v1.6.1
with:
owner: xero-internal
repo: xeroapi-sdk-codegen
github_token: ${{ steps.get_access_token.outputs.result }}
workflow_file_name: pr.yml
ref: PETOSS-536-enabling-workflow-dispatch
wait_interval: 10
client_payload: '{"branch_name": "${{github.head_ref}}"}'
propagate_failure: false
trigger_workflow: true
wait_workflow: true


# - name: Calling All SDK workflows
# run: |
# dispatchId=$((10000 + RANDOM % 90000))
# echo "dispatchId: $dispatchId"

json_payload=$(jq -n \
--arg ref "PETOSS-536-enabling-workflow-dispatch" \
--arg dispatch_id "$dispatchId" \
--arg branch_name "${{github.head_ref}}" \
--arg wait-for-completion "true" \
'{ref: $ref, inputs: {dispatch_id: $dispatch_id, branch_name: $branch_name, wait_for_completion: $wait-for-completion}}'
# json_payload=$(jq -n \
# --arg ref "PETOSS-536-enabling-workflow-dispatch" \
# --arg dispatch_id "$dispatchId" \
# --arg branch_name "${{github.head_ref}}" \
# --arg wait-for-completion "true" \
# '{ref: $ref, inputs: {dispatch_id: $dispatch_id, branch_name: $branch_name, wait_for_completion: $wait-for-completion}}'

)
curl -X POST \
-H 'Authorization: Bearer ${{ steps.get_access_token.outputs.result }}' \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/pr.yml/dispatches \
-d "$json_payload"
# )
# curl -X POST \
# -H 'Authorization: Bearer ${{ steps.get_access_token.outputs.result }}' \
# -H "Accept: application/vnd.github.everest-preview+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/pr.yml/dispatches \
# -d "$json_payload"

# - name: Get workflow run ID
# id: get-run-id
Expand All @@ -90,18 +105,18 @@ jobs:
# echo "workflow run ID: $run_id"
# fi

- name: Get workflow run ID
id: get-run-id
run: |
workflow_run=$(curl -s \
-H 'Authorization: Bearer ${{ steps.get_access_token.outputs.result }}' \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/pr.yml/runs \
| jq -r '.workflow_runs[0]')
# - name: Get workflow run ID
# id: get-run-id
# run: |
# workflow_run=$(curl -s \
# -H 'Authorization: Bearer ${{ steps.get_access_token.outputs.result }}' \
# -H "Accept: application/vnd.github.everest-preview+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/pr.yml/runs \
# | jq -r '.workflow_runs[0]')

echo "workflow run: $workflow_run"
# echo "workflow run: $workflow_run"

run_id=(echo $workflow_run | jq -r '.id')
# run_id=(echo $workflow_run | jq -r '.id')

echo "workflow run ID: $run_id"
# echo "workflow run ID: $run_id"

0 comments on commit 2f6f784

Please sign in to comment.