Skip to content

Commit 5d81214

Browse files
Update update-readme.yml
1 parent e699c20 commit 5d81214

File tree

1 file changed

+25
-83
lines changed

1 file changed

+25
-83
lines changed
Lines changed: 25 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,43 @@
1-
name: Update
1+
name: Update README
2+
23
on:
34
workflow_dispatch:
4-
schedule:
5-
- cron: '0 0 * * *'
65

76
jobs:
87
update-readme:
98
runs-on: ubuntu-latest
109

11-
permissions:
12-
contents: write
13-
packages: write
14-
1510
steps:
16-
# Check if the README file exists
17-
- name: Check for README file
18-
run: |
19-
if [ ! -f ./README.md ]; then
20-
echo "README file not found"
21-
exit 1
22-
else
23-
echo "README file found"
24-
fi
25-
26-
- name: Install dependencies
27-
run: |
28-
npm install axios fs
29-
30-
- name: Run the script
31-
uses: actions/github-script@v5
11+
- name: Checkout Repository
12+
uses: actions/checkout@v2
3213
with:
33-
script: |
34-
const axios = require("axios");
35-
const fs = require("fs");
36-
const os = require("os");
37-
38-
const owner = "kaal-coder";
39-
const repo = "hacktoberfest2023";
40-
const filePath = "./README.md";
41-
42-
const fetchDataAndUpdateReadme = async () => {
43-
try {
44-
// Fetch contributors' data from kaal-coder/hacktoberfest2023
45-
const response = await axios.get(
46-
`https://api.github.com/repos/${owner}/${repo}/contributors`
47-
);
48-
const contributors = response.data;
14+
ref: main # Replace with the desired branch name
4915

50-
// Build a new list of contributors with images and names
51-
let contributorsList = "## Contributors to this Repository\n\n";
52-
contributors.forEach((contributor) => {
53-
contributorsList += `<a href="https://github.com/${contributor.login}" target="_blank"><img src="${contributor.avatar_url}" alt="${contributor.login}" style="border-radius: 50%; width: 50px; height: 50px;"></a>\n`;
54-
});
55-
56-
// Read your existing README content with consistent line endings
57-
let readmeContent = fs
58-
.readFileSync(filePath, "utf8")
59-
.replace(/\r\n/g, "\n");
60-
61-
// Check if the "Contributors to this Repository" section already exists
62-
const sectionExists = readmeContent.includes(
63-
"## Contributors to this Repository"
64-
);
65-
66-
if (sectionExists) {
67-
// If the section exists, replace it with the new contributors
68-
const startIndex = readmeContent.indexOf(
69-
"## Contributors to this Repository"
70-
);
71-
const endIndex = readmeContent.indexOf("##", startIndex + 1);
72-
readmeContent =
73-
readmeContent.slice(0, startIndex) +
74-
contributorsList +
75-
readmeContent.slice(endIndex);
76-
} else {
77-
// If the section doesn't exist, simply add it with the new contributors
78-
readmeContent += contributorsList;
79-
}
80-
81-
// Write the updated content with consistent line endings
82-
fs.writeFileSync(
83-
filePath,
84-
readmeContent.replace(/\n/g, os.EOL),
85-
"utf8"
86-
);
87-
console.log("Updated Readme.md with new contributors section");
88-
} catch (error) {
89-
console.error("Error:", error);
90-
}
91-
};
16+
- name: Install Node.js and Dependencies
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: '14' # Use the Node.js version you need
9220

93-
fetchDataAndUpdateReadme();
21+
- name: Install Dependencies
22+
run: |
23+
npm install axios fs
24+
working-directory: ${{ github.workspace }}
9425

26+
- name: Debug
27+
run: |
28+
echo "Contents of the workspace:"
29+
ls -la
30+
cat README.md
31+
working-directory: ${{ github.workspace }}
32+
33+
- name: Run External Script
34+
run: node ./updateReadme.js
35+
9536
- name: Commit and Push Changes
9637
run: |
9738
git config user.name "${GITHUB_ACTOR}"
9839
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
9940
git add .
10041
git commit -m "Update README and dynamic content"
101-
git push origin HEAD:main # Replace 'main' with your branch name if different || { echo "Git push failed"; exit 0; }
42+
git push origin HEAD:main # Replace 'main' with your branch name if different
43+
working-directory: ${{ github.workspace }}

0 commit comments

Comments
 (0)