Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 68 additions & 3 deletions .github/workflows/module-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,58 @@ jobs:
echo "reason=$REASON" >> $GITHUB_OUTPUT
echo "Next version: ${NEXT_VERSION}, tag will be: modules/${MODULE}/${NEXT_VERSION} ($REASON)"

- name: Update go.mod for major version v2+
if: steps.skipcheck.outputs.changed == 'true'
run: |
set -euo pipefail
MODULE="${{ steps.version.outputs.module }}"
VERSION="${{ steps.version.outputs.next_version }}"

# Extract major version from VERSION (e.g., v2.0.0 -> 2)
MAJOR_VERSION="${VERSION#v}"
MAJOR_VERSION="${MAJOR_VERSION%%.*}"

Comment on lines +255 to +258
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The major version extraction logic is duplicated in three places in this file (lines 256-257, 396-397) and across multiple workflow files. Consider extracting this into a reusable shell function or a separate script that can be sourced by all workflows to ensure consistency and maintainability.

Suggested change
# Extract major version from VERSION (e.g., v2.0.0 -> 2)
MAJOR_VERSION="${VERSION#v}"
MAJOR_VERSION="${MAJOR_VERSION%%.*}"
# Function to extract major version from a version string (e.g., v2.0.0 -> 2)
extract_major_version() {
local ver="$1"
ver="${ver#v}"
echo "${ver%%.*}"
}
MAJOR_VERSION="$(extract_major_version "$VERSION")"

Copilot uses AI. Check for mistakes.
echo "Major version: $MAJOR_VERSION"

# Only update go.mod if major version is 2 or greater
if [ "$MAJOR_VERSION" -ge 2 ]; then
GO_MOD_PATH="modules/${MODULE}/go.mod"
CURRENT_MODULE_PATH=$(grep "^module " "$GO_MOD_PATH" | awk '{print $2}')
echo "Current module path: $CURRENT_MODULE_PATH"

# Check if module path already has version suffix
if [[ "$CURRENT_MODULE_PATH" =~ /v[0-9]+$ ]]; then
# Extract current major version from module path
CURRENT_MAJOR="${CURRENT_MODULE_PATH##*/v}"
echo "Current module path has version suffix: v$CURRENT_MAJOR"

if [ "$CURRENT_MAJOR" -ne "$MAJOR_VERSION" ]; then
echo "ERROR: Module path has /v${CURRENT_MAJOR} but releasing v${MAJOR_VERSION}"
echo "Please manually update module path in ${GO_MOD_PATH} to include /v${MAJOR_VERSION}"
exit 1
fi
echo "Module path already correct for v${MAJOR_VERSION}"
else
# No version suffix, need to add it
NEW_MODULE_PATH="${CURRENT_MODULE_PATH}/v${MAJOR_VERSION}"
echo "Updating module path to: $NEW_MODULE_PATH"

# Update the module path in go.mod
sed -i "s|^module ${CURRENT_MODULE_PATH}|module ${NEW_MODULE_PATH}|" "$GO_MOD_PATH"

# Commit the change
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add "$GO_MOD_PATH"
git commit -m "chore(${MODULE}): update module path for v${MAJOR_VERSION}"
git push origin HEAD:${{ github.ref_name }}

echo "✓ Updated module path to $NEW_MODULE_PATH"
fi
else
echo "Major version is $MAJOR_VERSION (< 2), no module path update needed"
fi

- name: Generate changelog
if: steps.skipcheck.outputs.changed == 'true'
run: |
Expand Down Expand Up @@ -336,10 +388,23 @@ jobs:
- name: Announce to Go proxy
if: steps.skipcheck.outputs.changed == 'true'
run: |
set -euo pipefail
VERSION=${{ steps.version.outputs.next_version }}
MODULE_NAME="github.com/CrisisTextLine/modular/modules/${{ steps.version.outputs.module }}"
MODULE="${{ steps.version.outputs.module }}"

# Extract major version from VERSION
MAJOR_VERSION="${VERSION#v}"
MAJOR_VERSION="${MAJOR_VERSION%%.*}"

