Skip to content

Re-enable Disabled Workflows #44

Re-enable Disabled Workflows

Re-enable Disabled Workflows #44

name: Re-enable Disabled Workflows
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 1' # Once a week: Monday at 00:00 UTC
jobs:
re-enable-workflows:
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Re-enable disabled workflows across repositories
env:
TOKEN: ${{ secrets.ENABLE_WORKFLOWS_TOKEN }}
run: |
set -uo pipefail
failure=false
failure_messages=()
echo "Checking for disabled workflows..."
# Search for repos
REPO_LIST=""
tmplist=/tmp/repos_code_search.txt
: > "$tmplist"
public_repos=$(curl -s -w "%{http_code}" -o /tmp/search_normal.json \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/search/code?q=org:Kuadrant+path:.github/workflows+schedule%3A&per_page=100")
if [ "$public_repos" != "200" ]; then
echo "Failed to search repositories (non-forks) (HTTP $public_repos)"
failure_messages+=("Failed to search repositories (non-forks) (HTTP $public_repos)")
failure=true
else
jq -r '.items[].repository.name' /tmp/search_normal.json >> "$tmplist" || true
fi
fork_repos=$(curl -s -w "%{http_code}" -o /tmp/search_forks.json \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/search/code?q=org:Kuadrant+fork:true+path:.github/workflows+schedule%3A&per_page=100")
if [ "$fork_repos" != "200" ]; then
echo "Failed to search repositories (forks) (HTTP $fork_repos)"
failure_messages+=("Failed to search repositories (forks) (HTTP $fork_repos)")
failure=true
else
jq -r '.items[].repository.name' /tmp/search_forks.json >> "$tmplist" || true
fi
if [ -s "$tmplist" ]; then
REPO_LIST="$(sort -u "$tmplist")"
fi
if [ -z "$REPO_LIST" ]; then
echo "No repositories found."
for msg in "${failure_messages[@]}"; do
echo "- $msg"
done
exit 1
fi
echo "Repositories found:"
echo "$REPO_LIST"
# Check repos for disabled workflows
while IFS= read -r repo; do
repo="$(echo "$repo" | xargs || true)"
[ -z "$repo" ] && continue
printf "\n=== Repository: Kuadrant/%s ===\n" "$repo"
url="https://api.github.com/repos/Kuadrant/$repo/actions/workflows?per_page=100"
response_code=$(curl -s -w "%{http_code}" -o /tmp/workflows.json \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/vnd.github+json" \
"$url")
if [ "$response_code" -ne 200 ]; then
echo "Failed to fetch workflows for $repo (HTTP $response_code)"
cat /tmp/workflows.json || true
resp_snippet=$(head -c 500 /tmp/workflows.json 2>/dev/null | tr '\n' ' ')
failure_messages+=("[$repo] list workflows failed (HTTP $response_code): ${resp_snippet:-<no body>}")
failure=true
continue
fi
workflows=$(cat /tmp/workflows.json)
disabled_ids=$(echo "$workflows" | jq -r '.workflows[] | select(.state == "disabled_inactivity") | .id')
[ -z "$disabled_ids" ] && continue
# Re-enable disabled workflows
while IFS= read -r workflow_id; do
[ -n "$workflow_id" ] || continue
workflow_name=$(echo "$workflows" | jq -r --arg id "$workflow_id" '.workflows[] | select(.id == ($id | tonumber)) | .name')
echo "$workflow_name"
response=$(curl -s -w "%{http_code}" -o /tmp/response.json \
-X PUT \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/Kuadrant/$repo/actions/workflows/$workflow_id/enable")
if [ "$response" -ne 204 ]; then
echo "Failed to re-enable: $workflow_name (HTTP $response)"
cat /tmp/response.json || true
resp_snippet=$(head -c 500 /tmp/response.json 2>/dev/null | tr '\n' ' ')
failure_messages+=("[$repo] enable '$workflow_name' (id $workflow_id) failed (HTTP $response): ${resp_snippet:-<no body>}")
failure=true
fi
done <<< "$disabled_ids"
done <<< "$REPO_LIST"
# Cleanup temporary files
rm -f /tmp/workflows.json /tmp/response.json /tmp/search_normal.json /tmp/search_forks.json /tmp/repos_code_search.txt || true
if [ "$failure" = true ]; then
echo "Completed with ${#failure_messages[@]} failure(s)."
echo "Failures detail:"
for msg in "${failure_messages[@]}"; do
echo "- $msg"
done
exit 1
fi
echo "Workflow re-enablement completed successfully!"