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
name: Trigger Target Workflow | |
on: | |
push: | |
branches: | |
- develop | |
paths: | |
- 'doc/man1/**' | |
- 'doc/man7/**' | |
jobs: | |
trigger: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 2 | |
- name: Trigger Workflow in Another Repository | |
run: | | |
# Set the required variables | |
repo_owner="mattsmida" | |
repo_name="ti.net" | |
event_type="trigger-workflow" | |
service="the-push-service" | |
version="v0.0.3" | |
# Get the list of changed filenames | |
changed_filenames=$(git -C $GITHUB_WORKSPACE diff --name-only HEAD~1) | |
formatted_changed_filenames="[$(echo "$changed_filenames" | sed 's/$/,/' | tr -d '\n' | sed 's/,$//')]" | |
# Initialize an empty array to store base64 encoded file contents | |
base64_encoded_files=() | |
# Loop through each changed file, base64 encode it, append to array | |
while IFS= read -r filename; do | |
base64_encoded_file=$(base64 "$filename" | tr -d '\n') | |
base64_encoded_files+=("$base64_encoded_file") | |
done <<< "$changed_filenames" | |
# Join the base64 encoded file contents with a comma | |
encoded_file_contents=$(IFS=","; echo "${base64_encoded_files[*]}") | |
# Construct the changed_filenames as an array-like list with filenames surrounded by single quotes | |
formatted_changed_filenames="[\"$(echo "$changed_filenames" | sed "s/.*/'&'/")\"]" | |
# Construct the encoded_file_contents as an array-like list of quoted base64 encoded file contents | |
formatted_encoded_file_contents="[${base64_encoded_files[@]}]" | |
# Update the curl command with the formatted changed_filenames and encoded_file_contents | |
curl -L \ | |
-X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ secrets.PAT }}" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/$repo_owner/$repo_name/dispatches \ | |
-d "{\"event_type\": \"$event_type\", \"client_payload\": {\"service\": \"$service\", \"version\": \"$version\", \"unit\": false, \"integration\": true, \"changed_filenames\": $formatted_changed_filenames, \"encoded_file_contents\": $formatted_encoded_file_contents}}" |