Skip to content

Commit a95c00b

Browse files
authored
Refined automation workflow
- Updated condition to run the job. - Provided version to Python. - Added logic to pull any newly added changes to avoid push failure. - Printed only diffs instead of whole files. - Grouped related logs
1 parent cde145c commit a95c00b

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

.github/workflows/update-contributors-details.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,39 @@ on:
55
types: [closed]
66
branches: [main]
77

8-
env:
9-
REPO_NAME: ${{ github.repository }}
10-
PR_NUMBER: ${{ github.event.pull_request.number }}
11-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12-
138
jobs:
149
update-by-pr:
15-
if: ${{ github.event.pull_request.title != 'init' && github.event.pull_request.merged == true }}
10+
if: |
11+
github.event.pull_request.merged == true &&
12+
!contains(github.event.pull_request.title, 'maintenance') &&
13+
!contains(github.event.pull_request.title, 'Maintenance')
14+
1615
runs-on: ubuntu-latest
1716

1817
permissions:
1918
contents: write
2019

20+
env:
21+
REPO_NAME: ${{ github.repository }}
22+
PR_NUMBER: ${{ github.event.pull_request.number }}
23+
2124
steps:
2225
- name: Checking out the repo
2326
uses: actions/checkout@v4.1.0
2427

2528
- name: Setup Python
2629
uses: actions/setup-python@v4.7.1
30+
with:
31+
python-version: 3.12
2732

2833
- name: Getting PR details
2934
run: |
3035
touch pr.json
3136
gh pr view $PR_NUMBER --json author,url,files > pr.json
37+
cat pr.json
38+
39+
- name: Pull any new changes
40+
run: git pull origin main
3241

3342
- name: Updating log file
3443
run: |
@@ -37,27 +46,36 @@ jobs:
3746
echo "Create `.github/data` directory"
3847
fi
3948
python .github/scripts/update_contributors_log.py
40-
cat .github/data/contributors-log.json
49+
git diff .github/data/contributors-log.json
4150
4251
- name: Updating index.md file
4352
run: |
4453
python .github/scripts/update_index_md.py
45-
cat index.md
54+
git diff index.md
4655
4756
- name: Remove unwanted files
4857
run: rm pr.json
4958

5059
- name: Commit and Push
5160
run: |
5261
if [ "$(git status | grep 'Changes not staged\|Untracked files')" ]; then
62+
echo "::group::Printing All Diffs"
5363
git diff
64+
echo "::endgroup::"
65+
66+
echo "::group::Configuring GitHub Action as author"
5467
git config --global user.email "actions@github.com"
5568
git config --global user.name "GitHub Actions"
69+
git config --list | cat
70+
echo "::endgroup::"
71+
72+
echo "::group::Adding and Pushing Changes"
5673
git add .
5774
git commit -m "Updated Contributors Details"
5875
git push origin main
5976
echo "Pushed the update successfully"
77+
echo "::endgroup::"
6078
else
61-
echo "Nothing to push"
79+
echo "::error::No Changes detected!"
6280
exit 1
6381
fi

0 commit comments

Comments
 (0)