Skip to content

Commit

Permalink
Add GitHub actions automation
Browse files Browse the repository at this point in the history
  • Loading branch information
natecohen committed Nov 16, 2024
1 parent 64d2635 commit f4cdb04
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/update-and-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Daily Update

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
update_and_commit:
runs-on: ubuntu-latest

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

# Run the update script
- name: Run update script
run: python script.py

# Check if there are any updates
- name: Check for updates
id: check_updates
run: |
if [ -f updated_categories.txt ]; then
echo "updates_found=true" >> $GITHUB_ENV
UPDATED_CATEGORIES=$(cat updated_categories.txt | tr '\n' ', ' | sed 's/, $//')
echo "updated_categories=${UPDATED_CATEGORIES}" >> $GITHUB_ENV
else
echo "updates_found=false" >> $GITHUB_ENV
# Commit and push changes if updates are found
- name: Commit and push changes
if: env.updates_found == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
COMMIT_MESSAGE="$(date +'%Y-%m-%d') Updated - ${UPDATED_CATEGORIES}"
git commit -m "${COMMIT_MESSAGE}"
git push
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ Some may be split further by service, and include an "All" subfolder with combin

You may find Windows attempt direct IP connections for updates. Those that are a part of [Microsoft Connected Cache for ISPs](https://techcommunity.microsoft.com/t5/windows-it-pro-blog/microsoft-connected-cache-for-isps-microsoft-s-distributed-cdn/ba-p/3891604) are not published.

## Todo

- Automation using GitHub Actions
- Addition of more services

## Related Projects

- https://github.com/blrchen/azure-ip-lookup
15 changes: 11 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ def __init__(self, update_file):
self.original_last_update_data = self.last_update_data.copy()

def save_updates(self):
if self.last_update_data != self.original_last_update_data:
updated_categories = [
key for key in self.last_update_data
if self.last_update_data[key] != self.original_last_update_data.get(key)
]

if updated_categories:
# Write updated categories to a file for the GitHub Action
with open("updated_categories.txt", "w") as f:
f.write("\n".join(updated_categories))

# Save the updated JSON file
with open(self.update_file, "w") as f:
json.dump(self.last_update_data, f, indent=2)

Expand Down Expand Up @@ -76,7 +86,6 @@ def process_azure(self):
region_service_list = {}

for item in data["values"]:

# Skip generic AzureCloud
if item["id"].startswith("AzureCloud"):
continue
Expand Down Expand Up @@ -117,7 +126,6 @@ def process_m365(self):
mem_endpoints = ["Worldwide", "USGOVDoD"]

for endpoint in endpoints:

change_url = f"https://endpoints.office.com/version/{endpoint}?allversions=true&format=rss&clientrequestid={client_request_id}"

try:
Expand Down Expand Up @@ -290,7 +298,6 @@ def process_entra_connect_health(self):
pass

for endpoint, urls in health_fqdns.items():

outdir = Path(__file__).parent / "entra-connect-health" / endpoint
outdir.mkdir(parents=True, exist_ok=True)

Expand Down

0 comments on commit f4cdb04

Please sign in to comment.