Skip to content

Try to deploy changed samples in a given PR #12

Try to deploy changed samples in a given PR

Try to deploy changed samples in a given PR #12

name: Deploy Changed Samples
on:
pull_request:
paths:
- 'samples/**'
jobs:
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 "changed samples"
CHANGED_FILES=$(cat changed_samples.txt)
# 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 --debug
# teardown the sample
defang compose down --detach
done