From a403b7e04ca7557e4dcc85e81563a4fc14775d4d Mon Sep 17 00:00:00 2001 From: Chuck Smith Date: Mon, 15 Jul 2024 07:23:08 -0400 Subject: [PATCH 1/3] Add update banner --- .github/workflows/update-banner.yml | 21 +++++++++++++++++++++ README.md | 2 ++ src/update_banner.py | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 .github/workflows/update-banner.yml create mode 100644 src/update_banner.py diff --git a/.github/workflows/update-banner.yml b/.github/workflows/update-banner.yml new file mode 100644 index 0000000..1b731d8 --- /dev/null +++ b/.github/workflows/update-banner.yml @@ -0,0 +1,21 @@ +name: Update List Count Banner + +on: + pull_request: + types: [opened, synchronize, reopened] + branches: + - master + push: + branches: + - master + +jobs: + update-banner: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Count list items and update README + run: python3 update_banner.py diff --git a/README.md b/README.md index faa1512..779b466 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ This repo was inspired by [Ali Spittel's](https://twitter.com/ASpittel) tweet Hopefully this repo can serve as a source of inspiration for your portfolio! +## Current List Count: X + --- **Jump to:** [A](#a) | [B](#b) | [C](#c) | [D](#d) | [E](#e) | [F](#f) | [G](#g) | [H](#h) | [I](#i) | [J](#j) | [K](#k) | [L](#l) | [M](#m) | [N](#n) | [O](#o) | [P](#p) | [Q](#q) | [R](#r) | [S](#s) | [T](#t) | [U](#u) | [V](#v) | [W](#w) | [Y](#y) | [Z](#z) diff --git a/src/update_banner.py b/src/update_banner.py new file mode 100644 index 0000000..93736f5 --- /dev/null +++ b/src/update_banner.py @@ -0,0 +1,18 @@ +import re + +# Load the README file +with open('README.md', 'r') as file: + readme_contents = file.read() + +# Count the list items +list_count = len(re.findall(r'^\s*[-*]\s', readme_contents, re.MULTILINE)) + +# Define the new banner message +new_banner = f'## Current List Count: {list_count}' + +# Replace old banner with new banner in README +new_readme_contents = re.sub(r'## Current List Count: \d+', new_banner, readme_contents) + +# Save the changes back to README.md +with open('README.md', 'w') as file: + file.write(new_readme_contents) From a4256b53ba00898d2e4dccc54ed52a54496338c1 Mon Sep 17 00:00:00 2001 From: Chuck Smith Date: Mon, 15 Jul 2024 07:24:50 -0400 Subject: [PATCH 2/3] Update checkout version --- .github/workflows/update-banner.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-banner.yml b/.github/workflows/update-banner.yml index 1b731d8..b03ff26 100644 --- a/.github/workflows/update-banner.yml +++ b/.github/workflows/update-banner.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Count list items and update README run: python3 update_banner.py From fc520641613eeed6dcf9b6aeb2e7a98a8a65210c Mon Sep 17 00:00:00 2001 From: Chuck Smith Date: Mon, 15 Jul 2024 07:25:43 -0400 Subject: [PATCH 3/3] Wrong script location --- .github/workflows/update-banner.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-banner.yml b/.github/workflows/update-banner.yml index b03ff26..9ba584c 100644 --- a/.github/workflows/update-banner.yml +++ b/.github/workflows/update-banner.yml @@ -18,4 +18,4 @@ jobs: uses: actions/checkout@v4 - name: Count list items and update README - run: python3 update_banner.py + run: python3 src/update_banner.py