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
44 changes: 43 additions & 1 deletion .github/workflows/deploy-col-mar-mm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,50 @@ env:
GHCR_IMAGE: ghcr.io/lumerin-protocol/collateral-margin-market-maker

jobs:
config-scope:
name: Config scope
runs-on: ubuntu-latest
outputs:
run: ${{ steps.gate.outputs.run }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Skip the other environment's config
id: gate
run: |
# dev does not deploy when the only change is config/prd.env.
# main does not deploy when the only change is config/dev.env.
# Any other file still deploys. A manual run always deploys.
REF="${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ "${{ github.event_name }}" = "pull_request" ]; then
git fetch --no-tags origin "$REF"
FILES=$(git diff --name-only "origin/${REF}...HEAD")
elif git cat-file -e "${{ github.event.before }}^{commit}" 2>/dev/null; then
FILES=$(git diff --name-only "${{ github.event.before }}" HEAD)
else
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
SKIP="config/prd.env"
[ "$REF" = "main" ] && SKIP="config/dev.env"
RUN=true
if [ -n "$FILES" ] && [ -z "$(printf '%s\n' "$FILES" | grep -vx "$SKIP" || true)" ]; then
RUN=false
fi
echo "run=$RUN" >> "$GITHUB_OUTPUT"
echo "ref=$REF skip=$SKIP run=$RUN"
printf '%s\n' "$FILES"

build:
name: 🔨 Build
needs: config-scope
if: needs.config-scope.result == 'success' && needs.config-scope.outputs.run == 'true'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.gen_tag.outputs.version }}
Expand Down Expand Up @@ -372,7 +414,7 @@ jobs:
name: 🧹 Cleanup
runs-on: ubuntu-latest
needs: [ build, verify ]
if: always() && needs.build.outputs.is_cicd_branch != 'true'
if: always() && needs.build.result != 'skipped' && needs.build.outputs.is_cicd_branch != 'true'

steps:
- name: Checkout code
Expand Down
44 changes: 43 additions & 1 deletion .github/workflows/deploy-keeper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,50 @@ env:
GHCR_IMAGE: ghcr.io/lumerin-protocol/collateral-margin-keeper

jobs:
config-scope:
name: Config scope
runs-on: ubuntu-latest
outputs:
run: ${{ steps.gate.outputs.run }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Skip the other environment's config
id: gate
run: |
# dev does not deploy when the only change is config/prd.env.
# main does not deploy when the only change is config/dev.env.
# Any other file still deploys. A manual run always deploys.
REF="${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ "${{ github.event_name }}" = "pull_request" ]; then
git fetch --no-tags origin "$REF"
FILES=$(git diff --name-only "origin/${REF}...HEAD")
elif git cat-file -e "${{ github.event.before }}^{commit}" 2>/dev/null; then
FILES=$(git diff --name-only "${{ github.event.before }}" HEAD)
else
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
SKIP="config/prd.env"
[ "$REF" = "main" ] && SKIP="config/dev.env"
RUN=true
if [ -n "$FILES" ] && [ -z "$(printf '%s\n' "$FILES" | grep -vx "$SKIP" || true)" ]; then
RUN=false
fi
echo "run=$RUN" >> "$GITHUB_OUTPUT"
echo "ref=$REF skip=$SKIP run=$RUN"
printf '%s\n' "$FILES"

build:
name: 🔨 Build
needs: config-scope
if: needs.config-scope.result == 'success' && needs.config-scope.outputs.run == 'true'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.gen_tag.outputs.version }}
Expand Down Expand Up @@ -453,7 +495,7 @@ jobs:
name: 🧹 Cleanup
runs-on: ubuntu-latest
needs: [build, verify]
if: always() && needs.build.outputs.is_cicd_branch != 'true'
if: always() && needs.build.result != 'skipped' && needs.build.outputs.is_cicd_branch != 'true'

steps:
- name: Checkout code
Expand Down
64 changes: 58 additions & 6 deletions .github/workflows/deploy-points-subgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,50 @@ env:
SERVICE_NAME: points-subgraph

