@@ -64,32 +64,110 @@ jobs:
6464 name : " wordpress-readme"
6565 steps :
6666 - name : Dispatch changelog generation
67+ id : dispatch
6768 env :
6869 GITHUB_TOKEN : ${{ secrets.GH_TOKEN }}
6970 run : |
70-
71+ # Install latest GitHub CLI
7172 if ! command -v gh &> /dev/null; then
73+ sudo mkdir -p -m 755 /etc/apt/keyrings
74+ wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
75+ sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
76+ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
7277 sudo apt update && sudo apt install -y gh
78+ else
79+ # Check if gh version supports --json flag
80+ if ! gh workflow list --help | grep -q "\--json"; then
81+ echo "📦 Updating GitHub CLI to latest version..."
82+ sudo mkdir -p -m 755 /etc/apt/keyrings
83+ wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
84+ sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
85+ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
86+ sudo apt update && sudo apt install -y gh
87+ fi
88+ fi
89+
90+ target_repo="codesnippetspro/.github-private"
91+
92+ # Try different possible workflow names for "Changelog Generate"
93+ workflow_candidates=(
94+ "(Changelog): Generate"
95+ "Changelog Generate"
96+ "Changelog: Generate"
97+ "changelog"
98+ "generate"
99+ )
100+
101+ workflow_id=""
102+ workflow_name=""
103+
104+ # Dynamically retrieve the workflow ID by trying different name patterns
105+ echo "🔍 Searching for changelog workflow in $target_repo..."
106+
107+ for candidate in "${workflow_candidates[@]}"; do
108+ echo " Trying: '$candidate'"
109+ if workflow_info=$(gh workflow list --repo "$target_repo" --json name,id | jq -r ".[] | select(.name == \"$candidate\") | .id"); then
110+ if [ -n "$workflow_info" ] && [ "$workflow_info" != "null" ]; then
111+ workflow_id="$workflow_info"
112+ workflow_name="$candidate"
113+ echo "✅ Found workflow '$candidate' with ID: $workflow_id"
114+ break
115+ fi
116+ fi
117+ done
118+
119+ # If exact match failed, try partial matching
120+ if [ -z "$workflow_id" ]; then
121+ echo "🔍 Trying partial name matching..."
122+ if workflow_info=$(gh workflow list --repo "$target_repo" --json name,id | jq -r '.[] | select(.name | test("(?i)(changelog|generate)")) | "\(.id)|\(.name)"' | head -1); then
123+ if [ -n "$workflow_info" ] && [ "$workflow_info" != "null" ]; then
124+ workflow_id=$(echo "$workflow_info" | cut -d'|' -f1)
125+ workflow_name=$(echo "$workflow_info" | cut -d'|' -f2)
126+ echo "✅ Found workflow '$workflow_name' with ID: $workflow_id"
127+ fi
128+ fi
73129 fi
130+
74131
75- gh workflow run changelog.yml \
76- --repo codesnippetspro/.github-private --ref main \
132+ if [ -z "$workflow_id" ]; then
133+ echo "::error::No changelog workflow found in $target_repo"
134+ echo "🔍 Available workflows:"
135+ gh workflow list --repo "$target_repo" --json name,id | jq -r '.[] | " \(.name) (ID: \(.id))"'
136+ echo "skip_monitoring=true" >> $GITHUB_OUTPUT
137+ exit 0
138+ fi
139+
140+ echo "✅ Found workflow '$workflow_name' with ID: $workflow_id"
141+
142+ # Attempt to dispatch the workflow
143+ if ! gh workflow run "$workflow_id" \
144+ --repo "$target_repo" --ref main \
77145 --field repo="${{ github.repository }}" \
78146 --field branch="${{ github.ref_name }}" \
79147 --field version="${{ needs.version.outputs.tag }}" \
80148 --field template="${{ matrix.template }}" \
81- --field target-file="./${{ matrix.target-file }}"
149+ --field target-file="./${{ matrix.target-file }}"; then
150+ echo "::error::Failed to dispatch workflow '$workflow_name' in $target_repo"
151+ exit 1
152+ fi
153+
154+ echo "✅ Successfully dispatched changelog generation for ${{ matrix.name }}"
155+ echo "skip_monitoring=false" >> $GITHUB_OUTPUT
156+ echo "workflow_id=$workflow_id" >> $GITHUB_OUTPUT
157+ echo "workflow_name=$workflow_name" >> $GITHUB_OUTPUT
82158
83159 - name : Monitor workflow execution
160+ if : steps.dispatch.outputs.skip_monitoring != 'true'
84161 env :
85162 GITHUB_TOKEN : ${{ secrets.GH_TOKEN }}
86163 run : |
87- workflow_name="${{ matrix.name }}"
164+ workflow_name="${{ steps.dispatch.outputs.workflow_name }}"
165+ workflow_id="${{ steps.dispatch.outputs.workflow_id }}"
88166 target_repo="codesnippetspro/.github-private"
89- max_attempts=30 # Maximum 5 minutes (30 * 10 seconds)
167+ max_attempts=10
90168 attempt=0
91169
92- echo "Monitoring workflow: $workflow_name in repository: $target_repo"
170+ echo "Monitoring workflow: $workflow_name (ID: $workflow_id) in repository: $target_repo"
93171
94172 # Check if the repository exists and is accessible
95173 if ! gh repo view "$target_repo" >/dev/null 2>&1; then
@@ -98,38 +176,54 @@ jobs:
98176 exit 0
99177 fi
100178
179+ # Wait a bit for the workflow to start
180+ echo "⏳ Waiting 10 seconds for workflow to start..."
181+ sleep 10
182+
101183 while : ; do
102184 attempt=$((attempt + 1))
103185
104186 # Check if we've exceeded max attempts
105187 if [ $attempt -gt $max_attempts ]; then
106188 echo "::warning::Timeout reached after $max_attempts attempts. Workflow '$workflow_name' monitoring stopped."
107- echo "::warning::This might be expected if testing locally or if the workflow doesn't exist yet ."
189+ echo "::warning::This might be expected if testing locally or if the workflow takes longer than expected ."
108190 exit 0
109191 fi
110192
111- # Get the latest run for this workflow with error handling
112- if ! status=$(gh run list --workflow changelog.yml --limit 1 --json status -q '.[0].status' --repo "$target_repo" --ref main 2>/dev/null); then
113- echo "::warning::Attempt $attempt/$max_attempts: Could not find workflow '$workflow_name' or no runs exist yet. Checking again..."
193+ # Get the latest run for this workflow using the workflow ID
194+ echo "🔍 Attempt $attempt/$max_attempts: Checking workflow status..."
195+
196+ # First check if we can list any runs at all
197+ if ! gh run list --repo "$target_repo" --limit 1 --json status,conclusion,workflowDatabaseId >/dev/null 2>&1; then
198+ echo "::warning::Attempt $attempt/$max_attempts: Cannot access workflow runs in $target_repo. Checking again..."
114199 sleep 10
115200 continue
116201 fi
117202
118- if ! conclusion=$(gh run list --workflow changelog.yml --limit 1 --json conclusion -q '.[0].conclusion' --repo "$target_repo" --ref main 2>/dev/null); then
119- echo "::warning::Attempt $attempt/$max_attempts: Could not get conclusion for workflow '$workflow_name'. Checking again..."
203+ # Try to get the status of the most recent run for our workflow
204+ run_data=$(gh run list --repo "$target_repo" --limit 10 --json status,conclusion,workflowDatabaseId 2>/dev/null | jq -r ".[] | select(.workflowDatabaseId == $workflow_id) | [.status, .conclusion] | @tsv" | head -1)
205+
206+ if [ -z "$run_data" ]; then
207+ echo "⏳ Attempt $attempt/$max_attempts: No runs found for workflow ID $workflow_id yet. Checking again..."
120208 sleep 10
121209 continue
122210 fi
123211
212+ status=$(echo "$run_data" | cut -f1)
213+ conclusion=$(echo "$run_data" | cut -f2)
214+
215+ echo "📊 Workflow status: $status, conclusion: $conclusion"
216+
124217 if [ "$status" = "completed" ]; then
125- if [ "$conclusion" != "success" ]; then
126- echo "::error::Workflow $workflow_name failed with conclusion: $conclusion"
218+ if [ "$conclusion" != "success" ] && [ "$conclusion" != "null" ] ; then
219+ echo "::error::Workflow $workflow_name (ID: $workflow_id) failed with conclusion: $conclusion"
127220 exit 1
128221 fi
129- echo "✅ Workflow $workflow_name completed successfully"
222+ echo "✅ Workflow $workflow_name (ID: $workflow_id) completed successfully"
130223 break
131224 fi
132225
133- echo "⏳ Attempt $attempt/$max_attempts: Workflow $workflow_name is still running (status: $status). Waiting..."
226+ echo "⏳ Attempt $attempt/$max_attempts: Workflow $workflow_name (ID: $workflow_id) is still running (status: $status). Waiting..."
134227 sleep 10
135228 done
229+
0 commit comments