Run Model #242
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: Run Model | |
on: | |
workflow_run: | |
workflows: ["Update Model"] | |
branches: [main] | |
types: | |
- completed | |
workflow_dispatch: | |
jobs: | |
run-script: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.ELECTIONMODELKEY }} | |
- name: Install & unlock git-crypt | |
run: | | |
if ! command -v git-crypt &> /dev/null; then | |
sudo apt-get update | |
sudo apt-get install -y git-crypt | |
fi | |
echo "${{ secrets.GIT_CRYPT_KEY }}" | base64 -d > ./production.env.key | |
git-crypt unlock ./production.env.key | |
rm ./production.env.key | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
cache: 'pip' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Run the script | |
run: | | |
python code/ModelPredicting.py --all | |
- name: Commit and push if there are changes | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "actions@users.noreply.github.com" | |
git pull | |
git add . | |
git diff-index --quiet HEAD || git commit -m "Run model" | |
git-crypt lock | |
git diff-index --quiet HEAD || git commit -m "Run model" | |
git push https://${{ secrets.GITHUB_ACTOR }}:${{ secrets.ELECTIONMODELKEY }}@github.com/BPR-Data-Team/ElectionModel2024.git |