jobs:
config-scope:
name: Config scope
runs-on: ubuntu-latest
outputs:
run: ${{ steps.gate.outputs.run }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Skip the other environment's config
id: gate
run: |
# dev does not deploy when the only change is config/prd.env.
# main does not deploy when the only change is config/dev.env.
# Any other file still deploys. A manual run always deploys.
REF="${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ "${{ github.event_name }}" = "pull_request" ]; then
git fetch --no-tags origin "$REF"
FILES=$(git diff --name-only "origin/${REF}...HEAD")
elif git cat-file -e "${{ github.event.before }}^{commit}" 2>/dev/null; then
FILES=$(git diff --name-only "${{ github.event.before }}" HEAD)
else
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
SKIP="config/prd.env"
[ "$REF" = "main" ] && SKIP="config/dev.env"
RUN=true
if [ -n "$FILES" ] && [ -z "$(printf '%s\n' "$FILES" | grep -vx "$SKIP" || true)" ]; then
RUN=false
fi
echo "run=$RUN" >> "$GITHUB_OUTPUT"
echo "ref=$REF skip=$SKIP run=$RUN"
printf '%s\n' "$FILES"

setup:
name: 🔧 Setup
needs: config-scope
if: needs.config-scope.result == 'success' && needs.config-scope.outputs.run == 'true'
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.gen_tag.outputs.environment }}
Expand Down Expand Up @@ -115,24 +157,34 @@ jobs:
fi
echo "goldsky_subgraph_name=$GS_NAME" >> $GITHUB_OUTPUT

# Rolling tag, public endpoint, and the config/<name>.env to load.
# Rolling tag and which config file to load. The public query URL
# is POINTS_SUBGRAPH_URL in that file.
case $ENV in
dev)
echo "goldsky_rolling_tag=dev-latest" >> $GITHUB_OUTPUT
echo "goldsky_endpoint=${{ vars.DEV_GS_POINTS }}" >> $GITHUB_OUTPUT
echo "config_env=dev" >> $GITHUB_OUTPUT
CONFIG_ENV=dev
;;
main)
echo "goldsky_rolling_tag=lmn-latest" >> $GITHUB_OUTPUT
echo "goldsky_endpoint=${{ vars.LMN_GS_POINTS }}" >> $GITHUB_OUTPUT
echo "config_env=prd" >> $GITHUB_OUTPUT
CONFIG_ENV=prd
;;
*)
echo "::error::Unknown environment '$ENV' (expected dev or main)"
exit 1
;;
esac

if [ -n "${CONFIG_ENV:-}" ]; then
ENDPOINT=$(grep -E '^POINTS_SUBGRAPH_URL=' "config/${CONFIG_ENV}.env" | head -1 | cut -d= -f2-)
if [ -z "$ENDPOINT" ]; then
echo "::error::POINTS_SUBGRAPH_URL is missing from config/${CONFIG_ENV}.env"
exit 1
fi
echo "goldsky_endpoint=$ENDPOINT" >> "$GITHUB_OUTPUT"
fi

echo "🎯 Deploying to Goldsky: subgraph=${GS_NAME}, env=${ENV}"

- name: Install dependencies
Expand Down Expand Up @@ -348,7 +400,7 @@ jobs:

if [ -z "${GOLDSKY_ENDPOINT}" ]; then
echo "⚠️ No Goldsky endpoint URL configured — skipping verification"
echo " Set DEV_GS_POINTS / LMN_GS_POINTS org variable"
echo " Set POINTS_SUBGRAPH_URL in config/dev.env or config/prd.env"
exit 0
fi

Expand Down Expand Up @@ -393,7 +445,7 @@ jobs:
name: 🧹 Cleanup
runs-on: ubuntu-latest
needs: [setup, build, verify]
if: always() && github.event_name != 'pull_request'
if: always() && needs.setup.result != 'skipped' && github.event_name != 'pull_request'

steps:
- name: Checkout code
Expand Down Expand Up @@ -440,7 +492,7 @@ jobs:
name: 📢 Notify
runs-on: ubuntu-latest
needs: [setup, build, deploy, verify, cleanup]
if: always() && github.event_name != 'pull_request'
if: always() && needs.setup.result != 'skipped' && github.event_name != 'pull_request'

steps:
- name: Checkout (for composite action)
Expand Down
64 changes: 58 additions & 6 deletions .github/workflows/deploy-subgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,50 @@ env:
SERVICE_NAME: collateral-vault-subgraph

