Merge branch 'main' of github.com:raminmohammadi/MLOps #105
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: Model Retraining on Push to Main - Github Lab 2 | |
| on: | |
| push: | |
| branches: | |
| - main # Trigger the workflow on pushes to the main branch | |
| jobs: | |
| retrain: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: 3.9 | |
| - name: Install dependencies | |
| run: pip install -r Labs/Github_Labs/Lab2/requirements.txt | |
| - name: Generate and Store Timestamp | |
| id: timestamp | |
| run: | | |
| timestamp=$(date '+%Y%m%d%H%M%S') | |
| echo "$timestamp" > timestamp.txt | |
| echo "timestamp=$timestamp" >> $GITHUB_ENV | |
| - name: Check File Permissions | |
| run: ls -l Labs/Github_Labs/Lab2/src/train_model.py | |
| - name: Set File Permissions | |
| run: chmod +x Labs/Github_Labs/Lab2/src/train_model.py | |
| - name: Retrain Model | |
| run: | | |
| python Labs/Github_Labs/Lab2/src/train_model.py --timestamp "$timestamp" | |
| - name: Evaluate Model and Log Metrics | |
| run: | | |
| python Labs/Github_Labs/Lab2/src/evaluate_model.py --timestamp "$timestamp" | |
| metrics_filename="${timestamp}_metrics.json" | |
| mkdir -p Labs/Github_Labs/Lab2/metrics | |
| mv "$metrics_filename" "Labs/Github_Labs/Lab2/metrics/$metrics_filename" | |
| - name: Store and Version the New Model | |
| run: | | |
| model_filename="model_${timestamp}_dt_model.joblib" | |
| mkdir -p Labs/Github_Labs/Lab2/models | |
| mv "$model_filename" "Labs/Github_Labs/Lab2/models/$model_filename" | |
| - name: Commit and Push Changes | |
| run: | | |
| git config --global user.email "26876927+raminmohammadi@users.noreply.github.com" | |
| git config --global user.name "raminmohammadi" | |
| metrics_filename="Labs/Github_Labs/Lab2/metrics/${timestamp}_metrics.json" | |
| model_filename="Labs/Github_Labs/Lab2/models/model_${timestamp}_dt_model.joblib" | |
| git add -f "$metrics_filename" "$model_filename" | |
| # Commit only if there are changes | |
| if ! git diff --cached --quiet; then | |
| git commit -m "Add metrics and updated model for $timestamp" | |
| git push | |
| else | |
| echo "No changes to commit." | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |