-
Notifications
You must be signed in to change notification settings - Fork 8
115 lines (102 loc) · 4.71 KB
/
update_leaderboard_after_merge.yaml
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: Update leader board after submission merge.
on:
push:
branches:
- development
jobs:
update-file:
if: github.repository == 'infocusp/llm_seminar_series'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 10
- name: Get current commit details
id: commit_info
run: |
commit_author=$(git log --format='%an' -1)
commit_email=$(git log --format='%ae' -1)
echo "Current commit author is $commit_author ($commit_email)"
echo "commit_author=$commit_author" >> "$GITHUB_ENV"
echo "commit_email=$commit_email" >> "$GITHUB_ENV"
- name: Get merge commit hash
id: merge_commit
run: |
merge_commit=$(git log --merges --pretty=format:%H -1 $GITHUB_SHA)
echo "Found merge commit: $merge_commit"
echo "merge_commit=$merge_commit" >> "$GITHUB_ENV"
- name: Set original author
run: |
if [ -n "$merge_commit" ] && [ "$GITHUB_SHA" = "$merge_commit" ]; then
original_author=$(git log --format='%an' -n 2 $merge_commit | tail -n 1)
original_email=$(git log --format='%ae' -n 2 $merge_commit | tail -n 1)
echo "Author of original commit is $original_author ($original_email)"
else
original_author=$commit_author
original_email=$commit_email
echo "Not a merge commit. Setting original author as $commit_author($commit_email)."
fi
echo "original_author=$original_author" >> "$GITHUB_ENV"
echo "original_email=$original_email" >> "$GITHUB_ENV"
# # Merge commit has maintainer's name so we get name from second last commit
# - name: Get original author's name
# id: original_author
# run: |
# echo "Passed merge commit: $merge_commit"
# echo "$(git log --format='%ae' -n 2 $merge_commit)"
# original_author=$(git log --format='%an' -n 2 $merge_commit | tail -n 1)
# original_email=$(git log --format='%ae' -n 2 $merge_commit | tail -n 1)
# echo "Author of original commit is $original_author ($original_email)"
# # echo "::set-output name=original_author::$original_author"
# echo "original_author=$original_author" >> "$GITHUB_ENV"
- name: Check if there are any changes in submissions dir
uses: dorny/[email protected]
id: changes
with:
# Use context to get the branch where commits were pushed.
# If there is only one long-lived branch (e.g. master),
# you can specify it directly.
# If it's not configured, the repository default branch is used.
base: ${{ github.ref }}
filters: |
src:
- added|modified: 'session_2/challenge/submissions/**'
list-files: "shell"
- name: Print changed files
run: |
echo '${{ toJSON(steps.changes.outputs) }}'
- if: ${{ (steps.changes.outputs.src_count > 1) }}
uses: actions/github-script@v7
with:
script: core.setFailed('More than one submissions are not allowed at once.')
- if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r session_2/challenge/requirements.txt
- if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r session_2/challenge/requirements.txt
- if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
name: Run leaderboard update script
id: leaderboard-update
run: |
cd session_2/challenge
filename=$(basename "${{ steps.changes.outputs.src_files }}")
filename_without_extension="${filename%.*}" # Remove extension
echo "Author name: $original_author | Submission name: $filename_without_extension"
python -m scripts.leaderboard --github_name="$original_author" --prompt="$filename_without_extension"
- if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
name: Commit changes
uses: EndBug/add-and-commit@v9
with:
message: Updated leaderboard
default_author: github_actions