Skip to content

Sync Terraform Modules #13

Sync Terraform Modules

Sync Terraform Modules #13

Workflow file for this run

name: Sync Terraform Modules
on:
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name to sync (e.g., v1.0.0)'
required: true
type: string
jobs:
sync-modules:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- module: 'ak-deployment/ak-aws/common'
repo: 'yaalalabs/terraform-aws-ak-common'
branch: 'develop'
link: 'https://registry.terraform.io/modules/yaalalabs/ak-common/aws/latest'
- module: 'ak-deployment/ak-aws/serverless'
repo: 'yaalalabs/terraform-aws-ak-serverless'
branch: 'develop'
link: 'https://registry.terraform.io/modules/yaalalabs/ak-serverless/aws/latest'
- module: 'ak-deployment/ak-aws/containerized'
repo: 'yaalalabs/terraform-aws-ak-containerized'
branch: 'develop'
link: 'https://registry.terraform.io/modules/yaalalabs/ak-containerized/aws/latest'
steps:
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: yaalalabs
repositories: |
agent-kernel
terraform-aws-ak-common
terraform-aws-ak-serverless
terraform-aws-ak-containerized
- name: Get tag name
id: tag
run: echo "TAG_NAME=${{ inputs.tag_name }}" >> $GITHUB_OUTPUT
- name: Checkout yaalalabs/agent-kernel
uses: actions/checkout@v4
with:
ref: ${{ steps.tag.outputs.TAG_NAME }}
fetch-depth: 0 # Fetch all history for all branches and tags
- name: Setup Git
run: |
git config --global user.name "agent-kernel-ci[bot]"
git config --global user.email "agent-kernel-ci[bot]@users.noreply.github.com"
- name: Extract and push module
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
TAG_NAME="${{ steps.tag.outputs.TAG_NAME }}"
MODULE="${{ matrix.module }}"
TARGET_REPO="${{ matrix.repo }}"
TARGET_BRANCH="${{ matrix.branch }}"
REGISTRY_LINK="${{ matrix.link }}"
echo "Syncing $MODULE to $TARGET_REPO (branch: $TARGET_BRANCH) with tag $TAG_NAME"
# Create a temporary directory
TEMP_DIR=$(mktemp -d)
cd $TEMP_DIR
# Clone the target repository or create initial commit if new
if git clone https://x-access-token:${GH_TOKEN}@github.com/${TARGET_REPO}.git; then
cd $(basename $TARGET_REPO)
# Checkout or create the target branch
git checkout $TARGET_BRANCH 2>/dev/null || git checkout -b $TARGET_BRANCH
else
mkdir $(basename $TARGET_REPO)
cd $(basename $TARGET_REPO)
git init
git checkout -b $TARGET_BRANCH
git remote add origin https://x-access-token:${GH_TOKEN}@github.com/${TARGET_REPO}.git
fi
# Remove all existing files (except .git)
find . -maxdepth 1 ! -name '.git' ! -name '.' ! -name '..' -exec rm -rf {} +
# Copy module files from agent-kernel monorepo
cp -r $GITHUB_WORKSPACE/$MODULE/* .
# Commit changes (if any)
if [[ -n $(git status -s) ]]; then
git add .
git commit -m "Sync from yaalalabs/agent-kernel tag $TAG_NAME"
git push origin $TARGET_BRANCH
echo "✅ Changes committed and pushed to $TARGET_BRANCH"
else
echo "ℹ️ No file changes detected for $MODULE"
fi
# Always create the tag and release
# Create the same tag in the target repo
git tag -a $TAG_NAME -m "Release $TAG_NAME from yaalalabs/agent-kernel" || true
git push origin $TAG_NAME
# Create GitHub Release
# Extract module name from path (e.g., 'common', 'serverless', 'containerized')
MODULE_NAME=$(basename $MODULE)
# Determine if this is a prerelease based on tag format
if [[ "$TAG_NAME" =~ -[ab][0-9]+$ ]]; then
PRERELEASE_FLAG="--prerelease"
PRERELEASE_NOTE="⚠️ Pre-release version"
else
PRERELEASE_FLAG=""
PRERELEASE_NOTE="✅ Stable release"
fi
# Create release body
cat << EOF > release_body.md
🚀 **Terraform Module: ${MODULE_NAME} ${TAG_NAME}**
${PRERELEASE_NOTE}
📦 [View on Terraform Registry](${REGISTRY_LINK})
### Usage
\`\`\`hcl
module "${MODULE_NAME}" {
source = "yaalalabs/${MODULE_NAME}/aws"
version = "${TAG_NAME#v}"
# Add your configuration here
}
\`\`\`
---
Synced from [yaalalabs/agent-kernel](https://github.com/yaalalabs/agent-kernel) ${TAG_NAME}
EOF
# Create release using gh CLI
gh release create "$TAG_NAME" \
--repo "$TARGET_REPO" \
--title "${TAG_NAME}" \
--notes-file release_body.md \
${PRERELEASE_FLAG}
echo "✅ Successfully synced $MODULE to $TARGET_REPO with tag $TAG_NAME and created release"
# Cleanup
cd $GITHUB_WORKSPACE
rm -rf $TEMP_DIR