Try to deploy changed samples in a given PR #23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: Install Docker Compose | |
| uses: ndeloof/[email protected] | |
| with: | |
| version: v2.29.7 | |
| - 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..." | |
| bash scripts/changed-samples.sh > changed_samples.txt | |
| - name: Run Docker Compose Up and down | |
| 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 run them one at a time with docker locally | |
| for sample in $CHANGED_FILES; do | |
| if ! bash scripts/compose-sample.sh $sample; then | |
| echo "Failed to compose up and down $sample" | |
| fi | |
| done | |
| deploy_samples: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| env: | |
| DEFANG_FABRIC: fabric-staging.defang.dev:443 | |
| concurrency: | |
| group: deploy_samples-group-${{ github.head_ref }} | |
| cancel-in-progress: true | |
| 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..." | |
| bash scripts/changed-samples.sh > 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: Deprovision any previously running projects | |
| run: | | |
| echo "Deprovisioning any previously running projects..." | |
| CURRENTLY_RUNNING_PROJECT=$(defang ls | grep -v '^ \* ' | head -n1 | awk '{print $2}') | |
| # if CURRENTLY_RUNNING_PROJECT is not empty, deprovision it | |
| if [ -n "$CURRENTLY_RUNNING_PROJECT" ]; then | |
| defang down --detach --project-name=$CURRENTLY_RUNNING_PROJECT | |
| fi | |
| - 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" | |
| if ! bash scripts/deploy-sample.sh $sample; then | |
| echo "Failed to deploy and deprovision $sample" | |
| fi | |
| done |