|
| 1 | +name: "(Tag): Prepare" |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: write |
| 5 | + pull-requests: write |
| 6 | + actions: read |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + version: |
| 12 | + description: 'Version to create the tag for (e.g. 3.6.9) or `next`' |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + default: next |
| 16 | + |
| 17 | +jobs: |
| 18 | + version: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + tag: ${{ steps.version.outputs.version }} |
| 22 | + steps: |
| 23 | + - name: Checkout branch for release |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Get tag version from package.json |
| 27 | + id: version |
| 28 | + run: | |
| 29 | + INPUT_VERSION=${{ github.event.inputs.version }} |
| 30 | + if [ -z "$INPUT_VERSION" ]; then |
| 31 | + echo "::info:: No version input provided, defaulting to 'next'." |
| 32 | + INPUT_VERSION="next" |
| 33 | + fi |
| 34 | +
|
| 35 | + if [ $INPUT_VERSION = "next" ]; then |
| 36 | + CURR=$(jq -r .version package.json) |
| 37 | + MAJOR=$(echo $CURR | cut -d. -f1) |
| 38 | + MINOR=$(echo $CURR | cut -d. -f2) |
| 39 | + PATCH=$(echo $CURR | cut -d. -f3) |
| 40 | + NEW_PATCH=$((PATCH+1)) |
| 41 | + NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH" |
| 42 | + VERSION="$NEW_VERSION" |
| 43 | + else |
| 44 | + VERSION="${{ github.event.inputs.version }}" |
| 45 | + fi |
| 46 | + |
| 47 | + if [ -z "$VERSION" ]; then |
| 48 | + echo "::error::Version is empty. Failing job." |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 52 | +
|
| 53 | + changelog: |
| 54 | + runs-on: ubuntu-latest |
| 55 | + needs: version |
| 56 | + strategy: |
| 57 | + matrix: |
| 58 | + include: |
| 59 | + - target-file: "CHANGELOG.md" |
| 60 | + template: "changelog" |
| 61 | + name: "github-changelog" |
| 62 | + - target-file: "src/readme.txt" |
| 63 | + template: "readme" |
| 64 | + name: "wordpress-readme" |
| 65 | + steps: |
| 66 | + - name: Validate repository access |
| 67 | + id: validate |
| 68 | + env: |
| 69 | + GH_TOKEN: ${{ secrets.CHANGELOG_PAT || github.token }} |
| 70 | + run: | |
| 71 | + target_repo="codesnippetspro/.github-private" |
| 72 | + workflow_file="changelog.yml" |
| 73 | + |
| 74 | + echo "::notice::Validating access to $target_repo..." |
| 75 | + |
| 76 | + # Test repository access |
| 77 | + if ! gh repo view "$target_repo" >/dev/null 2>&1; then |
| 78 | + echo "::error::Cannot access repository $target_repo" |
| 79 | + echo "::error::Please ensure CHANGELOG_PAT secret is configured with access to private repositories" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | + |
| 83 | + echo "::notice::Repository access confirmed" |
| 84 | + |
| 85 | + # Verify workflow file exists |
| 86 | + if ! gh workflow view "$workflow_file" --repo "$target_repo" >/dev/null 2>&1; then |
| 87 | + echo "::error::Workflow file '$workflow_file' not found in $target_repo" |
| 88 | + echo "::error::Expected: https://github.com/$target_repo/blob/main/.github/workflows/$workflow_file" |
| 89 | + exit 1 |
| 90 | + fi |
| 91 | + |
| 92 | + echo "::notice::Workflow file '$workflow_file' found" |
| 93 | + echo "target_repo=$target_repo" >> $GITHUB_OUTPUT |
| 94 | + echo "workflow_file=$workflow_file" >> $GITHUB_OUTPUT |
| 95 | +
|
| 96 | + - name: Dispatch changelog workflow |
| 97 | + id: dispatch |
| 98 | + env: |
| 99 | + GH_TOKEN: ${{ secrets.CHANGELOG_PAT || github.token }} |
| 100 | + run: | |
| 101 | + target_repo="${{ steps.validate.outputs.target_repo }}" |
| 102 | + workflow_file="${{ steps.validate.outputs.workflow_file }}" |
| 103 | + |
| 104 | + echo "::notice::Dispatching workflow '$workflow_file' for ${{ matrix.name }}..." |
| 105 | + echo " Repository: $target_repo" |
| 106 | + echo " Version: ${{ needs.version.outputs.tag }}" |
| 107 | + echo " Template: ${{ matrix.template }}" |
| 108 | + echo " Target file: ${{ matrix.target-file }}" |
| 109 | + |
| 110 | + # Dispatch the workflow with required parameters |
| 111 | + if ! gh workflow run "$workflow_file" \ |
| 112 | + --repo "$target_repo" \ |
| 113 | + --ref main \ |
| 114 | + --field repo="${{ github.repository }}" \ |
| 115 | + --field branch="${{ github.ref_name }}" \ |
| 116 | + --field version="${{ needs.version.outputs.tag }}" \ |
| 117 | + --field template="${{ matrix.template }}" \ |
| 118 | + --field target-file="./${{ matrix.target-file }}"; then |
| 119 | + echo "::error::Failed to dispatch workflow '$workflow_file' in $target_repo" |
| 120 | + exit 1 |
| 121 | + fi |
| 122 | + |
| 123 | + echo "::notice::Successfully dispatched changelog generation" |
| 124 | + |
| 125 | + # Wait a moment for the run to be created |
| 126 | + echo "Waiting for workflow run to be created..." |
| 127 | + sleep 10 |
| 128 | + |
| 129 | + # Get the workflow run URL for monitoring |
| 130 | + if run_url=$(gh run list --repo "$target_repo" --workflow "$workflow_file" --limit 1 --json url -q '.[0].url' 2>/dev/null); then |
| 131 | + if [ -n "$run_url" ] && [ "$run_url" != "null" ]; then |
| 132 | + echo "::notice::Workflow run: $run_url" |
| 133 | + echo "run_url=$run_url" >> $GITHUB_OUTPUT |
| 134 | + fi |
| 135 | + fi |
| 136 | +
|
| 137 | + - name: Monitor workflow completion |
| 138 | + env: |
| 139 | + GH_TOKEN: ${{ secrets.CHANGELOG_PAT || github.token }} |
| 140 | + run: | |
| 141 | + target_repo="${{ steps.validate.outputs.target_repo }}" |
| 142 | + workflow_file="${{ steps.validate.outputs.workflow_file }}" |
| 143 | + max_attempts=30 |
| 144 | + attempt=0 |
| 145 | + |
| 146 | + echo "::notice::Monitoring workflow completion..." |
| 147 | + |
| 148 | + while [ $attempt -lt $max_attempts ]; do |
| 149 | + attempt=$((attempt + 1)) |
| 150 | + |
| 151 | + # Get latest run status |
| 152 | + run_data=$(gh run list \ |
| 153 | + --repo "$target_repo" \ |
| 154 | + --workflow "$workflow_file" \ |
| 155 | + --limit 1 \ |
| 156 | + --json status,conclusion,url \ |
| 157 | + -q '.[0] | [.status, .conclusion, .url] | @tsv' 2>/dev/null) |
| 158 | + |
| 159 | + if [ -n "$run_data" ]; then |
| 160 | + status=$(echo "$run_data" | cut -f1) |
| 161 | + conclusion=$(echo "$run_data" | cut -f2) |
| 162 | + url=$(echo "$run_data" | cut -f3) |
| 163 | + |
| 164 | + if [ "$status" = "completed" ]; then |
| 165 | + if [ "$conclusion" = "success" ]; then |
| 166 | + echo "::notice::Workflow completed successfully!" |
| 167 | + echo "::notice::Run details: $url" |
| 168 | + break |
| 169 | + else |
| 170 | + echo "::error::Workflow failed with conclusion: $conclusion" |
| 171 | + echo "::error::Run details: $url" |
| 172 | + exit 1 |
| 173 | + fi |
| 174 | + else |
| 175 | + echo "Attempt $attempt/$max_attempts: Workflow status: $status" |
| 176 | + fi |
| 177 | + else |
| 178 | + echo "Attempt $attempt/$max_attempts: Waiting for workflow run data..." |
| 179 | + fi |
| 180 | + |
| 181 | + if [ $attempt -eq $max_attempts ]; then |
| 182 | + echo "::warning::Timeout reached after $max_attempts attempts" |
| 183 | + echo "::warning::Workflow may still be running. Check manually: ${{ steps.dispatch.outputs.run_url }}" |
| 184 | + exit 0 |
| 185 | + fi |
| 186 | + |
| 187 | + sleep 10 |
| 188 | + done |
0 commit comments