# Construct correct module path with version suffix for v2+
if [ "$MAJOR_VERSION" -ge 2 ]; then
MODULE_NAME="github.com/CrisisTextLine/modular/modules/${MODULE}/v${MAJOR_VERSION}"
else
MODULE_NAME="github.com/CrisisTextLine/modular/modules/${MODULE}"
fi

go get ${MODULE_NAME}@${VERSION}
echo "Announcing ${MODULE_NAME}@${VERSION} to Go proxy..."
GOPROXY=proxy.golang.org go list -m ${MODULE_NAME}@${VERSION}

echo "Announced version ${{steps.version.outputs.module}}@${VERSION} to Go proxy"
echo "Announced version ${MODULE}@${VERSION} to Go proxy"

26 changes: 24 additions & 2 deletions .github/workflows/release-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,22 @@ jobs:
- name: Re-announce to Go proxy
if: steps.ensure.outputs.release_url
run: |
set -euo pipefail
CURR=$(git tag -l 'v*' | grep -v '/' | sort -V | tail -n1 || true)
[ -z "$CURR" ] && exit 0
GOPROXY=proxy.golang.org go list -m github.com/CrisisTextLine/modular@${CURR}

# Extract major version
MAJOR_VERSION="${CURR#v}"
MAJOR_VERSION="${MAJOR_VERSION%%.*}"
Comment on lines +331 to +332
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The major version extraction logic is duplicated in two places in this file (lines 331-332, 377-378) and across multiple workflow files. Consider extracting this into a reusable shell function or a separate script that can be sourced by all workflows to ensure consistency and maintainability.

Copilot uses AI. Check for mistakes.

# Construct correct module path with version suffix for v2+
if [ "$MAJOR_VERSION" -ge 2 ]; then
MODULE_NAME="github.com/CrisisTextLine/modular/v${MAJOR_VERSION}"
else
MODULE_NAME="github.com/CrisisTextLine/modular"
fi

GOPROXY=proxy.golang.org go list -m ${MODULE_NAME}@${CURR}

