Skip to content

Commit

Permalink
Setup GitHub Action with essential files
Browse files Browse the repository at this point in the history
  • Loading branch information
G0v1ndD3v committed Dec 25, 2024
1 parent 8e2a51d commit a51ba9c
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .github/workflows/update_readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Update README with Random Quote"

on:
schedule:
- cron: "0 0 * * *" # Run daily at midnight (UTC)
workflow_dispatch: # Manual trigger

jobs:
update-readme:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker
uses: docker/setup-buildx-action@v2

- name: Build and run the action
uses: ./
with:
quotes_file: "data/quotes.json"
readme_file: "README.md"

- name: Commit changes
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git add README.md
git commit -m "Update README with random quote" || echo "No changes to commit"
git push
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.9-slim

# Set working directory
WORKDIR /app

# Copy repository files
COPY . /app

# Run Python script
CMD ["python", "update_readme.py"]
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# QuoteThisAction
A GitHub Action that delivers developer quotes.
A GitHub Action I created to share my favorite quotes on my profile.

## Quote of the Day

<!-- START QUOTE -->
<!-- END QUOTE -->

## License
This project is licensed under the terms & conditions (T&Cs) of the MIT license. If you're interested in reading more about it, please take a look at the [LICENSE](./LICENSE) document.
21 changes: 21 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "QuoteThisAction"
description: "A GitHub Action that delivers developer quotes."
author: "Govind S Nair"

inputs:
quotes_file:
description: "Path to the quotes.json file"
required: true
default: "data/quotes.json"
readme_file:
description: "Path to the README.md file"
required: true
default: "README.md"

runs:
using: "docker"
image: "Dockerfile"

branding:
icon: "book"
color: "blue"
102 changes: 102 additions & 0 deletions data/quotes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[
{
"text": "Premature optimization is the root of all evil.",
"autor": "Donald Knuth"
},
{
"text": "The best way to predict the future is to invent it.",
"autor": "Alan Kay"
},
{
"text": "The most dangerous phrase in the English language is 'We've always done it this way'.",
"autor": "Grace Hopper"
},
{
"text": "There are only two hard things in computer science: cache invalidation and naming things.",
"autor": "Phil Karlton"
},
{
"text": "The computer was born to solve problems that did not exist before.",
"autor": "Bill Gates"
},
{
"text": "Measuring programming progress by lines of code is like measuring aircraft building progress by weight.",
"autor": "Bill Gates"
},
{
"text": "The three great virtues of a programmer: laziness, impatience, and hubris.",
"autor": "Larry Wall"
},
{
"text": "Code is like humor. When you have to explain it, it’s bad.",
"autor": "Cory House"
},
{
"text": "Write tests until fear is transformed into boredom.",
"autor": "Kent Beck"
},
{
"text": "Computer Science is no more about computers than astronomy is about telescopes.",
"autor": "Edsger W. Dijkstra"
},
{
"text": "Simplicity is prerequisite for reliability.",
"autor": "Edsger W. Dijkstra"
},
{
"text": "The computing scientist’s main challenge is not to get confused by the complexities of his own making.",
"autor": "Edsger W. Dijkstra"
},
{
"text": "An algorithm must be seen to be believed.",
"autor": "Donald Knuth"
},
{
"text": "If you think your users are idiots, only idiots will use it.",
"autor": "Linus Torvalds"
},
{
"text": "First, solve the problem. Then, write the code.",
"autor": "John Johnson"
},
{
"text": "The function of good software is to make the complex appear to be simple.",
"autor": "Grady Booch"
},
{
"text": "The task of the software development team is to engineer the illusion of simplicity.",
"autor": "Grady Booch"
},
{
"text": "In God we trust, all others must bring data.",
"autor": "W. Edwards Deming"
},
{
"text": "If you can't describe what you are doing as a process, you don't know what you're doing.",
"autor": "W. Edwards Deming"
},
{
"text": "Much of the essence of building a program is in fact the debugging of the specification.",
"autor": "Fred Brooks"
},
{
"text": "When debugging, novices insert corrective code; experts remove defective code.",
"autor": "Richard E. Pattis"
},
{
"text": "In programming the hard part isn’t solving problems, but deciding what problems to solve.",
"autor": "Paul Graham"
},
{
"text": "Prolific programmers contribute to certain disaster.",
"autor": "Niklaus Wirth"
},
{
"text": "Software gets slower faster than hardware gets faster.",
"autor": "Niklaus Wirth"
},
{
"text": "You can’t have great software without a great team, and most software is not great.",
"autor": "Joel Spolsky"
}
]
40 changes: 40 additions & 0 deletions update_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import json
import random
from pathlib import Path

# Paths
DATA_FILE = Path("data/quotes.json")
README_FILE = Path("README.md")

def get_random_quote():
with open(DATA_FILE, "r", encoding="utf-8") as file:
quotes = json.load(file)
return random.choice(quotes)

def update_readme(quote):
with open(README_FILE, "r", encoding="utf-8") as file:
lines = file.readlines()

# Look for a placeholder in the README
start_marker = "<!-- START QUOTE -->"
end_marker = "<!-- END QUOTE -->"
start_index = lines.index(f"{start_marker}\n") + 1
end_index = lines.index(f"{end_marker}\n")

# Replace the quote section
lines[start_index:end_index] = [
"```\n",
f"{quote['text']}\n",
f"— {quote['autor']}\n",
"```\n",
]

with open(README_FILE, "w", encoding="utf-8") as file:
file.writelines(lines)

def main():
quote = get_random_quote()
update_readme(quote)

if __name__ == "__main__":
main()

0 comments on commit a51ba9c

Please sign in to comment.