jobs:
config-scope:
name: Config scope
runs-on: ubuntu-latest
outputs:
run: ${{ steps.gate.outputs.run }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Skip the other environment's config
id: gate
run: |
# dev does not deploy when the only change is config/prd.env.
# main does not deploy when the only change is config/dev.env.
# Any other file still deploys. A manual run always deploys.
REF="${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ "${{ github.event_name }}" = "pull_request" ]; then
git fetch --no-tags origin "$REF"
FILES=$(git diff --name-only "origin/${REF}...HEAD")
elif git cat-file -e "${{ github.event.before }}^{commit}" 2>/dev/null; then
FILES=$(git diff --name-only "${{ github.event.before }}" HEAD)
else
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
SKIP="config/prd.env"
[ "$REF" = "main" ] && SKIP="config/dev.env"
RUN=true
if [ -n "$FILES" ] && [ -z "$(printf '%s\n' "$FILES" | grep -vx "$SKIP" || true)" ]; then
RUN=false
fi
echo "run=$RUN" >> "$GITHUB_OUTPUT"
echo "ref=$REF skip=$SKIP run=$RUN"
printf '%s\n' "$FILES"

setup:
name: 🔧 Setup
needs: config-scope
if: needs.config-scope.result == 'success' && needs.config-scope.outputs.run == 'true'
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.gen_tag.outputs.environment }}
Expand Down Expand Up @@ -113,24 +155,34 @@ jobs:
fi
echo "goldsky_subgraph_name=$GS_NAME" >> $GITHUB_OUTPUT

# Rolling tag, public endpoint, and the config/<name>.env to load.
# Rolling tag and which config file to load. The public query URL
# is VAULT_SUBGRAPH_URL in that file.
case $ENV in
dev)
echo "goldsky_rolling_tag=dev-latest" >> $GITHUB_OUTPUT
echo "goldsky_endpoint=${{ vars.DEV_GS_VAULT }}" >> $GITHUB_OUTPUT
echo "config_env=dev" >> $GITHUB_OUTPUT
CONFIG_ENV=dev
;;
main)
echo "goldsky_rolling_tag=lmn-latest" >> $GITHUB_OUTPUT
echo "goldsky_endpoint=${{ vars.LMN_GS_VAULT }}" >> $GITHUB_OUTPUT
echo "config_env=prd" >> $GITHUB_OUTPUT
CONFIG_ENV=prd
;;
*)
echo "::error::Unknown environment '$ENV' (expected dev or main)"
exit 1
;;
esac

if [ -n "${CONFIG_ENV:-}" ]; then
ENDPOINT=$(grep -E '^VAULT_SUBGRAPH_URL=' "config/${CONFIG_ENV}.env" | head -1 | cut -d= -f2-)
if [ -z "$ENDPOINT" ]; then
echo "::error::VAULT_SUBGRAPH_URL is missing from config/${CONFIG_ENV}.env"
exit 1
fi
echo "goldsky_endpoint=$ENDPOINT" >> "$GITHUB_OUTPUT"
fi

echo "🎯 Deploying to Goldsky: subgraph=${GS_NAME}, env=${ENV}"

- name: Install dependencies
Expand Down Expand Up @@ -346,7 +398,7 @@ jobs:

if [ -z "${GOLDSKY_ENDPOINT}" ]; then
echo "⚠️ No Goldsky endpoint URL configured — skipping verification"
echo " Set DEV_GS_VAULT / LMN_GS_VAULT org variable"
echo " Set VAULT_SUBGRAPH_URL in config/dev.env or config/prd.env"
exit 0
fi

Expand Down Expand Up @@ -391,7 +443,7 @@ jobs:
name: 🧹 Cleanup
runs-on: ubuntu-latest
needs: [setup, build, verify]
if: always() && github.event_name != 'pull_request'
if: always() && needs.setup.result != 'skipped' && github.event_name != 'pull_request'

steps:
- name: Checkout code
Expand Down Expand Up @@ -438,7 +490,7 @@ jobs:
name: 📢 Notify
runs-on: ubuntu-latest
needs: [setup, build, deploy, verify, cleanup]
if: always() && github.event_name != 'pull_request'
if: always() && needs.setup.result != 'skipped' && github.event_name != 'pull_request'

steps:
- name: Checkout (for composite action)
Expand Down
Loading
Loading