Skip to content

Commit

Permalink
Testing pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
moe-ad committed Nov 11, 2024
1 parent 4fbe72e commit 66a789b
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 36 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/hello-world.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

# - name: Copy randomtext.txt into some location in repo
# shell: bash
# run:
# run:

# name: hello-world
# on: push
Expand Down Expand Up @@ -144,7 +144,7 @@
# # Format XML with indentation
# rough_string = ET.tostring(sitemap_index, 'utf-8')
# reparsed = minidom.parseString(rough_string)
# pretty_xml = reparsed.toprettyxml(indent=" ")
# pretty_xml = reparsed.toprettyxml(indent=" ")

# # Create the tree and write to XML file
# with open("globalsitemap.xml", "w") as f:
Expand Down Expand Up @@ -216,7 +216,7 @@ jobs:
- name: Checkout repository main branch
uses: actions/checkout@v4
with:
ref: main
ref: main

- name: Copy tools folder to /tmp and run sitemap script
working-directory: /tmp
Expand Down Expand Up @@ -249,4 +249,4 @@ jobs:
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "update sitemaps folder"
message: "update sitemaps folder"
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.3
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This repository contains the core web application files and configuration you'll

To follow along with the step-by-step instructions in the Essentials module, you will need to create a copy of this repository by doing the following:
1. Click **Use this template** above the file list and select **Create a new repository**.
2. Use the **Owner** dropdown menu to select the account you want to own the repository.
2. Use the **Owner** dropdown menu to select the account you want to own the repository.
3. Name your repository `actions-learning-pathway` and add a simple description to make it easier to identify later.
4. Set the default visibility for the repo to public, as private repositories use Actions minutes, while public repositories can use GitHub-hosted runners for free.

Expand Down
6 changes: 3 additions & 3 deletions SUPPORT.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Support
# Support

This repo contains supplemental content for the [GitHub Actions learning pathway](https://resources.github.com/learn/pathways).
This repo contains supplemental content for the [GitHub Actions learning pathway](https://resources.github.com/learn/pathways).

**actions-learning-pathway** is not an open source project, but rather supplemental demo content maintained by GitHub staff. We encourage users to direct questions to the [Community of Discussions](https://github.com/orgs/community/discussions/) or reference [GitHub Docs](https://docs.github.com/en).
**actions-learning-pathway** is not an open source project, but rather supplemental demo content maintained by GitHub staff. We encourage users to direct questions to the [Community of Discussions](https://github.com/orgs/community/discussions/) or reference [GitHub Docs](https://docs.github.com/en).

## GitHub Support Policy

Expand Down
22 changes: 11 additions & 11 deletions demo-files/build-test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ name: build-test-deploy

on: push

jobs:
jobs:
build:
runs-on: ubuntu-latest

steps:
steps:
- name: checkout repo
uses: actions/checkout@v3
- name: use node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
- run: npm install
- run: npm run build
- run: npm run build

test:
test:
needs: build

runs-on: ubuntu-latest

steps:
steps:
- name: checkout repo
uses: actions/checkout@v3
- name: use node.js
Expand All @@ -36,15 +36,15 @@ jobs:

permissions:
contents: write
pages: write
id-token: write
pages: write
id-token: write

environment:
name: production
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest

steps:
- name: checkout repo
uses: actions/checkout@v3
Expand All @@ -59,10 +59,10 @@ jobs:
with:
static_site_generator: next
- run: npm install
- run: npm run build
- run: npm run build
- name: upload artifacts
uses: actions/upload-pages-artifact@v1
with:
with:
path: './out'
- name: deploy
id: deployment
Expand Down
4 changes: 2 additions & 2 deletions demo-files/hello-world.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: hello-world

on: push

jobs:
jobs:
hello-world-job:

runs-on: ubuntu-latest

steps:
steps:
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "$(cat hello_world.txt)"
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const nextConfig = {
images: {
unoptimized: true,
},

reactStrictMode: true,
}

Expand Down
2 changes: 1 addition & 1 deletion public/next.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/vercel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/create_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is a test script that creates a file which I can then upload as artifact on Github

# with open('../output_files/sample_file.txt', mode='w') as w:
with open('sample_file.txt', mode='w') as w:
w.write('My name is Moe\nI just started as an employee at Ansys')
with open("sample_file.txt", mode="w") as w:
w.write("My name is Moe\nI just started as an employee at Ansys")
23 changes: 13 additions & 10 deletions tools/catsitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from xml.dom import minidom
from links import LINKS


def download_file(url: str, dest_path: Path) -> None:
"""Given the url of a sitemap file, this function downloads the file into destination
path (dest_path)
Expand All @@ -24,15 +25,16 @@ def download_file(url: str, dest_path: Path) -> None:
# Send the request
try:
response = requests.get(url, stream=True, timeout=30)
except requests.exceptions.Timeout as e:
except requests.exceptions.Timeout:
print(f"Timed out while trying to get download the sitemap at this url: {url}")
raise requests.exceptions.Timeout

# Write the file content to the specified location
with open(dest_path, mode='wb') as file:
with open(dest_path, mode="wb") as file:
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)


def extract_urls_and_headers(links_dict: dict) -> tuple:
"""Processes the dictionary of project metadata, confirms existence of a downloadable
sitemap, returns valid lists of project names and sitemap urls in a tuple
Expand All @@ -51,7 +53,7 @@ def extract_urls_and_headers(links_dict: dict) -> tuple:
valid_project_names = []
valid_urls = []
for project_name, url in links_dict.items():
if url == None:
if url is None:
continue
updated_url = url.split("docs.pyansys.com")[0] + "docs.pyansys.com/sitemap.xml"
if requests.get(url).status_code == 404:
Expand All @@ -75,8 +77,9 @@ def generate_sitemap_index(project_names: list, dest_path: Path) -> None:
"""

# Create the root element with namespace
sitemap_index = ET.Element("sitemapindex", xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")

sitemap_index = ET.Element(
"sitemapindex", xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
)

# Create sitemap elements for each URL
for project in project_names:
Expand All @@ -88,9 +91,9 @@ def generate_sitemap_index(project_names: list, dest_path: Path) -> None:
loc.text = modified_url

# Format XML with indentation
rough_string = ET.tostring(sitemap_index, 'utf-8')
rough_string = ET.tostring(sitemap_index, "utf-8")
reparsed = minidom.parseString(rough_string)
pretty_xml = reparsed.toprettyxml(indent=" ")
pretty_xml = reparsed.toprettyxml(indent=" ")

# Create the tree and write to XML file
with open(dest_path, "w") as f:
Expand All @@ -100,7 +103,7 @@ def generate_sitemap_index(project_names: list, dest_path: Path) -> None:
# Run the script
if __name__ == "__main__":
# Create path
folder_path = Path('.') / 'sitemaps'
folder_path = Path(".") / "sitemaps"
folder_path.mkdir()

# Get actual valid URLS and corresponding project names
Expand All @@ -111,5 +114,5 @@ def generate_sitemap_index(project_names: list, dest_path: Path) -> None:
generate_sitemap_index(project_names, file_path)

for index, url in enumerate(project_urls):
file_path = folder_path / (project_names[index] + '_sitemap.xml')
download_file(url, file_path)
file_path = folder_path / (project_names[index] + "_sitemap.xml")
download_file(url, file_path)

0 comments on commit 66a789b

Please sign in to comment.