update git workflow config #11
This file contains 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: CI/CD Pipeline | |
on: | |
push: | |
branches: [ main ] | |
paths-ignore: | |
- '**/*.md' # Exclude all markdown files (.md) | |
pull_request: | |
branches: [ main ] | |
paths-ignore: | |
- '**/*.md' # Exclude all markdown files (.md) | |
jobs: | |
# Build job | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Build Docker image | |
run: docker build -t music-recommender . | |
# Test job with matrix build | |
test: | |
needs: build | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: [3.8, 3.9, 3.10] # Testing across different Python versions | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
# Caching pip dependencies | |
- name: Cache pip | |
uses: actions/cache@v2 | |
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 requirements.txt | |
- name: Run tests | |
run: python -m unittest discover tests | |
# Run linting with continue-on-error | |
- name: Run linting | |
run: pylint your_code/ | |
continue-on-error: true | |
- name: Run tests in Docker | |
run: docker run music-recommender python -m unittest discover tests | |
# Deploy job | |
deploy: | |
needs: test | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
steps: | |
- uses: actions/checkout@v2 | |
# Authenticate with Google Cloud | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v0.2.0 | |
with: | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
service_account_key: ${{ secrets.GCP_SA_KEY }} | |
export_default_credentials: true | |
# Verify GCP Authentication | |
- name: Verify GCP Authentication | |
run: gcloud auth list | |
# Validate the repository structure | |
- name: Validate repository structure | |
run: | | |
if [ ! -f "cloudbuild.yaml" ]; then | |
echo "cloudbuild.yaml not found, failing build." | |
exit 1 | |
fi | |
if [ ! -f "deployment/deploy_pipeline.py" ]; then | |
echo "deploy_pipeline.py not found, failing build." | |
exit 1 | |
fi | |
# Trigger Cloud Build | |
- name: Trigger Cloud Build | |
run: | | |
gcloud builds submit --config cloudbuild.yaml \ | |
--substitutions=_REGION=us-central1 | |
# Run smoke tests in Docker before deploying to Vertex AI | |
- name: Smoke Test | |
run: docker run music-recommender python -m unittest discover tests | |
# Deploy to Vertex AI with pinned versions of kfp and google-cloud-aiplatform | |
- name: Deploy to Vertex AI | |
run: | | |
pip install 'kfp==1.7.2' 'google-cloud-aiplatform==1.7.1' | |
python deployment/deploy_pipeline.py \ | |
--platform vertex \ | |
--project_id ${{ secrets.GCP_PROJECT_ID }} \ | |
--region us-central1 \ | |
--output_file pipeline.yaml |