-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (59 loc) · 2.52 KB
/
update_data.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
# checks if the required env variables and secrets are present
- name: Validate required variables and secrets
run: |
missing_vars=()
# Check for required variables
[ -z "${{ secrets.GITHUB_TOKEN }}" ] && missing_vars+=("secrets.GITHUB_TOKEN")
# If any variables are missing, print them and exit with an error
if [ ${#missing_vars[@]} -ne 0 ]; then
echo "Error: The following required variables are missing:"
printf '%s\n' "${missing_vars[@]}"
exit 1
fi
shell: bash
# 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 }}