88jobs :
99 parse-and-commit :
1010 runs-on : ubuntu-latest
11-
1211 steps :
1312 - name : Checkout the 2024 branch
1413 uses : actions/checkout@v3
@@ -27,40 +26,26 @@ jobs:
2726 cd blog-repo
2827 git checkout pey-2024-test
2928
30- - name : Get latest commit hash from pey-archive
31- id : get_commit_hash
29+ - name : Check for new commits
30+ id : check_commits
3231 run : |
3332 cd pey-archive
34- echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_ENV
35-
36- - name : Load previous commit hash from cache
37- id : load_cache
38- run : |
39- echo "Loading previous commit hash from cache..."
40- echo "prev_commit_hash=$(cat ${{ github.workspace }}/commit_hash.txt || echo 'none')" >> $GITHUB_ENV
33+ git fetch origin main # Fetch the latest changes
34+ NEW_COMMITS=$(git rev-list HEAD...origin/main --count)
35+ echo "new_commits=$NEW_COMMITS" >> $GITHUB_ENV
4136
42- - name : Check if the commit has changed
43- id : check_commit
44- run : |
45- if [ "${{ env.prev_commit_hash }}" == "none" ]; then
46- echo "No previous commit hash found. Will run processing code."
47- echo "commit_changed=true" >> $GITHUB_ENV
48- elif [ "${{ env.commit_hash }}" != "${{ env.prev_commit_hash }}" ]; then
49- echo "Commit hash has changed. Will run processing code."
50- echo "commit_changed=true" >> $GITHUB_ENV
51- else
52- echo "Commit hash has not changed. Skipping processing code."
53- echo "commit_changed=false" >> $GITHUB_ENV
54- fi
37+ - name : Skip if no new commits
38+ if : env.new_commits == '0'
39+ run : echo "No new commits found. Skipping the workflow."
5540
5641 - name : Set up Python
57- if : env.commit_changed == 'true ' # Only run if the commit has changed
42+ if : env.new_commits != '0 ' # Only run if there are new commits
5843 uses : actions/setup-python@v4
5944 with :
6045 python-version : ' 3.x'
6146
6247 - name : Cache pip dependencies
63- if : env.commit_changed == 'true ' # Only run if the commit has changed
48+ if : env.new_commits != '0 ' # Only run if there are new commits
6449 uses : actions/cache@v3
6550 with :
6651 path : ~/.cache/pip
@@ -69,52 +54,52 @@ jobs:
6954 ${{ runner.os }}-pip-
7055
7156 - name : Install dependencies
72- if : env.commit_changed == 'true ' # Only run if the commit has changed
57+ if : env.new_commits != '0 ' # Only run if there are new commits
7358 run : pip install -r requirements.txt
7459
60+ - name : Delete existing JSON file
61+ if : env.new_commits != '0' # Only run if there are new commits
62+ run : |
63+ rm -f blog-repo/data/PEYJobPosting2024.json
64+
7565 - name : Run the parsing script
76- if : env.commit_changed == 'true ' # Only run if the commit has changed
66+ if : env.new_commits != '0 ' # Only run if there are new commits
7767 run : python parse_folder_to_db.py -v -d "pey-archive/postings" -o "blog-repo/data/PEYJobPosting2024.json"
7868
7969 - name : Configure git for commit
80- if : env.commit_changed == 'true ' # Only run if the commit has changed
70+ if : env.new_commits != '0 ' # Only run if there are new commits
8171 run : |
8272 git config --global user.name "github-actions[bot]"
8373 git config --global user.email "github-actions[bot]@users.noreply.github.com"
8474
8575 - name : Commit the new JSON file with timestamp
86- if : env.commit_changed == 'true ' # Only run if the commit has changed
76+ if : env.new_commits != '0 ' # Only run if there are new commits
8777 run : |
8878 cd blog-repo
8979 timestamp=$(date)
9080 git add data/PEYJobPosting2024.json
9181 git commit -m "Add updated PEY job postings data - $timestamp"
9282
9383 - name : View git log
94- if : env.commit_changed == 'true ' # Only run if the commit has changed
84+ if : env.new_commits != '0 ' # Only run if there are new commits
9585 run : |
9686 cd blog-repo
9787 git log --oneline
9888
9989 - name : Set up authentication for pushing changes
100- if : env.commit_changed == 'true ' # Only run if the commit has changed
90+ if : env.new_commits != '0 ' # Only run if there are new commits
10191 run : |
10292 cd blog-repo
10393 git remote set-url origin https://x-access-token:${{ secrets.GH_BLOG_TOKEN }}@github.com/sadmanca/blog.git
10494
10595 - name : Push changes to the blog repo
106- if : env.commit_changed == 'true ' # Only run if the commit has changed
96+ if : env.new_commits != '0 ' # Only run if there are new commits
10797 run : |
10898 cd blog-repo
10999 git push -u origin pey-2024-test
110100
111- - name : Save current commit hash to cache
112- if : env.commit_changed == 'true' # Only run if the commit has changed
113- run : |
114- echo "${{ env.commit_hash }}" > ${{ github.workspace }}/commit_hash.txt
115-
116101 - name : Send notification via curl
117- if : env.commit_changed == 'true ' # Only run if the commit has changed
102+ if : env.new_commits != '0 ' # Only run if there are new commits
118103 run : |
119104 current_time=$(date)
120105 curl -d "$current_time" ntfy.sh/sadmanca-uoft-pey-coop-jobs-dashboard-2024-2025
0 commit comments