From 46e20069fcb675e0185533c69a19ae1af170fe73 Mon Sep 17 00:00:00 2001 From: zramsay Date: Fri, 28 Nov 2025 20:52:43 +0000 Subject: [PATCH] Update .gitea/workflows/z-docs.yml --- .gitea/workflows/z-docs.yml | 173 +++++++++++++++++++++++++++--------- 1 file changed, 129 insertions(+), 44 deletions(-) diff --git a/.gitea/workflows/z-docs.yml b/.gitea/workflows/z-docs.yml index c600866..c29e27e 100644 --- a/.gitea/workflows/z-docs.yml +++ b/.gitea/workflows/z-docs.yml @@ -1,52 +1,137 @@ -name: Deploy from Main +#!/bin/bash -on: - push: - branches: '*' - schedule: - - cron: '0 0 * * 0' # Weekly: Every Sunday at midnight UTC - workflow_dispatch: +# Exit on any error +set -e -env: - TARGET_REPO: zramsay/zenith-docs - CERC_REGISTRY_USER_KEY: ${{ secrets.CICD_LACONIC_USER_KEY }} - CERC_REGISTRY_BOND_ID: ${{ secrets.CICD_LACONIC_BOND_ID }} - CERC_REGISTRY_RPC_ENDPOINT: "http://143.198.37.25:26657" - CERC_REGISTRY_GQL_ENDPOINT: "http://143.198.37.25:9473/api" - CERC_REGISTRY_CHAIN_ID: "laconic-mainnet" - CERC_REGISTRY_DEPLOYMENT_HOSTNAME: zenith-docs - APP_NAME: "zenith-docs" - DEPLOYER_LRN: "lrn://mito-systems/deployers/webapp-deployer-api.pwa.laconic.audubon.app" - AUTHORITY: "mito-systems" +# Check for required positional arguments +if [ $# -ne 2 ]; then + echo "Error: Two arguments required" + echo "Usage: $0 " + exit 1 +fi -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - name: "Clone project repository" - uses: actions/checkout@v3 +# Check required environment variables +if [ -z "$CERC_REGISTRY_USER_KEY" ]; then + echo "Error: CERC_REGISTRY_USER_KEY environment variable is required" + exit 1 +fi - - name: Use Node.js - uses: actions/setup-node@v3 - with: - node-version: 18 +if [ -z "$CERC_REGISTRY_BOND_ID" ]; then + echo "Error: CERC_REGISTRY_BOND_ID environment variable is required" + exit 1 +fi - - name: Deploy from docs-mvp branch - run: | - # Get latest commit from docs-mvp branch - commit_info=$(curl -s https://git.vdb.to/api/v1/repos/${{ env.TARGET_REPO }}/branches/docs-mvp) - commit_hash=$(echo $commit_info | jq -r .commit.id) - commit_date=$(echo $commit_info | jq -r .commit.timestamp) +REPO_PATH="$1" +REF="$2" +REPO="https://git.vdb.to/${REPO_PATH}" - echo "Latest commit: $commit_hash" - echo "Committed at: $commit_date" - echo "Proceeding with deployment" +# Get the commit hash - try as branch first, then as tag +COMMIT_HASH=$(curl -s "https://git.vdb.to/api/v1/repos/${REPO_PATH}/branches/${REF}" | jq -r '.commit.id') +if [ -z "$COMMIT_HASH" ] || [ "$COMMIT_HASH" = "null" ]; then + # Fall back to tag lookup + COMMIT_HASH=$(curl -s "https://git.vdb.to/api/v1/repos/${REPO_PATH}/tags/${REF}" | jq -r '.commit.sha') + if [ -z "$COMMIT_HASH" ] || [ "$COMMIT_HASH" = "null" ]; then + echo "Error: Could not find commit hash for ref $REF" + exit 1 + fi +fi - # Setup dependencies - sudo apt -y update && sudo apt -y install jq - corepack enable - npm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/ - npm install -g @cerc-io/laconic-registry-cli +# Use short commit hash for version +SHORT_HASH="${COMMIT_HASH:0:7}" +VERSION="${REF}-${SHORT_HASH}" - # Run deployment - ./deploy-gitea.sh ${{ env.TARGET_REPO }} docs-mvp \ No newline at end of file +echo "Deploying from ref: $REF" +echo "Commit hash: $COMMIT_HASH" +echo "Version: $VERSION" + +# Create temporary files +RECORD_FILE=tmp.rf.$ +CONFIG_FILE=$(mktemp) + +# Generate registry configuration +cat < "$CONFIG_FILE" +services: + registry: + rpcEndpoint: '${CERC_REGISTRY_RPC_ENDPOINT}' + gqlEndpoint: '${CERC_REGISTRY_GQL_ENDPOINT}' + chainId: ${CERC_REGISTRY_CHAIN_ID} + gas: 900000 + fees: 900000alnt +EOF + +# Generate the application record +cat < "$RECORD_FILE" +record: + type: ApplicationRecord + name: "$APP_NAME" + version: "$VERSION" + app_type: webapp + repository: + - "$REPO" + repository_ref: "$COMMIT_HASH" + app_version: "0.0.1" +EOF + +# Publish the application record +echo "Publishing application record..." +cat $RECORD_FILE +RECORD_ID=$(laconic -c $CONFIG_FILE registry record publish --filename $RECORD_FILE --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} | jq -r '.id') +echo "Record ID: $RECORD_ID" + +# Set up LRN (Laconic Resource Name) +if [ -z "$CERC_REGISTRY_APP_LRN" ]; then + CERC_REGISTRY_APP_LRN="lrn://$AUTHORITY/applications/$APP_NAME" +fi + +# Set name mappings +echo "Setting name mappings..." +laconic -c $CONFIG_FILE registry name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_LRN" "$RECORD_ID" +laconic -c $CONFIG_FILE registry name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_LRN@${COMMIT_HASH}" "$RECORD_ID" + + +# Handle deployer payment if required +if [ ! -z "$DEPLOYER_LRN" ]; then + echo "Processing deployer payment..." + paymentAddress=$(laconic -c $CONFIG_FILE registry name resolve "$DEPLOYER_LRN" | jq -r '.[0].attributes.paymentAddress') + paymentAmount=$(laconic -c $CONFIG_FILE registry name resolve "$DEPLOYER_LRN" | jq -r '.[0].attributes.minimumPayment' | sed 's/alnt//g') + + if [[ -n "$paymentAmount" && "$paymentAmount" != "null" ]]; then + payment=$(laconic -c $CONFIG_FILE registry tokens send --address "$paymentAddress" --type alnt --quantity "$paymentAmount" --user-key "$CERC_REGISTRY_USER_KEY" --bond-id "$CERC_REGISTRY_BOND_ID") + txHash=$(echo "$payment" | jq -r '.tx.hash') + echo "Paid deployer with txHash: $txHash" + else + echo "No payment required - skipping payment step" + txHash="" + fi + + # Generate deployment request + echo "Generating deployment request..." + cat < "$RECORD_FILE" +record: + type: ApplicationDeploymentRequest + version: '1.0.0' + name: "$APP_NAME" + application: "$CERC_REGISTRY_APP_LRN" + deployer: $DEPLOYER_LRN + dns: $CERC_REGISTRY_DEPLOYMENT_HOSTNAME + config: + env: + LACONIC_HOSTED_CONFIG_laconicd_chain_id: laconic-testnet-2 + meta: + note: "Added by CI @ $(date)" + repository: "$REPO" + repository_ref: "$COMMIT_HASH" + payment: $txHash +EOF + + cat $RECORD_FILE + DEPLOY_RECORD_ID=$(laconic -c $CONFIG_FILE registry record publish \ + --filename $RECORD_FILE \ + --user-key "${CERC_REGISTRY_USER_KEY}" \ + --bond-id ${CERC_REGISTRY_BOND_ID} | jq -r '.id') + echo "Deployment Record ID: $DEPLOY_RECORD_ID" +fi + +# Cleanup +rm -f $RECORD_FILE $CONFIG_FILE +echo "Script completed successfully" \ No newline at end of file