ensure-modules:
needs: detect
Expand Down Expand Up @@ -359,7 +372,16 @@ jobs:
TAG=$(git tag -l "modules/${M}/v*" | sort -V | tail -n1 || true)
[ -z "$TAG" ] && { echo "Module $M has no tags yet; skipping."; continue; }
VER=${TAG##*/}
MOD_PATH="github.com/CrisisTextLine/modular/modules/${M}"

# Extract major version and construct correct module path
MAJOR_VERSION="${VER#v}"
MAJOR_VERSION="${MAJOR_VERSION%%.*}"
if [ "$MAJOR_VERSION" -ge 2 ]; then
MOD_PATH="github.com/CrisisTextLine/modular/modules/${M}/v${MAJOR_VERSION}"
else
MOD_PATH="github.com/CrisisTextLine/modular/modules/${M}"
fi

if gh release view "$TAG" >/dev/null 2>&1; then
echo "Release exists for $TAG"
URL=$(gh release view "$TAG" --json url --jq .url || echo '')
Expand Down
68 changes: 66 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,57 @@ jobs:
echo "reason=$REASON" >> $GITHUB_OUTPUT
echo "Next version: $NEXT_VERSION ($REASON)"

- name: Update go.mod for major version v2+
if: steps.detect.outputs.core_changed == 'true'
run: |
set -euo pipefail
VERSION="${{ steps.version.outputs.next_version }}"

# Extract major version from VERSION (e.g., v2.0.0 -> 2)
MAJOR_VERSION="${VERSION#v}"
MAJOR_VERSION="${MAJOR_VERSION%%.*}"
Comment on lines +201 to +209
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The major version extraction logic is duplicated in three places in this file (lines 208-209, 348-349) and across multiple workflow files. Consider extracting this into a reusable shell function or a separate script that can be sourced by all workflows to ensure consistency and maintainability.

Suggested change
- name: Update go.mod for major version v2+
if: steps.detect.outputs.core_changed == 'true'
run: |
set -euo pipefail
VERSION="${{ steps.version.outputs.next_version }}"
# Extract major version from VERSION (e.g., v2.0.0 -> 2)
MAJOR_VERSION="${VERSION#v}"
MAJOR_VERSION="${MAJOR_VERSION%%.*}"
- name: Create major version extraction script
run: |
mkdir -p .github/scripts
cat > .github/scripts/extract_major_version.sh <<'EOF'
#!/bin/sh
# Usage: ./extract_major_version.sh v2.0.0
VERSION="$1"
MAJOR="${VERSION#v}"
MAJOR="${MAJOR%%.*}"
echo "$MAJOR"
EOF
chmod +x .github/scripts/extract_major_version.sh
- name: Update go.mod for major version v2+
if: steps.detect.outputs.core_changed == 'true'
run: |
set -euo pipefail
VERSION="${{ steps.version.outputs.next_version }}"
# Extract major version from VERSION (e.g., v2.0.0 -> 2) using reusable script
MAJOR_VERSION="$(.github/scripts/extract_major_version.sh "$VERSION")"

Copilot uses AI. Check for mistakes.

echo "Major version: $MAJOR_VERSION"

# Only update go.mod if major version is 2 or greater
if [ "$MAJOR_VERSION" -ge 2 ]; then
GO_MOD_PATH="go.mod"
CURRENT_MODULE_PATH=$(grep "^module " "$GO_MOD_PATH" | awk '{print $2}')
echo "Current module path: $CURRENT_MODULE_PATH"

# Check if module path already has version suffix
if [[ "$CURRENT_MODULE_PATH" =~ /v[0-9]+$ ]]; then
# Extract current major version from module path
CURRENT_MAJOR="${CURRENT_MODULE_PATH##*/v}"
echo "Current module path has version suffix: v$CURRENT_MAJOR"

if [ "$CURRENT_MAJOR" -ne "$MAJOR_VERSION" ]; then
echo "ERROR: Module path has /v${CURRENT_MAJOR} but releasing v${MAJOR_VERSION}"
echo "Please manually update module path in ${GO_MOD_PATH} to include /v${MAJOR_VERSION}"
exit 1
fi
echo "Module path already correct for v${MAJOR_VERSION}"
else
# No version suffix, need to add it
NEW_MODULE_PATH="${CURRENT_MODULE_PATH}/v${MAJOR_VERSION}"
echo "Updating module path to: $NEW_MODULE_PATH"

# Update the module path in go.mod
sed -i "s|^module ${CURRENT_MODULE_PATH}|module ${NEW_MODULE_PATH}|" "$GO_MOD_PATH"

# Commit the change
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add "$GO_MOD_PATH"
git commit -m "chore: update module path for v${MAJOR_VERSION}"
git push origin HEAD:${{ github.ref_name }}

echo "✓ Updated module path to $NEW_MODULE_PATH"
fi
else
echo "Major version is $MAJOR_VERSION (< 2), no module path update needed"
fi

- name: Run tests
if: steps.detect.outputs.core_changed == 'true'
run: |
Expand Down Expand Up @@ -290,10 +341,23 @@ jobs:
- name: Announce to Go proxy
if: steps.detect.outputs.core_changed == 'true'
run: |
set -euo pipefail
VERSION=${{ steps.version.outputs.next_version }}
MODULE_NAME="github.com/CrisisTextLine/modular"

# Extract major version from VERSION
MAJOR_VERSION="${VERSION#v}"
MAJOR_VERSION="${MAJOR_VERSION%%.*}"

# Construct correct module path with version suffix for v2+
if [ "$MAJOR_VERSION" -ge 2 ]; then
MODULE_NAME="github.com/CrisisTextLine/modular/v${MAJOR_VERSION}"
else
MODULE_NAME="github.com/CrisisTextLine/modular"
fi

echo "Announcing ${MODULE_NAME}@${VERSION} to Go proxy..."
GOPROXY=proxy.golang.org go list -m ${MODULE_NAME}@${VERSION}
echo "Announced version ${VERSION} to Go proxy"
echo "Announced version ${VERSION} to Go proxy"

bump-modules:
needs: release
Expand Down
Loading
Loading