fix: update workflow reference for tag computation #41
This file contains hidden or 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: "(Tag): Prepare" | ||
Check failure on line 1 in .github/workflows/prepare-tag.yml
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
actions: read | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: 'Version to create the tag for (e.g. 3.6.9) or `next`' | ||
required: true | ||
type: string | ||
default: next | ||
changelog_path: | ||
description: 'Relative path to changelog in calling repo' | ||
required: false | ||
type: string | ||
default: ./CHANGELOG.md | ||
readme_path: | ||
description: 'Relative path to readme file in calling repo' | ||
required: false | ||
type: string | ||
default: ./src/readme.txt | ||
model: | ||
description: 'LLM model to use for generation' | ||
required: false | ||
type: string | ||
default: gpt-5-mini | ||
jobs: | ||
version: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
tag: ${{ steps.compute.outputs.version || github.event.inputs.version }} | ||
steps: | ||
- name: Compute tag when input is 'next' | ||
if: ${{ github.event.inputs.version == 'next' }} | ||
id: compute | ||
uses: codesnippetspro/.github/workflows/next_version.yml | ||
with: | ||
file_path: package.json | ||
ref_name: ${{ github.ref_name }} | ||
changelog: | ||
runs-on: ubuntu-latest | ||
needs: version | ||
steps: | ||
- name: Validate repository access | ||
id: validate | ||
env: | ||
GH_TOKEN: ${{ secrets.CHANGELOG_PAT || github.token }} | ||
run: | | ||
target_repo="codesnippetspro/.github-private" | ||
workflow_file="changelog.yml" | ||
echo "::notice::Validating access to $target_repo..." | ||
# Test repository access | ||
if ! gh repo view "$target_repo" >/dev/null 2>&1; then | ||
echo "::error::Cannot access repository $target_repo" | ||
echo "::error::Please ensure CHANGELOG_PAT secret is configured with access to private repositories" | ||
exit 1 | ||
fi | ||
echo "::notice::Repository access confirmed" | ||
# Verify workflow file exists | ||
if ! gh workflow view "$workflow_file" --repo "$target_repo" >/dev/null 2>&1; then | ||
echo "::error::Workflow file '$workflow_file' not found in $target_repo" | ||
echo "::error::Expected: https://github.com/$target_repo/blob/main/.github/workflows/$workflow_file" | ||
exit 1 | ||
fi | ||
echo "::notice::Workflow file '$workflow_file' found" | ||
echo "target_repo=$target_repo" >> $GITHUB_OUTPUT | ||
echo "workflow_file=$workflow_file" >> $GITHUB_OUTPUT | ||
- name: Dispatch changelog workflow | ||
id: dispatch | ||
env: | ||
GH_TOKEN: ${{ secrets.CHANGELOG_PAT || github.token }} | ||
run: | | ||
target_repo="${{ steps.validate.outputs.target_repo }}" | ||
workflow_file="${{ steps.validate.outputs.workflow_file }}" | ||
echo "::notice::Dispatching workflow '$workflow_file' to generate changelog and readme entries..." | ||
echo " Calling repo: $target_repo" | ||
echo " Version: ${{ needs.version.outputs.tag }}" | ||
echo " Changelog path: ${GITHUB_EVENT_INPUTS_CHANGELOG_PATH:-./CHANGELOG.md}" | ||
echo " Readme path: ${GITHUB_EVENT_INPUTS_README_PATH:-./src/readme.txt}" | ||
# Dispatch the workflow with required parameters | ||
if ! gh workflow run "$workflow_file" \ | ||
--repo "$target_repo" \ | ||
--ref main \ | ||
--field repo="${{ github.repository }}" \ | ||
--field branch="${{ github.ref_name }}" \ | ||
--field version="${{ needs.version.outputs.tag }}" \ | ||
--field changelog_path="${{ github.event.inputs.changelog_path || './CHANGELOG.md' }}" \ | ||
--field readme_path="${{ github.event.inputs.readme_path || './src/readme.txt' }}" \ | ||
--field model="${{ github.event.inputs.model || 'gpt-5-mini' }}"; then | ||
echo "::error::Failed to dispatch workflow '$workflow_file' in $target_repo" | ||
exit 1 | ||
fi | ||
echo "::notice::Successfully dispatched changelog generation" | ||
# Wait a moment for the run to be created | ||
echo "Waiting for workflow run to be created..." | ||
sleep 10 | ||
# Get the workflow run URL for monitoring | ||
if run_url=$(gh run list --repo "$target_repo" --workflow "$workflow_file" --limit 1 --json url -q '.[0].url' 2>/dev/null); then | ||
if [ -n "$run_url" ] && [ "$run_url" != "null" ]; then | ||
echo "::notice::Workflow run: $run_url" | ||
echo "run_url=$run_url" >> $GITHUB_OUTPUT | ||
fi | ||
fi | ||
- name: Monitor workflow completion | ||
env: | ||
GH_TOKEN: ${{ secrets.CHANGELOG_PAT || github.token }} | ||
run: | | ||
target_repo="${{ steps.validate.outputs.target_repo }}" | ||
workflow_file="${{ steps.validate.outputs.workflow_file }}" | ||
max_attempts=30 | ||
attempt=0 | ||
echo "::notice::Monitoring workflow completion..." | ||
while [ $attempt -lt $max_attempts ]; do | ||
attempt=$((attempt + 1)) | ||
# Get latest run status | ||
run_data=$(gh run list \ | ||
--repo "$target_repo" \ | ||
--workflow "$workflow_file" \ | ||
--limit 1 \ | ||
--json status,conclusion,url \ | ||
-q '.[0] | [.status, .conclusion, .url] | @tsv' 2>/dev/null) | ||
if [ -n "$run_data" ]; then | ||
status=$(echo "$run_data" | cut -f1) | ||
conclusion=$(echo "$run_data" | cut -f2) | ||
url=$(echo "$run_data" | cut -f3) | ||
if [ "$status" = "completed" ]; then | ||
if [ "$conclusion" = "success" ]; then | ||
echo "::notice::Workflow completed successfully!" | ||
echo "::notice::Run details: $url" | ||
break | ||
else | ||
echo "::error::Workflow failed with conclusion: $conclusion" | ||
echo "::error::Run details: $url" | ||
exit 1 | ||
fi | ||
else | ||
echo "Attempt $attempt/$max_attempts: Workflow status: $status" | ||
fi | ||
else | ||
echo "Attempt $attempt/$max_attempts: Waiting for workflow run data..." | ||
fi | ||
if [ $attempt -eq $max_attempts ]; then | ||
echo "::warning::Timeout reached after $max_attempts attempts" | ||
echo "::warning::Workflow may still be running. Check manually: ${{ steps.dispatch.outputs.run_url }}" | ||
exit 0 | ||
fi | ||
sleep 10 | ||
done |