Skip to content

Train and save model to GCS #9

Train and save model to GCS

Train and save model to GCS #9

name: Train and save model to GCS # Define the name of the GitHub Actions workflow
on:
schedule:
- cron: '0 0 * * *' # Run every day at midnight
workflow_dispatch: # Allow manual trigger of the workflow
jobs:
train_and_save: # Define a job called "train_and_save"
runs-on: ubuntu-latest # Specify the runner environment to use the latest version of Ubuntu
steps:
- name: Checkout the code # First step: Checkout the repository code
uses: actions/checkout@v4 # Use GitHub's checkout action, version 4
- name: Set up Python # Set up a specific Python version for the runner
uses: actions/setup-python@v5 # Use the setup-python action, version 5
with:
python-version: '3.11' # Specify the Python version to set up
- name: Get cache dir # Get the directory where pip caches files
id: pip-cache-dir # Assign an ID to reference this step's outputs
run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT # Output the pip cache directory to use in subsequent steps
- name: Cache pip dependencies # Cache the pip dependencies to speed up builds
uses: actions/cache@v4 # Use the cache action, version 4
with:
path: ${{ steps.pip-cache-dir.outputs.dir }} # Specify the path to cache based on the previous step
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} # Define a key for the cache
restore-keys: | # Define fallback keys to restore the cache if exact match not found
${{ runner.os }}-pip-
- name: Install dependencies # Install project dependencies
run: |
python -m pip install --upgrade pip # Upgrade pip to the latest version
pip install -r Labs/Github_Labs/Lab3/requirements.txt # Install dependencies from the requirements.txt file
- name: Authenticate with GCP # Authenticate to Google Cloud Platform
uses: 'google-github-actions/auth@v2' # Use the Google authentication action, version 2
with:
credentials_json: '${{ secrets.GCP_SA_KEY }}' # Use GCP service account key stored in GitHub secrets
- name: Train and save model # Train the model and save it to Google Cloud Storage
run: |
python Labs/Github_Labs/Lab3/train_and_save_model.py # Run the script to train the model and save it