Skip to content

Commit

Permalink
feat: Trigger other Benchmark workflows (#106)
Browse files Browse the repository at this point in the history
* feat: bash script to trigger other workflow files

Signed-off-by: Dipankar Das <[email protected]>

* added error handling

Signed-off-by: Dipankar Das <[email protected]>

* added temporary error handling of ghtoken escape

Signed-off-by: Dipankar Das <[email protected]>

* improved the curl requests

Signed-off-by: Dipankar Das <[email protected]>

* updated the final reviewd codebase

Signed-off-by: Dipankar Das <[email protected]>

* Updated the dispatch file name

Signed-off-by: Dipankar Das <[email protected]>

* updated the logging

Signed-off-by: Dipankar Das <[email protected]>

* added the handling of sub_components

Signed-off-by: Dipankar Das <[email protected]>

* fix the workflow_dispatch

Signed-off-by: Dipankar Das <[email protected]>

* improved the logging

Signed-off-by: Dipankar Das <[email protected]>

---------

Signed-off-by: Dipankar Das <[email protected]>
  • Loading branch information
dipankardas011 committed Jun 24, 2024
1 parent fe0a5b2 commit 6be6e66
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/workflows/project-trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Reconciles Project Versions and triggers them

on:
schedule:
- cron: '0 8 * * *'
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
get-latest-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
sudo apt update -y
sudo apt install jq -y
- name: trigger the workflows
working-directory: scripts
env:
GH_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
run: |
bash project-trigger.sh
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
infrastructure/equinix-metal/.terraform/
infrastructure/equinix-metal/terraform.tfvars
infrastructure/equinix-metal/.terraform.lock.hcl
infrastructure/equinix-metal/.terraform.lock.hcl
.idea
13 changes: 13 additions & 0 deletions projects/projects.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"projects": [
{
"name": "falco",
"organization": "falcosecurity",
"sub_components": [
"ebpf",
"modern-ebpf",
"kmod"
]
}
]
}
81 changes: 81 additions & 0 deletions scripts/project-trigger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash


json_file="../projects/projects.json"
gh_token=$GH_TOKEN
git_ref="main"
workflow_organization_name="cncf-tags"
workflow_project_name="green-reviews-tooling"
workflow_dispatcher_file_name="benchmark-pipeline.yaml"

if [ -z "$gh_token" ]; then
echo "GH_TOKEN not set"
exit 20
fi

jq -c '.projects[]' "$json_file" | while read -r project; do
proj_name=$(echo "$project" | jq -r '.name')
proj_organization=$(echo "$project" | jq -r '.organization')
sub_components=$(echo "$project" | jq -r '.sub_components')

echo "Project Name: $proj_name"
echo "Organization: $proj_organization"
echo "SubComponents: $sub_components"

release_url="https://api.github.com/repos/${proj_organization}/${proj_name}/releases/latest"


response=$(curl --fail-with-body -sSL -X GET $release_url)
status_code=$?
if [ $status_code -ne 0 ]; then
echo "fetching latest release for ${proj_name} from ${release_url}. Status code: $status_code"
echo "curl Response: $response"
continue
fi

latest_proj_version=$(echo "$response" | jq -r '.tag_name')
if [ -z "$latest_proj_version" ]; then
echo "could not find the latest version for ${proj_name}"
continue
fi

echo "latest version: $latest_proj_version"

if [ "$sub_components" == "null" ]; then
echo "$proj_name has no sub components triggering pipeline once"
workflow_dispatch=$(curl --fail-with-body -sSL -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $gh_token" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$workflow_organization_name/$workflow_project_name/actions/workflows/$workflow_dispatcher_file_name/dispatches" \
-d "{\"ref\":\"${git_ref}\",\"inputs\":{\"cncf_project\":\"${proj_name}\",\"cncf_project_sub\":\"\",\"version\":\"${latest_proj_version}\"}}")

status_code=$?
if [ $status_code -ne 0 ]; then
echo "dispatching workflow for [proj: ${proj_name}, ver: $latest_proj_version] Status code: $status_code"
echo "curl response: $workflow_dispatch"
continue
fi

echo "workflow_call event [proj: $proj_name, ver: $latest_proj_version]=> OK"
else
echo "$proj_name has sub-components triggering pipeline once per sub-component"
for sub_component in $(echo "$sub_components" | jq -r '.[]'); do
workflow_dispatch=$(curl --fail-with-body -sSL -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $gh_token" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$workflow_organization_name/$workflow_project_name/actions/workflows/$workflow_dispatcher_file_name/dispatches" \
-d "{\"ref\":\"${git_ref}\",\"inputs\":{\"cncf_project\":\"${proj_name}\",\"cncf_project_sub\":\"${sub_component}\",\"version\":\"${latest_proj_version}\"}}")

status_code=$?
if [ $status_code -ne 0 ]; then
echo "dispatching workflow for [proj: ${proj_name}, component: $sub_component, ver: $latest_proj_version] Status code: $status_code"
echo "curl response: $workflow_dispatch"
continue
fi

echo "workflow_call event [proj: $proj_name, component: $sub_component, ver: $latest_proj_version]=> OK"
done
fi
done

0 comments on commit 6be6e66

Please sign in to comment.