Skip to content

Commit

Permalink
feat: bash script to trigger other workflow files
Browse files Browse the repository at this point in the history
Signed-off-by: Dipankar Das <[email protected]>
  • Loading branch information
dipankardas011 committed Jun 19, 2024
1 parent eb0b41d commit ed05fa1
Show file tree
Hide file tree
Showing 4 changed files with 84 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 0 * * 0'
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
infrastructure/equinix-metal/.terraform/
infrastructure/equinix-metal/terraform.tfvars
infrastructure/equinix-metal/.terraform.lock.hcl
infrastructure/equinix-metal/.terraform.lock.hcl
website/public/
website/resources/
website/node_modules/
.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"
]
}
]
}
36 changes: 36 additions & 0 deletions scripts/project-trigger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash


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


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"

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


latest_proj_version=$(curl -fsSL -X GET $releaseUrl | jq -r '.tag_name')
echo "Version: $latest_proj_version"


workflow_dispatch=$(curl -fsSL -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\":\"main\",\"inputs\":{\"cncf_project\":\"${proj_name}\",\"cncf_project_sub\":\"${sub_components}\",\"version\":\"${latest_proj_version}\"}}")

echo "workflow_call event [proj: $proj_name]=> $workflow_dispatch"
echo "-----------------------------"
done

0 comments on commit ed05fa1

Please sign in to comment.