Skip to content

Try to deploy changed samples in a given PR #15

Try to deploy changed samples in a given PR

Try to deploy changed samples in a given PR #15

name: Deploy Changed Samples
on:
pull_request:
paths:
- 'samples/**'
jobs:
run_samples_locally:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
env:
DEFANG_FABRIC: fabric-staging.defang.dev:443
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Fetch main branch
run: git fetch origin main:main # Fetch the main branch reference for comparison
- name: Identify changed samples
run: |
echo "Identifying changed samples..."
echo $(git diff --name-only HEAD main | grep '^samples/' | awk -F'/' '{print $1"/"$2}' | sort | uniq) > changed_samples.txt
- name: Run Docker Compose Up
run: |
echo "Running Docker Compose Up..."
docker-compose up
- name: Run Docker Compose Down
run: |
echo "Running Docker Compose Down..."
docker-compose down
deploy_samples:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
env:
DEFANG_FABRIC: fabric-staging.defang.dev:443
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Fetch main branch
run: git fetch origin main:main # Fetch the main branch reference for comparison
- name: Identify changed samples
run: |
echo "Identifying changed samples..."
echo $(git diff --name-only HEAD main | grep '^samples/' | awk -F'/' '{print $1"/"$2}' | sort | uniq) > changed_samples.txt
- name: Install defang
shell: bash
run: . <(curl -Lf https://raw.githubusercontent.com/DefangLabs/defang/main/src/bin/install || echo return $?)
env:
GH_TOKEN: ${{ github.token }} # avoid rate-limits
- name: Login to Defang
shell: bash
run: |
defang login
defang whoami
- name: Deploy Config
shell: bash
run: |
echo "DEFANG_DEBUG=$RUNNER_DEBUG" >> $GITHUB_ENV
CHANGED_FILES=$(cat changed_samples.txt)
echo "changed samples"
echo $CHANGED_FILES
# Iterate over the changed samples and deploy them one at a time
for sample in $CHANGED_FILES; do
echo "Deploying $sample"
cd $sample
# deploy the sample
defang compose up
# teardown the sample
defang compose down --detach
cd ..
done