Skip to content

Commit d055ebc

Browse files
committed
Fix username
1 parent e4268b9 commit d055ebc

File tree

1 file changed

+54
-23
lines changed

1 file changed

+54
-23
lines changed

.github/workflows/update_leaderboard_after_merge.yaml

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ jobs:
1414
with:
1515
fetch-depth: 10
1616

17+
- name: Get merge commit hash
18+
id: merge_commit
19+
with:
20+
fetch-depth: 10
21+
22+
- name: Get current commit details
23+
id: commit_info
24+
run: |
25+
commit_author=$(git log --format='%an' -1)
26+
commit_email=$(git log --format='%ae' -1)
27+
echo "Current commit author is $commit_author ($commit_email)"
28+
echo "commit_author=$commit_author" >> "$GITHUB_ENV"
29+
echo "commit_email=$commit_email" >> "$GITHUB_ENV"
30+
1731
- name: Get merge commit hash
1832
id: merge_commit
1933
run: |
@@ -25,14 +39,36 @@ jobs:
2539
# Merge commit has maintainer's name so we get name from second last commit
2640
- name: Get original author's name
2741
id: original_author
42+
merge_commit=$(git log --merges --pretty=format:%H -1 $GITHUB_SHA)
43+
echo "Found merge commit: $merge_commit"
44+
# echo "::set-output name=merge_commit::$merge_commit"
45+
echo "merge_commit=$merge_commit" >> "$GITHUB_ENV"
46+
47+
- name: Set original author
2848
run: |
29-
echo "Passed merge commit: $merge_commit"
30-
echo "$(git log --format='%ae' -n 2 $merge_commit)"
31-
original_author=$(git log --format='%an' -n 2 $merge_commit | tail -n 1)
32-
original_email=$(git log --format='%ae' -n 2 $merge_commit | tail -n 1)
33-
echo "Author of original commit is $original_author ($original_email)"
34-
# echo "::set-output name=original_author::$original_author"
49+
if [ -n "$merge_commit" ] && [ "$GITHUB_SHA" = "$merge_commit" ]; then
50+
original_author=$(git log --format='%an' -n 2 $merge_commit | tail -n 1)
51+
original_email=$(git log --format='%ae' -n 2 $merge_commit | tail -n 1)
52+
echo "Author of original commit is $original_author ($original_email)"
53+
else
54+
original_author=$commit_author
55+
original_email=$commit_email
56+
echo "No merge commit found. Setting original author as $commit_author($commit_email)."
57+
fi
3558
echo "original_author=$original_author" >> "$GITHUB_ENV"
59+
echo "original_email=$original_email" >> "$GITHUB_ENV"
60+
61+
# # Merge commit has maintainer's name so we get name from second last commit
62+
# - name: Get original author's name
63+
# id: original_author
64+
# run: |
65+
# echo "Passed merge commit: $merge_commit"
66+
# echo "$(git log --format='%ae' -n 2 $merge_commit)"
67+
# original_author=$(git log --format='%an' -n 2 $merge_commit | tail -n 1)
68+
# original_email=$(git log --format='%ae' -n 2 $merge_commit | tail -n 1)
69+
# echo "Author of original commit is $original_author ($original_email)"
70+
# # echo "::set-output name=original_author::$original_author"
71+
# echo "original_author=$original_author" >> "$GITHUB_ENV"
3672

3773

3874
- name: Check if there are any changes in submissions dir
@@ -58,22 +94,17 @@ jobs:
5894
with:
5995
script: core.setFailed('More than one submissions are not allowed at once.')
6096

61-
# # TODO(hetul): Get github profile from email https://api.github.com/search/users?q=EMAIL
62-
# - if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
63-
# name: Get author's name from last commit
64-
# id: author_name
65-
# run: |
66-
# # author_name=$(git log -1 --pretty=format:'%an' -- "${{ steps.changes.outputs.src_files }}")
67-
# author_name=$("${{ github.event.commits[0].author.name }}")
68-
# echo Last author $author_name
69-
# echo "{author_name}={$author_name}" >> $GITHUB_OUTPUT
70-
7197
- if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
7298
name: Install Python
7399
uses: actions/setup-python@v5
74100
with:
75101
python-version: "3.10"
76102

103+
- if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
104+
name: Install dependencies
105+
run: |
106+
python -m pip install --upgrade pip
107+
pip install -r session_2/challenge/requirements.txt
77108
- if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
78109
name: Install dependencies
79110
run: |
@@ -88,11 +119,11 @@ jobs:
88119
filename=$(basename "${{ steps.changes.outputs.src_files }}")
89120
filename_without_extension="${filename%.*}" # Remove extension
90121
echo "Author name: $original_author | Submission name: $filename_without_extension"
91-
python -m scripts.leaderboard --github_name="${{ steps.author_name.outputs.author_name }}" --prompt="$filename_without_extension"
122+
python -m scripts.leaderboard --github_name="$original_author" --prompt="$filename_without_extension"
92123
93-
# - if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
94-
# name: Commit changes
95-
# uses: EndBug/add-and-commit@v9
96-
# with:
97-
# message: Updated leaderboard
98-
# default_author: github_actions
124+
- if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
125+
name: Commit changes
126+
uses: EndBug/add-and-commit@v9
127+
with:
128+
message: Updated leaderboard
129+
default_author: github_actions

0 commit comments

Comments
 (0)