Skip to content

Commit eed5f90

Browse files
authored
Merge pull request #384 from anmol098/feat/ci-cd_test_for_action
Ability to test and review PR using CI/CD
2 parents e1576ed + 42e1f0e commit eed5f90

File tree

8 files changed

+231
-77
lines changed

8 files changed

+231
-77
lines changed

.github/workflows/ci.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
ci:
13+
name: Run Test and Review PR
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout 🛎️
18+
uses: actions/checkout@v3
19+
20+
- name: Setup Python 3.8 🐍
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: 3.8
24+
25+
- name: Install Dependencies 📥
26+
run: pip install -r requirements.txt
27+
28+
- name: Create Assets Folder 📥
29+
run: mkdir assets
30+
31+
- name: Create Previous Comments 🫣
32+
uses: int128/hide-comment-action@v1
33+
with:
34+
starts-with: "README stats current output:"
35+
36+
- name: Run Action Preview on Current Code 🧪
37+
id: make-stats
38+
env:
39+
INPUT_GH_TOKEN: ${{ secrets.INPUT_GITHUB_TOKEN }}
40+
INPUT_WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
41+
INPUT_SHOW_TIMEZONE: True
42+
INPUT_SHOW_PROJECTS: True
43+
INPUT_SHOW_EDITORS: True
44+
INPUT_SHOW_OS: True
45+
INPUT_SHOW_LANGUAGE: True
46+
INPUT_SYMBOL_VERSION: 1
47+
INPUT_SHOW_LINES_OF_CODE: True
48+
INPUT_SHOW_LOC_CHART: True
49+
INPUT_SHOW_PROFILE_VIEWS: True
50+
INPUT_SHOW_TOTAL_CODE_TIME: True
51+
INPUT_SHOW_SHORT_INFO: True
52+
INPUT_SHOW_COMMIT: True
53+
INPUT_SHOW_DAYS_OF_WEEK: True
54+
INPUT_SHOW_LANGUAGE_PER_REPO: True
55+
INPUT_SHOW_UPDATED_DATE: True
56+
INPUT_COMMIT_BY_ME: True
57+
INPUT_DEBUG_LOGGING: True # Not for prod
58+
DEBUG_RUN: True # Not for prod
59+
run: python3 sources/main.py
60+
61+
- name: Save Branch Name Without Slashes 📛
62+
if: ${{ github.ref != 'refs/heads/master' }}
63+
env:
64+
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
65+
run: |
66+
BRANCH_NAME=${{ env.BRANCH_NAME }}
67+
BRANCH_NAME=${BRANCH_NAME////_}
68+
echo BRANCH_NAME=${BRANCH_NAME} >> $GITHUB_ENV
69+
70+
- name: Upload Artifact 📦
71+
uses: actions/upload-artifact@v3
72+
if: ${{ github.ref != 'refs/heads/master' }}
73+
with:
74+
name: ${{ format('github-pages-for-branch-{0}', env.BRANCH_NAME) }}
75+
path: assets
76+
77+
- name: Create Comment 💬
78+
uses: jungwinter/comment@v1
79+
with:
80+
type: create
81+
body: ${{ steps.make-stats.outputs.README_CONTENT }}
82+
issue_number: ${{ github.event.number }}
83+
token: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ jobs:
108108

109109
```yml
110110
- uses: anmol098/waka-readme-stats@master
111-
with:
112-
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
113-
GH_TOKEN: ${{ secrets.GH_TOKEN }}
114-
SHOW_OS: "False"
115-
SHOW_PROJECTS: "False"
111+
with:
112+
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
113+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
114+
SHOW_OS: "False"
115+
SHOW_PROJECTS: "False"
116116
```
117117

118118
### Flags Available
@@ -288,14 +288,15 @@ Contributions are welcome! ♥! Please share any features, and add unit tests! U
288288
# Selected Contributors
289289

290290
1. [Anmol Pratap Singh](https://github.com/anmol098): Maintainer
291-
2. [Prabhat Singh](https://github.com/prabhatdev): For code timeline graph [#18](https://github.com/anmol098/waka-readme-stats/pull/18)
292-
2. [Aravind V. Nair](https://github.com/aravindvnair99): Maintainer and For Pull Request [#188](https://github.com/anmol098/waka-readme-stats/pull/188) And Other improvements
293-
3. [Hedy Li](https://github.com/hedythedev): For Pull Request [#34](https://github.com/anmol098/waka-readme-stats/pull/34) and [#23](https://github.com/anmol098/waka-readme-stats/pull/23)
294-
4. [Pedro Torres](https://github.com/Corfucinas): For Pull Request [#29](https://github.com/anmol098/waka-readme-stats/pull/29)
295-
5. [Aaron Meese](https://github.com/ajmeese7): For Pull Request [#45](https://github.com/anmol098/waka-readme-stats/pull/45)
296-
6. [Arnav Jindal](https://github.com/Daggy1234): For Pull Request [#48](https://github.com/anmol098/waka-readme-stats/pull/48)
297-
7. [Daniel Rowe](https://github.com/DanRowe): For Pull Request [#57](https://github.com/anmol098/waka-readme-stats/pull/57)
298-
8. [Ss5h](https://github.com/tlatkdgus1): For adding support for natural sentence writing for translation [#136](https://github.com/anmol098/waka-readme-stats/pull/136)
291+
2. [Alexander Sergeev](https://github.com/pseusys): Maintainer
292+
3. [Aravind V. Nair](https://github.com/aravindvnair99): Maintainer
293+
4. [Prabhat Singh](https://github.com/prabhatdev): For code timeline graph [#18](https://github.com/anmol098/waka-readme-stats/pull/18)
294+
5. [Hedy Li](https://github.com/hedythedev): For Pull Request [#34](https://github.com/anmol098/waka-readme-stats/pull/34) and [#23](https://github.com/anmol098/waka-readme-stats/pull/23)
295+
6. [Pedro Torres](https://github.com/Corfucinas): For Pull Request [#29](https://github.com/anmol098/waka-readme-stats/pull/29)
296+
7. [Aaron Meese](https://github.com/ajmeese7): For Pull Request [#45](https://github.com/anmol098/waka-readme-stats/pull/45)
297+
8. [Arnav Jindal](https://github.com/Daggy1234): For Pull Request [#48](https://github.com/anmol098/waka-readme-stats/pull/48)
298+
9. [Daniel Rowe](https://github.com/DanRowe): For Pull Request [#57](https://github.com/anmol098/waka-readme-stats/pull/57)
299+
10. [Ss5h](https://github.com/tlatkdgus1): For adding support for natural sentence writing for translation [#136](https://github.com/anmol098/waka-readme-stats/pull/136)
299300

300301
<details>
301302
<summary>Special mention for those who are currently making their profile readme more awesome :smile: :tada:</summary>
@@ -420,6 +421,10 @@ Contributions are welcome! ♥! Please share any features, and add unit tests! U
420421

421422
- [Muhammad Bilal](https://github.com/BilalJaved15)
422423

424+
- [Wyatt Walsh](https://www.github.com/wyattowalsh)
425+
426+
- [Nithin Balaji](https://github.com/thenithinbalaji)
427+
423428

424429

425430
</details>

sources/graphics_list_formatter.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from manager_download import DownloadManager as DM
88
from manager_environment import EnvironmentManager as EM
99
from manager_github import GitHubManager as GHM
10-
from manager_localization import LocalizationManager as LM
10+
from manager_file import FileManager as FM
1111

1212

1313
DAY_TIME_EMOJI = ["🌞", "🌆", "🌃", "🌙"] # Emojis, representing different times of day.
@@ -109,17 +109,17 @@ async def make_commit_day_time_list(time_zone: str) -> str:
109109
sum_week = sum(week_days)
110110
day_times = day_times[1:] + day_times[:1]
111111

112-
dt_names = [f"{DAY_TIME_EMOJI[i]} {LM.t(DAY_TIME_NAMES[i])}" for i in range(len(day_times))]
112+
dt_names = [f"{DAY_TIME_EMOJI[i]} {FM.t(DAY_TIME_NAMES[i])}" for i in range(len(day_times))]
113113
dt_texts = [f"{day_time} commits" for day_time in day_times]
114114
dt_percents = [round((day_time / sum_day) * 100, 2) for day_time in day_times]
115-
title = LM.t("I am an Early") if sum(day_times[0:2]) >= sum(day_times[2:4]) else LM.t("I am a Night")
115+
title = FM.t("I am an Early") if sum(day_times[0:2]) >= sum(day_times[2:4]) else FM.t("I am a Night")
116116
stats += f"**{title}** \n\n```text\n{make_list(names=dt_names, texts=dt_texts, percents=dt_percents, top_num=7, sort=False)}\n```\n"
117117

118118
if EM.SHOW_DAYS_OF_WEEK:
119-
wd_names = [LM.t(week_day) for week_day in WEEK_DAY_NAMES]
119+
wd_names = [FM.t(week_day) for week_day in WEEK_DAY_NAMES]
120120
wd_texts = [f"{week_day} commits" for week_day in week_days]
121121
wd_percents = [round((week_day / sum_week) * 100, 2) for week_day in week_days]
122-
title = LM.t("I am Most Productive on") % wd_names[wd_percents.index(max(wd_percents))]
122+
title = FM.t("I am Most Productive on") % wd_names[wd_percents.index(max(wd_percents))]
123123
stats += f"📅 **{title}** \n\n```text\n{make_list(names=wd_names, texts=wd_texts, percents=wd_percents, top_num=7, sort=False)}\n```\n"
124124

125125
return stats
@@ -144,5 +144,5 @@ def make_language_per_repo_list(repositories: Dict) -> str:
144144
percents = [round(language_count[lang]["count"] / len(repos_with_language) * 100, 2) for lang in names]
145145

146146
top_language = max(list(language_count.keys()), key=lambda x: language_count[x]["count"])
147-
title = f"**{LM.t('I Mostly Code in') % top_language}** \n\n" if len(repos_with_language) > 0 else ""
147+
title = f"**{FM.t('I Mostly Code in') % top_language}** \n\n" if len(repos_with_language) > 0 else ""
148148
return f"{title}```text\n{make_list(names=names, texts=texts, percents=percents)}\n```\n\n"

sources/main.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from manager_download import init_download_manager, DownloadManager as DM
1111
from manager_environment import EnvironmentManager as EM
1212
from manager_github import init_github_manager, GitHubManager as GHM
13-
from manager_localization import init_localization_manager, LocalizationManager as LM
13+
from manager_file import init_localization_manager, FileManager as FM
1414
from manager_debug import init_debug_manager, DebugManager as DBM
1515
from graphics_chart_drawer import create_loc_graph, GRAPH_PATH
1616
from yearly_commit_calculator import calculate_yearly_commit_data
@@ -33,33 +33,33 @@ async def get_waka_time_stats() -> str:
3333
stats += f"{await make_commit_day_time_list(data['data']['timezone'])}\n\n"
3434

3535
if EM.SHOW_TIMEZONE or EM.SHOW_LANGUAGE or EM.SHOW_EDITORS or EM.SHOW_PROJECTS or EM.SHOW_OS:
36-
no_activity = LM.t("No Activity Tracked This Week")
37-
stats += f"📊 **{LM.t('This Week I Spend My Time On')}** \n\n```text\n"
36+
no_activity = FM.t("No Activity Tracked This Week")
37+
stats += f"📊 **{FM.t('This Week I Spend My Time On')}** \n\n```text\n"
3838

3939
if EM.SHOW_TIMEZONE:
4040
DBM.i("Adding user timezone info...")
4141
time_zone = data["data"]["timezone"]
42-
stats += f"🕑︎ {LM.t('Timezone')}: {time_zone}\n\n"
42+
stats += f"🕑︎ {FM.t('Timezone')}: {time_zone}\n\n"
4343

4444
if EM.SHOW_LANGUAGE:
4545
DBM.i("Adding user top languages info...")
4646
lang_list = no_activity if len(data["data"]["languages"]) == 0 else make_list(data["data"]["languages"])
47-
stats += f"💬 {LM.t('Languages')}: \n{lang_list}\n\n"
47+
stats += f"💬 {FM.t('Languages')}: \n{lang_list}\n\n"
4848

4949
if EM.SHOW_EDITORS:
5050
DBM.i("Adding user editors info...")
5151
edit_list = no_activity if len(data["data"]["editors"]) == 0 else make_list(data["data"]["editors"])
52-
stats += f"🔥 {LM.t('Editors')}: \n{edit_list}\n\n"
52+
stats += f"🔥 {FM.t('Editors')}: \n{edit_list}\n\n"
5353

5454
if EM.SHOW_PROJECTS:
5555
DBM.i("Adding user projects info...")
5656
project_list = no_activity if len(data["data"]["projects"]) == 0 else make_list(data["data"]["projects"])
57-
stats += f"🐱‍💻 {LM.t('Projects')}: \n{project_list}\n\n"
57+
stats += f"🐱‍💻 {FM.t('Projects')}: \n{project_list}\n\n"
5858

5959
if EM.SHOW_OS:
6060
DBM.i("Adding user operating systems info...")
6161
os_list = no_activity if len(data["data"]["operating_systems"]) == 0 else make_list(data["data"]["operating_systems"])
62-
stats += f"💻 {LM.t('operating system')}: \n{os_list}\n\n"
62+
stats += f"💻 {FM.t('operating system')}: \n{os_list}\n\n"
6363

6464
stats = f"{stats[:-1]}```\n\n"
6565

@@ -75,44 +75,44 @@ async def get_short_github_info() -> str:
7575
:returns: String representation of the info.
7676
"""
7777
DBM.i("Adding short GitHub info...")
78-
stats = f"**🐱 {LM.t('My GitHub Data')}** \n\n"
78+
stats = f"**🐱 {FM.t('My GitHub Data')}** \n\n"
7979

8080
DBM.i("Adding user disk usage info...")
8181
if GHM.USER.disk_usage is None:
82-
disk_usage = LM.t("Used in GitHub's Storage") % "?"
82+
disk_usage = FM.t("Used in GitHub's Storage") % "?"
8383
DBM.p("Please add new github personal access token with user permission!")
8484
else:
85-
disk_usage = LM.t("Used in GitHub's Storage") % naturalsize(GHM.USER.disk_usage)
85+
disk_usage = FM.t("Used in GitHub's Storage") % naturalsize(GHM.USER.disk_usage)
8686
stats += f"> 📦 {disk_usage} \n > \n"
8787

8888
data = await DM.get_remote_json("github_stats")
8989
DBM.i("Adding contributions info...")
9090
if len(data["years"]) > 0:
91-
contributions = LM.t("Contributions in the year") % (intcomma(data["years"][0]["total"]), data["years"][0]["year"])
91+
contributions = FM.t("Contributions in the year") % (intcomma(data["years"][0]["total"]), data["years"][0]["year"])
9292
stats += f"> 🏆 {contributions}\n > \n"
9393
else:
9494
DBM.p("GitHub contributions data unavailable!")
9595

9696
DBM.i("Adding opted for hire info...")
9797
opted_to_hire = GHM.USER.hireable
9898
if opted_to_hire:
99-
stats += f"> 💼 {LM.t('Opted to Hire')}\n > \n"
99+
stats += f"> 💼 {FM.t('Opted to Hire')}\n > \n"
100100
else:
101-
stats += f"> 🚫 {LM.t('Not Opted to Hire')}\n > \n"
101+
stats += f"> 🚫 {FM.t('Not Opted to Hire')}\n > \n"
102102

103103
DBM.i("Adding public repositories info...")
104104
public_repo = GHM.USER.public_repos
105105
if public_repo != 1:
106-
stats += f"> 📜 {LM.t('public repositories') % public_repo} \n > \n"
106+
stats += f"> 📜 {FM.t('public repositories') % public_repo} \n > \n"
107107
else:
108-
stats += f"> 📜 {LM.t('public repository') % public_repo} \n > \n"
108+
stats += f"> 📜 {FM.t('public repository') % public_repo} \n > \n"
109109

110110
DBM.i("Adding private repositories info...")
111111
private_repo = GHM.USER.owned_private_repos if GHM.USER.owned_private_repos is not None else 0
112112
if public_repo != 1:
113-
stats += f"> 🔑 {LM.t('private repositories') % private_repo} \n > \n"
113+
stats += f"> 🔑 {FM.t('private repositories') % private_repo} \n > \n"
114114
else:
115-
stats += f"> 🔑 {LM.t('private repository') % private_repo} \n > \n"
115+
stats += f"> 🔑 {FM.t('private repository') % private_repo} \n > \n"
116116

117117
DBM.g("Short GitHub info added!")
118118
return stats
@@ -144,13 +144,13 @@ async def get_stats() -> str:
144144
if EM.SHOW_PROFILE_VIEWS:
145145
DBM.i("Adding profile views info...")
146146
data = GHM.REPO.get_views_traffic(per="week")
147-
stats += f"![Profile Views](http://img.shields.io/badge/{quote(LM.t('Profile Views'))}-{data['count']}-blue)\n\n"
147+
stats += f"![Profile Views](http://img.shields.io/badge/{quote(FM.t('Profile Views'))}-{data['count']}-blue)\n\n"
148148

149149
if EM.SHOW_LINES_OF_CODE:
150150
DBM.i("Adding lines of code info...")
151151
total_loc = sum([yearly_data[y][q][d] for y in yearly_data.keys() for q in yearly_data[y].keys() for d in yearly_data[y][q].keys()])
152-
data = f"{intword(total_loc)} {LM.t('Lines of code')}"
153-
stats += f"![Lines of code](https://img.shields.io/badge/{quote(LM.t('From Hello World I have written'))}-{quote(data)}-blue)\n\n"
152+
data = f"{intword(total_loc)} {FM.t('Lines of code')}"
153+
stats += f"![Lines of code](https://img.shields.io/badge/{quote(FM.t('From Hello World I have written'))}-{quote(data)}-blue)\n\n"
154154

155155
if EM.SHOW_SHORT_INFO:
156156
stats += await get_short_github_info()
@@ -163,9 +163,7 @@ async def get_stats() -> str:
163163

164164
if EM.SHOW_LOC_CHART:
165165
await create_loc_graph(yearly_data, GRAPH_PATH)
166-
GHM.update_chart(GRAPH_PATH)
167-
chart_path = f"{GHM.USER.login}/{GHM.USER.login}/{GHM.branch()}/{GRAPH_PATH}"
168-
stats += f"**{LM.t('Timeline')}**\n\n![Lines of Code chart](https://raw.githubusercontent.com/{chart_path})\n\n"
166+
stats += GHM.update_chart(GRAPH_PATH)
169167

170168
if EM.SHOW_UPDATED_DATE:
171169
DBM.i("Adding last updated time...")
@@ -181,12 +179,17 @@ async def main():
181179
Initializes all managers, collects user info and updates README.md if necessary.
182180
"""
183181
init_github_manager()
184-
await init_download_manager()
182+
await init_download_manager(GHM.USER.login)
185183
init_localization_manager()
186184
DBM.i("Managers initialized.")
187185

188-
if GHM.update_readme(await get_stats()):
189-
DBM.g("Readme updated!")
186+
stats = await get_stats()
187+
if not EM.DEBUG_RUN:
188+
if GHM.update_readme(stats):
189+
DBM.g("Readme updated!")
190+
else:
191+
GHM.set_github_output(stats)
192+
DBM.g("Debug run, readme not updated. Check the latest comment for the generated stats.")
190193
await DM.close_remote_resources()
191194

192195

0 commit comments

Comments
 (0)