@@ -245,8 +245,135 @@ jobs:
245245 echo "reason=$REASON" >> $GITHUB_OUTPUT
246246 echo "Next version: ${NEXT_VERSION}, tag will be: modules/${MODULE}/${NEXT_VERSION} ($REASON)"
247247
248- - name : Generate changelog
248+ - name : Check go.mod for major version v2+
249249 if : steps.skipcheck.outputs.changed == 'true'
250+ id : check_module_path
251+ run : |
252+ set -euo pipefail
253+ MODULE="${{ steps.version.outputs.module }}"
254+ VERSION="${{ steps.version.outputs.next_version }}"
255+
256+ # Extract major version from VERSION (e.g., v2.0.0 -> 2)
257+ MAJOR_VERSION="${VERSION#v}"
258+ MAJOR_VERSION="${MAJOR_VERSION%%.*}"
259+
260+ echo "Major version: $MAJOR_VERSION"
261+ echo "major_version=$MAJOR_VERSION" >> $GITHUB_OUTPUT
262+
263+ # Only check go.mod if major version is 2 or greater
264+ if [ "$MAJOR_VERSION" -ge 2 ]; then
265+ GO_MOD_PATH="modules/${MODULE}/go.mod"
266+ CURRENT_MODULE_PATH=$(grep "^module " "$GO_MOD_PATH" | awk '{print $2}')
267+ echo "Current module path: $CURRENT_MODULE_PATH"
268+ echo "current_module_path=$CURRENT_MODULE_PATH" >> $GITHUB_OUTPUT
269+
270+ # Check if module path already has version suffix
271+ if [[ "$CURRENT_MODULE_PATH" =~ /v[0-9]+$ ]]; then
272+ # Extract current major version from module path
273+ CURRENT_MAJOR="${CURRENT_MODULE_PATH##*/v}"
274+ echo "Current module path has version suffix: v$CURRENT_MAJOR"
275+
276+ if [ "$CURRENT_MAJOR" -ne "$MAJOR_VERSION" ]; then
277+ echo "ERROR: Module path has /v${CURRENT_MAJOR} but releasing v${MAJOR_VERSION}"
278+ echo "Please manually update module path in ${GO_MOD_PATH} to include /v${MAJOR_VERSION}"
279+ exit 1
280+ fi
281+ echo "Module path already correct for v${MAJOR_VERSION}"
282+ echo "needs_update=false" >> $GITHUB_OUTPUT
283+ else
284+ # No version suffix, need to add it
285+ echo "Module path needs v${MAJOR_VERSION} suffix"
286+ echo "needs_update=true" >> $GITHUB_OUTPUT
287+ NEW_MODULE_PATH="${CURRENT_MODULE_PATH}/v${MAJOR_VERSION}"
288+ echo "new_module_path=$NEW_MODULE_PATH" >> $GITHUB_OUTPUT
289+ fi
290+ else
291+ echo "Major version is $MAJOR_VERSION (< 2), no module path update needed"
292+ echo "needs_update=false" >> $GITHUB_OUTPUT
293+ fi
294+
295+ - name : Create PR for module path update
296+ if : steps.skipcheck.outputs.changed == 'true' && steps.check_module_path.outputs.needs_update == 'true'
297+ run : |
298+ set -euo pipefail
299+ MODULE="${{ steps.version.outputs.module }}"
300+ VERSION="${{ steps.version.outputs.next_version }}"
301+ MAJOR_VERSION="${{ steps.check_module_path.outputs.major_version }}"
302+ CURRENT_MODULE_PATH="${{ steps.check_module_path.outputs.current_module_path }}"
303+ NEW_MODULE_PATH="${{ steps.check_module_path.outputs.new_module_path }}"
304+
305+ # Create a new branch for the module path update
306+ BRANCH_NAME="chore/${MODULE}-update-module-path-v${MAJOR_VERSION}"
307+ git checkout -b "$BRANCH_NAME"
308+
309+ # Update the module path in go.mod
310+ GO_MOD_PATH="modules/${MODULE}/go.mod"
311+ sed -i "s|^module ${CURRENT_MODULE_PATH}|module ${NEW_MODULE_PATH}|" "$GO_MOD_PATH"
312+
313+ # Run go mod tidy to ensure consistency
314+ cd "modules/${MODULE}"
315+ go mod tidy
316+ cd ../..
317+
318+ # Commit the change
319+ git config user.name 'github-actions[bot]'
320+ git config user.email 'github-actions[bot]@users.noreply.github.com'
321+ git add "modules/${MODULE}/go.mod"
322+ # Add go.sum if it was modified
323+ git add "modules/${MODULE}/go.sum" 2>/dev/null || true
324+ git commit -m "chore(${MODULE}): update module path for v${MAJOR_VERSION}
325+
326+ This updates the ${MODULE} module path from :
327+ ${CURRENT_MODULE_PATH}
328+ to :
329+ ${NEW_MODULE_PATH}
330+
331+ This is required for releasing version ${VERSION} according to Go module versioning requirements.
332+ See https://go.dev/blog/v2-go-modules for more information."
333+
334+ # Push the branch
335+ git push origin "$BRANCH_NAME"
336+
337+ # Create the PR
338+ gh pr create \
339+ --title "chore(${MODULE}) : update module path for v${MAJOR_VERSION}" \
340+ --body "## Module Path Update for ${MODULE} ${VERSION}
341+
342+ This PR updates the module path in \`modules/${MODULE}/go.mod\` to include the \`/v${MAJOR_VERSION}\` suffix as required by Go module versioning for major versions 2 and above.
343+
344+ # ## Changes:
345+ - **Module**: ${MODULE}
346+ - **Old module path**: \`${CURRENT_MODULE_PATH}\`
347+ - **New module path**: \`${NEW_MODULE_PATH}\`
348+
349+ # ## Why This Change Is Needed:
350+ According to Go module versioning requirements, when releasing a major version v2 or higher, the module path must include a version suffix. This ensures proper dependency resolution and prevents conflicts with v0/v1 versions.
351+
352+ Reference : https://go.dev/blog/v2-go-modules
353+
354+ # ## Next Steps:
355+ 1. Review and merge this PR
356+ 2. After merging, re-run the module release workflow for **${MODULE}** to complete the ${VERSION} release
357+
358+ This PR was automatically created by the module release workflow." \
359+ --base "${{ github.ref_name }}" \
360+ --head "$BRANCH_NAME"
361+
362+ echo "✓ Created PR for module path update"
363+ echo ""
364+ echo "============================================"
365+ echo "⚠️ RELEASE PAUSED"
366+ echo "============================================"
367+ echo ""
368+ echo "A PR has been created to update the module path for ${MODULE} v${MAJOR_VERSION}."
369+ echo "Please merge the PR, then re-run this release workflow to complete the release."
370+ echo ""
371+ exit 1
372+ env :
373+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
374+
375+ - name : Generate changelog
376+ if : steps.skipcheck.outputs.changed == 'true' && steps.check_module_path.outputs.needs_update != 'true'
250377 run : |
251378 MODULE=${{ steps.version.outputs.module }}
252379 TAG=${{ steps.version.outputs.tag }}
@@ -304,7 +431,7 @@ jobs:
304431 echo "Generated changelog for $MODULE"
305432
306433 - name : Create release
307- if : steps.skipcheck.outputs.changed == 'true'
434+ if : steps.skipcheck.outputs.changed == 'true' && steps.check_module_path.outputs.needs_update != 'true'
308435 id : create_release
309436 run : |
310437 gh release create ${{ steps.version.outputs.tag }} \
@@ -334,12 +461,25 @@ jobs:
334461 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
335462
336463 - name : Announce to Go proxy
337- if : steps.skipcheck.outputs.changed == 'true'
464+ if : steps.skipcheck.outputs.changed == 'true' && steps.check_module_path.outputs.needs_update != 'true'
338465 run : |
466+ set -euo pipefail
339467 VERSION=${{ steps.version.outputs.next_version }}
340- MODULE_NAME="github.com/CrisisTextLine/modular/modules/${{ steps.version.outputs.module }}"
468+ MODULE="${{ steps.version.outputs.module }}"
469+
470+ # Extract major version from VERSION
471+ MAJOR_VERSION="${VERSION#v}"
472+ MAJOR_VERSION="${MAJOR_VERSION%%.*}"
473+
474+ # Construct correct module path with version suffix for v2+
475+ if [ "$MAJOR_VERSION" -ge 2 ]; then
476+ MODULE_NAME="github.com/CrisisTextLine/modular/modules/${MODULE}/v${MAJOR_VERSION}"
477+ else
478+ MODULE_NAME="github.com/CrisisTextLine/modular/modules/${MODULE}"
479+ fi
341480
342- go get ${MODULE_NAME}@${VERSION}
481+ echo "Announcing ${MODULE_NAME}@${VERSION} to Go proxy..."
482+ GOPROXY=proxy.golang.org go list -m ${MODULE_NAME}@${VERSION}
343483
344- echo "Announced version ${{steps.version.outputs.module} }@${VERSION} to Go proxy"
484+ echo "✓ Announced version ${MODULE }@${VERSION} to Go proxy"
345485
0 commit comments