Skip to content

sync-custom-router-version #382

sync-custom-router-version

sync-custom-router-version #382

name: Sync Hyperswitch Updates
on:
repository_dispatch:
types:
- sync-hyperswitch-updates # daily-releases
- sync-custom-router-version # custom-releases
permissions:
contents: write
actions: write
jobs:
sync-hyperswitch:
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.HYPERSWITCH_BOT_APP_ID }}
private-key: ${{ secrets.HYPERSWITCH_BOT_APP_PRIVATE_KEY }}
- name: Determine sync configuration
id: config
run: |
EVENT_TYPE="${{ github.event.action }}"
echo "branch=deployments" >> $GITHUB_OUTPUT
if [ "$EVENT_TYPE" = "sync-hyperswitch-updates" ]; then
echo "update_all_services=true" >> $GITHUB_OUTPUT
echo "tag_prefix=app-" >> $GITHUB_OUTPUT
echo "sync_type=full" >> $GITHUB_OUTPUT
echo "Building charts for daily deployments"
elif [ "$EVENT_TYPE" = "sync-custom-router-version" ]; then
echo "update_all_services=false" >> $GITHUB_OUTPUT
echo "tag_prefix=cus-" >> $GITHUB_OUTPUT
echo "sync_type=router-only" >> $GITHUB_OUTPUT
echo "Builing charts for custom deployment"
else
echo "❌ Unknown event type: $EVENT_TYPE"
exit 1
fi
- name: Checkout target branch
uses: actions/checkout@v4
with:
ref: ${{ steps.config.outputs.branch }}
token: ${{ steps.app-token.outputs.token }}
fetch-depth: 0
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Generate and validate tag
id: generate_tag
run: |
# Check if version_tag is provided in client_payload
if [ -z "${{ github.event.client_payload.version_tag }}" ]; then
echo "❌ version_tag not provided in repository_dispatch client_payload"
exit 1
fi
SOURCE_REF="${{ github.event.client_payload.version_tag }}"
TAG_PREFIX="${{ steps.config.outputs.tag_prefix }}"
echo "Using version_tag from client_payload: $SOURCE_REF"
echo "Using tag prefix: $TAG_PREFIX"
# Generate the new tag
NEW_TAG="$TAG_PREFIX$SOURCE_REF"
echo "Generated tag: $NEW_TAG"
# Check if tag already exists on remote
echo "Checking if tag '$NEW_TAG' already exists..."
if git ls-remote --tags origin | grep -q "refs/tags/$NEW_TAG$"; then
echo "❌ Tag '$NEW_TAG' already exists on remote"
exit 1
fi
echo "✅ Tag '$NEW_TAG' does not exist, safe to proceed"
echo "tag=$NEW_TAG" >> $GITHUB_OUTPUT
echo "target_ref=$SOURCE_REF" >> $GITHUB_OUTPUT
- name: Merge latest changes from main
id: merge_step
run: |
git fetch origin main
git merge origin/main -X theirs --no-edit
if [ -n "$(git log origin/${{ steps.config.outputs.branch }}..HEAD --oneline)" ]; then
echo "has_merge_updates=true" >> $GITHUB_OUTPUT
echo "Merge brought updates from main"
else
echo "has_merge_updates=false" >> $GITHUB_OUTPUT
echo "No updates from merge"
fi
- name: Download configuration files
run: |
SOURCE_REF="${{ steps.generate_tag.outputs.target_ref }}"
BASE_URL="https://raw.githubusercontent.com/juspay/hyperswitch/${SOURCE_REF}/config/deployments"
echo "Downloading configuration files from hyperswitch ref: $SOURCE_REF"
# Create target directory
mkdir -p charts/incubator/hyperswitch-app/configs
# Download specific configuration files with error handling
echo "Downloading integration_test.toml..."
curl -fsSL -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3.raw" \
"${BASE_URL}/integration_test.toml" \
-o charts/incubator/hyperswitch-app/configs/router-integ.toml
echo "Downloading sandbox.toml..."
curl -fsSL -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3.raw" \
"${BASE_URL}/sandbox.toml" \
-o charts/incubator/hyperswitch-app/configs/router-sandbox.toml
echo "Downloading production.toml..."
curl -fsSL -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3.raw" \
"${BASE_URL}/production.toml" \
-o charts/incubator/hyperswitch-app/configs/router-production.toml
echo "✅ Configuration files downloaded successfully"
- name: Update service versions and chart version
id: update_versions
run: |
SOURCE_REF="${{ steps.generate_tag.outputs.target_ref }}"
VALUES_FILE="charts/incubator/hyperswitch-app/values.yaml"
CHART_FILE="charts/incubator/hyperswitch-app/Chart.yaml"
UPDATE_ALL="${{ steps.config.outputs.update_all_services }}"
TAG_PREFIX="${{ steps.config.outputs.tag_prefix }}"
echo "Updating service versions and chart version with hyperswitch reference: $SOURCE_REF"
echo "Update all services: $UPDATE_ALL"
echo "Tag prefix: $TAG_PREFIX"
# Install yq for reliable YAML processing
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
if [ "$UPDATE_ALL" = "true" ]; then
# Update all service versions
echo "Updating all service versions to $SOURCE_REF"
yq eval ".services.router.version = \"$SOURCE_REF\"" -i $VALUES_FILE
yq eval ".services.consumer.version = \"$SOURCE_REF\"" -i $VALUES_FILE
yq eval ".services.producer.version = \"$SOURCE_REF\"" -i $VALUES_FILE
yq eval ".services.drainer.version = \"$SOURCE_REF\"" -i $VALUES_FILE
else
# Update router service version
echo "Updating router service version to $SOURCE_REF"
yq eval ".services.router.version = \"$SOURCE_REF\"" -i $VALUES_FILE
fi
# Update chart version to valid SemVer format with hyperswitch version as prerelease
# Read chart version from main branch as prefix
MAIN_CHART_VERSION=$(git show origin/main:$CHART_FILE | yq eval ".version" -)
# Replace dots with hyphens in SOURCE_REF to make it a single prerelease identifier
SOURCE_REF_HYPHENATED=$(echo "$SOURCE_REF" | tr '.' '-')
CHART_VERSION="$MAIN_CHART_VERSION-$TAG_PREFIX$SOURCE_REF_HYPHENATED"
echo "Converting hyperswitch version $SOURCE_REF to chart version $CHART_VERSION (using main branch version $MAIN_CHART_VERSION as prefix)"
yq eval ".version = \"$CHART_VERSION\"" -i $CHART_FILE
echo "chart_version=$CHART_VERSION" >> $GITHUB_OUTPUT
echo "Service versions and chart version updated successfully"
- name: Setup Helm
uses: azure/setup-helm@v4
with:
version: 'v3.14.0'
- name: Helm dependency update
run: |
CHART_DIR="charts/incubator/hyperswitch-app"
echo "Updating chart dependencies..."
cd $CHART_DIR
helm dependency update
cd ../../..
echo "✅ Chart dependencies updated"
- name: Check for changes
id: check_changes
run: |
# Check for both file changes and merge updates
if git diff --quiet && [ -z "$(git status --porcelain)" ] && [ "${{ steps.merge_step.outputs.has_merge_updates }}" != "true" ]; then
echo "No changes detected"
echo "changes=false" >> $GITHUB_OUTPUT
else
echo "Changes detected"
echo "changes=true" >> $GITHUB_OUTPUT
# Show what changed for debugging
echo "Git status:"
git status --porcelain
echo "Merge updates: ${{ steps.merge_step.outputs.has_merge_updates }}"
fi
- name: Commit and push changes
if: steps.check_changes.outputs.changes == 'true'
run: |
SYNC_TYPE="${{ steps.config.outputs.sync_type }}"
SOURCE_REF="${{ steps.generate_tag.outputs.target_ref }}"
CHART_VERSION="${{ steps.update_versions.outputs.chart_version }}"
TAG="${{ steps.generate_tag.outputs.tag }}"
# Generate commit title and service update section based on sync type
if [ "$SYNC_TYPE" = "full" ]; then
COMMIT_TITLE="chore: sync hyperswitch updates from $SOURCE_REF"
SERVICE_SECTION="Service versions:
- Updated all service versions to $SOURCE_REF"
else
COMMIT_TITLE="chore: sync custom router version updates from $SOURCE_REF"
SERVICE_SECTION="Router version: $SOURCE_REF"
fi
# Build common commit message with conditional parts
COMMIT_MSG="$COMMIT_TITLE
Hyperswitch version: $SOURCE_REF
Configuration files:
- Updated router-integ.toml from integration_test.toml
- Updated router-sandbox.toml from sandbox.toml
- Updated router-production.toml from production.toml
$SERVICE_SECTION
Chart version:
- Updated chart version to $CHART_VERSION
Source: https://github.com/juspay/hyperswitch/tree/$SOURCE_REF/config/deployments
Source ref: $SOURCE_REF
Tag: $TAG"
# Check if there are uncommitted changes to commit
if [ -n "$(git status --porcelain)" ]; then
echo "Committing file changes..."
git add charts/incubator/hyperswitch-app/configs/ charts/incubator/hyperswitch-app/values.yaml charts/incubator/hyperswitch-app/Chart.yaml
git add -f charts/incubator/hyperswitch-app/charts/ charts/incubator/hyperswitch-app/Chart.lock
git commit -m "$COMMIT_MSG"
else
echo "No file changes to commit (changes may have come from merge)"
fi
- name: Create and push tag
if: steps.check_changes.outputs.changes == 'true'
run: |
git tag "${{ steps.generate_tag.outputs.tag }}"
git push origin HEAD "${{ steps.generate_tag.outputs.tag }}"
- name: Summary
if: steps.check_changes.outputs.changes == 'true'
run: |
SYNC_TYPE="${{ steps.config.outputs.sync_type }}"
SOURCE_REF="${{ steps.generate_tag.outputs.target_ref }}"
CHART_VERSION="${{ steps.update_versions.outputs.chart_version }}"
TAG="${{ steps.generate_tag.outputs.tag }}"
echo "Hyperswitch sync completed successfully!"
echo "Sync type: $SYNC_TYPE"
echo "Target branch: ${{ steps.config.outputs.branch }}"
echo "Source ref: $SOURCE_REF"
echo "Chart version: $CHART_VERSION"
echo "Tag: $TAG"
echo ""
echo "Configuration files updated:"
echo " - charts/incubator/hyperswitch-app/configs/router-integ.toml"
echo " - charts/incubator/hyperswitch-app/configs/router-sandbox.toml"
echo " - charts/incubator/hyperswitch-app/configs/router-production.toml"
if [ "$SYNC_TYPE" = "full" ]; then
echo "All service versions updated:"
echo " - router, consumer, producer, drainer → $SOURCE_REF"
else
echo "Router service version updated:"
echo " - router → $SOURCE_REF"
fi
echo "Chart updates:"
echo " - charts/incubator/hyperswitch-app/Chart.yaml"
echo "Dependencies updated for air-gapped deployments:"
echo " - charts/incubator/hyperswitch-app/charts/"
echo " - charts/incubator/hyperswitch-app/Chart.lock"
- name: No changes summary
if: steps.check_changes.outputs.changes == 'false'
run: |
echo "No changes detected - hyperswitch updates are already up to date"