name: Build and Deploy Supply Chain Environment on: push: branches: - main - master pull_request: branches: - main env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: # Job 1: Run Tests test: runs-on: ubuntu-latest name: Run Tests steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Python 3.11 uses: actions/setup-python@v4 with: python-version: '3.11' - name: Cache pip packages uses: actions/cache@v3 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r server/requirements.txt pip install pytest pytest-asyncio - name: Run pytest run: | cd supply_chain_env pytest tests/ -v --tb=short 2>&1 || true continue-on-error: true - name: Run full environment test run: | cd supply_chain_env timeout 60 python run_full_test.py 2>&1 || true continue-on-error: true # Job 2: Build Docker Image & Push to GHCR build: runs-on: ubuntu-latest name: Build and Push Docker Image needs: test permissions: contents: read packages: write steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Log in to Container Registry uses: docker/login-action@v2 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v4 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=sha,prefix={{branch}}- type=raw,value=latest - name: Build and push Docker image to GHCR uses: docker/build-push-action@v4 with: context: . push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max # Job 3: Deploy to Hugging Face Spaces deploy-hf: runs-on: ubuntu-latest name: Deploy to Hugging Face Spaces needs: build if: github.ref == 'refs/heads/main' && github.event_name == 'push' steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - name: Push to Hugging Face run: | git config user.email "actions@github.com" git config user.name "GitHub Actions" git remote add hf https://Vanshkumar16:${{ secrets.HF_TOKEN }}@huggingface.co/spaces/Consensusss/supply_chain_env git push hf main --force continue-on-error: true - name: Notify deployment if: success() run: | echo "✅ Deployment to HF Space initiated" echo "View Space at: https://consensusss-supply-chain-env.hf.space" # Job 4: Summary summary: runs-on: ubuntu-latest name: Build Summary needs: [test, build, deploy-hf] if: always() steps: - name: Print summary run: | echo "==========================================" echo "Build Summary" echo "==========================================" echo "Tests: ${{ needs.test.result }}" echo "Docker Build: ${{ needs.build.result }}" echo "HF Deploy: ${{ needs.deploy-hf.result }}" echo "" echo "✅ Docker image: ghcr.io/${{ github.repository }}:latest" echo "✅ HF Space: https://consensusss-supply-chain-env.hf.space" echo "✅ GitHub: https://github.com/${{ github.repository }}"