Skip to content

Update data on a schedule #19

Update data on a schedule

Update data on a schedule #19

Workflow file for this run

name: Update data on a schedule
on:
schedule:
- cron: 0 0 1 * * # Runs on the first day of every month
workflow_dispatch: # Can be run manually if needed
jobs:
update-data:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository and create a pull request
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
# Downloads and extracts the files to the respective directory
- name: Run the data download script
run: |
cd ./noaa-cpfp-point
./download.sh
# Runs the data preprocessing and aggregation on the extracted files
- name: Run data preprocessing and aggregation on the downloaded data
run: |
cd ./noaa-cpfp-point/data_processing
pip install -r ./requirements.txt
python3 ./main.py
- name: Set current date as env variable
run: echo "NOW=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
# Commit all changed files to a new branch back to the repository
- name: Commit changes to a new branch
id: commit-changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Update data
create_branch: true
branch: update-data-${{ env.NOW }}
# file_pattern: 'data/**'
file_pattern: './noaa-cpfp-point/data/**'
# Create a PR from the new branch (if there was a change) to main
- name: Create pull request to main
if: steps.commit-changes.outputs.changes_detected == 'true'
run: |
echo -e "📅 Scheduled data update ${{ env.NOW }}. 🔔 @slesaad\nAutomatically created by Github action" > msg
gh pr create -H update-data-${{ env.NOW }} -B main --title 'Update data ${{ env.NOW }}' --body-file msg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}