Skip to content

Commit 0f5bc9b

Browse files
committed
fix: Update GitHub Actions workflow to use stable versions and improve error handling for IndexNow submission
1 parent c9f9583 commit 0f5bc9b

1 file changed

Lines changed: 37 additions & 28 deletions

File tree

.github/workflows/docs.yml

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
INDEXNOW_KEY: ${{ secrets['INDEXNOW_KEY'] }}
2323
steps:
2424
- name: Checkout
25-
uses: actions/checkout@v6
25+
uses: actions/checkout@v4
2626

2727
- name: Setup .NET
2828
uses: actions/setup-dotnet@v5
@@ -40,6 +40,29 @@ jobs:
4040
run: |
4141
printf "%s" "$INDEXNOW_KEY" > "docs/_site/${INDEXNOW_KEY}.txt"
4242
43+
- name: Fix README images
44+
run: |
45+
mkdir -p docs/_site/docs/images
46+
cp -r docs/images/* docs/_site/docs/images/
47+
48+
- name: Upload artifact
49+
uses: actions/upload-pages-artifact@v5
50+
with:
51+
path: docs/_site
52+
53+
deploy:
54+
environment:
55+
name: github-pages
56+
url: ${{ steps.deployment.outputs.page_url }}
57+
runs-on: ubuntu-latest
58+
needs: build
59+
env:
60+
INDEXNOW_KEY: ${{ secrets['INDEXNOW_KEY'] }}
61+
steps:
62+
- name: Deploy to GitHub Pages
63+
id: deployment
64+
uses: actions/deploy-pages@v4
65+
4366
- name: Submit IndexNow URLs
4467
if: ${{ env.INDEXNOW_KEY != '' }}
4568
run: |
@@ -48,15 +71,18 @@ jobs:
4871
import os
4972
import xml.etree.ElementTree as ET
5073
from urllib import request
74+
from urllib.error import HTTPError
5175
5276
endpoint = "https://api.indexnow.org/indexnow"
5377
key = os.environ["INDEXNOW_KEY"]
5478
key_location = f"https://aalmada.github.io/BookStore/{key}.txt"
55-
sitemap_path = "docs/_site/sitemap.xml"
79+
sitemap_url = "https://aalmada.github.io/BookStore/sitemap.xml"
80+
81+
with request.urlopen(sitemap_url, timeout=30) as resp:
82+
xml_data = resp.read()
5683
5784
ns = {"sm": "http://www.sitemaps.org/schemas/sitemap/0.9"}
58-
tree = ET.parse(sitemap_path)
59-
root = tree.getroot()
85+
root = ET.fromstring(xml_data)
6086
6187
urls = []
6288
for loc in root.findall("sm:url/sm:loc", ns):
@@ -81,28 +107,11 @@ jobs:
81107
method="POST",
82108
)
83109
84-
with request.urlopen(req, timeout=30) as response:
85-
print(f"IndexNow response: {response.status}")
86-
print(response.read().decode("utf-8"))
110+
try:
111+
with request.urlopen(req, timeout=30) as response:
112+
print(f"IndexNow response: {response.status}")
113+
print(response.read().decode("utf-8"))
114+
except HTTPError as e:
115+
print(f"IndexNow error: {e.code} {e.reason}")
116+
raise
87117
PY
88-
89-
- name: Fix README images
90-
run: |
91-
mkdir -p docs/_site/docs/images
92-
cp -r docs/images/* docs/_site/docs/images/
93-
94-
- name: Upload artifact
95-
uses: actions/upload-pages-artifact@v5
96-
with:
97-
path: docs/_site
98-
99-
deploy:
100-
environment:
101-
name: github-pages
102-
url: ${{ steps.deployment.outputs.page_url }}
103-
runs-on: ubuntu-latest
104-
needs: build
105-
steps:
106-
- name: Deploy to GitHub Pages
107-
id: deployment
108-
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)