Skip to content

Commit 8a44271

Browse files
committed
feat: update no. of workflows
1 parent 61762ae commit 8a44271

File tree

5 files changed

+66
-9
lines changed

5 files changed

+66
-9
lines changed

.github/workflows/blog-posts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v4
1313
- name: Update post list
1414
run: |
15-
cd scripts && npm install && npm run get:posts
15+
cd scripts && npm install && ACCESS_TOKEN=${{ secrets.ACCESS_TOKEN }} npm run get:posts
1616
- name: Commit changes
1717
run: |
1818
git config --local user.email "github-actions[bot]@users.noreply.github.com"

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ My name is Pulkit. I'm a undergraduate from 🇮🇳
100100

101101
---
102102

103+
### :bar_chart: Coding time in the last month
104+
105+
<picture>
106+
<source media="(prefers-color-scheme: dark)" srcset="https://wakatime.com/share/@pulkitxm/b09efaa2-860c-4ed4-afbe-4a645828d6fe.svg">
107+
<img src="https://wakatime.com/share/@pulkitxm/b09efaa2-860c-4ed4-afbe-4a645828d6fe.svg" width="100%" height="auto" style="max-height: 400px; object-fit: contain;">
108+
</picture>
109+
110+
<br/><br/>
111+
112+
---
113+
103114
### Let's Connect
104115

105116
- [LinkedIn](https://www.linkedin.com/in/pulkitxm)
@@ -108,9 +119,6 @@ My name is Pulkit. I'm a undergraduate from 🇮🇳
108119

109120
---
110121

111-
### :bar_chart: [Coding time in the last month](https://wakatime.com/@pulkitxm)
112-
113-
<picture>
114-
<source media="(prefers-color-scheme: dark)" srcset="https://wakatime.com/share/@pulkitxm/b09efaa2-860c-4ed4-afbe-4a645828d6fe.svg">
115-
<img align="right" width="100%" src="https://wakatime.com/share/@pulkitxm/b09efaa2-860c-4ed4-afbe-4a645828d6fe.svg">
116-
</picture>
122+
<!--START_SECTION:blog-posts-->
123+
*Note: All the data displayed above is updated automatically via GitHub Actions. There have been **3** workflow runs so far.*
124+
<!--END_SECTION:blog-posts-->

scripts/src/fetchFollowers.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if(process.env.ACCESS_TOKEN === undefined){
88

99
import { Octokit } from "@octokit/rest";
1010
import { readFileSync, writeFileSync } from "fs";
11+
import { updateWorkflowNumber } from "./updateWorkflowNumber.js";
1112
import { READMEFILE_PATH } from "./config.js";
1213

1314
const octokit = new Octokit({
@@ -65,4 +66,6 @@ async function main() {
6566
writeFileSync(READMEFILE_PATH, readme);
6667
}
6768

68-
main();
69+
main().then(async()=>{
70+
await updateWorkflowNumber()
71+
})

scripts/src/fetchLatestBlogPosts.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ dotenv.config();
33

44
import axios from "axios";
55
import { readFileSync, writeFileSync } from "fs";
6+
import { updateWorkflowNumber } from "./updateWorkflowNumber.js";
67
import { BlogsResponseSchema, READMEFILE_PATH } from "./config.js";
78

89
const fetchLatestBlogs = async () => {
@@ -68,4 +69,6 @@ async function main() {
6869
writeFileSync(READMEFILE_PATH, readme);
6970
}
7071

71-
main();
72+
main().then(async () => {
73+
await updateWorkflowNumber();
74+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import dotenv from "dotenv";
2+
dotenv.config();
3+
4+
if (process.env.ACCESS_TOKEN === undefined) {
5+
console.error("Please provide ACCESS_TOKEN in .env file");
6+
process.exit(1);
7+
}
8+
9+
import { Octokit } from "@octokit/rest";
10+
import { readFileSync, writeFileSync } from "fs";
11+
import { READMEFILE_PATH } from "./config.js";
12+
13+
const octokit = new Octokit({
14+
auth: process.env.ACCESS_TOKEN,
15+
});
16+
17+
const getWorflowCount = async () => {
18+
const username = "pulkitxm";
19+
const repoName = username;
20+
try {
21+
const response = await octokit.actions.listWorkflowRunsForRepo({
22+
owner: username,
23+
repo: repoName,
24+
});
25+
return response.data.total_count;
26+
} catch (error) {
27+
console.error(error.message);
28+
return 0;
29+
}
30+
};
31+
32+
export async function updateWorkflowNumber() {
33+
const workflowCount = await getWorflowCount();
34+
const readmeContent = readFileSync(READMEFILE_PATH, "utf-8");
35+
36+
const updatedContent = readmeContent.replace(
37+
/There have been \*\*\d+\*\* workflow runs so far\./,
38+
`There have been **${workflowCount}** workflow runs so far.`
39+
);
40+
41+
writeFileSync(READMEFILE_PATH, updatedContent, "utf-8");
42+
console.log("README file updated with the latest workflow count.");
43+
}

0 commit comments

Comments
 (0)