Skip to content

Commit

Permalink
Run Python script in CI without custom action
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Nov 13, 2022
1 parent 04f0083 commit d26b373
Showing 1 changed file with 56 additions and 57 deletions.
113 changes: 56 additions & 57 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,35 @@ jobs:

- name: Determine folder name
id: folder
uses: jannekem/run-python-script-action@v1
with:
script: |
import os
import re
github_ref = os.environ.get('GITHUB_REF')
print("github_ref:", github_ref)
github_event_name = os.environ.get("GITHUB_EVENT_NAME")
print("github_event_name:", github_event_name)
workflow_dispatch_tag = os.environ.get("WORKFLOW_DISPATCH_TAG")
print("workflow_dispatch_tag:", workflow_dispatch_tag)
if github_event_name == "push" and github_ref.startswith("refs/heads/release/"):
name = "v" + github_ref.split("refs/heads/release/")[1]
print("name 1:", name)
elif github_event_name == "push" and github_ref.startswith("refs/tags/"):
name = github_ref.split("refs/tags/")[1]
print("name 2:", name)
elif github_event_name == "workflow_dispatch":
name = workflow_dispatch_tag
print("name 3:", name)
else:
print("name 4:")
raise RuntimeError
set_output("name", name)
shell: python
run: |
import os
import re
github_ref = os.environ.get('GITHUB_REF')
print("github_ref:", github_ref)
github_event_name = os.environ.get("GITHUB_EVENT_NAME")
print("github_event_name:", github_event_name)
workflow_dispatch_tag = os.environ.get("WORKFLOW_DISPATCH_TAG")
print("workflow_dispatch_tag:", workflow_dispatch_tag)
if github_event_name == "push" and github_ref.startswith("refs/heads/release/"):
name = "v" + github_ref.split("refs/heads/release/")[1]
print("name 1:", name)
elif github_event_name == "push" and github_ref.startswith("refs/tags/"):
name = github_ref.split("refs/tags/")[1]
print("name 2:", name)
elif github_event_name == "workflow_dispatch":
name = workflow_dispatch_tag
print("name 3:", name)
else:
print("name 4:")
raise RuntimeError
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"name={name}")
- name: Clear old version folder
run: |
Expand All @@ -118,34 +118,33 @@ jobs:
run: rm docs.tar.gz

- name: Update versions.json file
uses: jannekem/run-python-script-action@v1
with:
script: |
import json
import pathlib
import os
# Determine the version folders
cwd = pathlib.Path.cwd()
versions = sorted((item.name for item in cwd.iterdir() if item.is_dir() and not item.name.startswith(".")), reverse=True)
print(versions)
list_of_dicts = []
latest = None
for version in versions:
title = version
aliases = []
if "x" in version:
title += " (pre-release)"
elif latest is None:
latest = version
aliases = ["latest"]
os.system(f"ln -s {version} latest")
list_of_dicts.append({"version": version, "title": title, "aliases": aliases})
print(list_of_dicts)
with (cwd / "versions.json").open("w") as f:
json.dump(list_of_dicts, f, indent=4)
shell: python
run: |
import json
import pathlib
import os
# Determine the version folders
cwd = pathlib.Path.cwd()
versions = sorted((item.name for item in cwd.iterdir() if item.is_dir() and not item.name.startswith(".")), reverse=True)
print(versions)
list_of_dicts = []
latest = None
for version in versions:
title = version
aliases = []
if "x" in version:
title += " (pre-release)"
elif latest is None:
latest = version
aliases = ["latest"]
os.system(f"ln -s {version} latest")
list_of_dicts.append({"version": version, "title": title, "aliases": aliases})
print(list_of_dicts)
with (cwd / "versions.json").open("w") as f:
json.dump(list_of_dicts, f, indent=4)
- name: Publish to GitHub pages
uses: peaceiris/actions-gh-pages@v3
Expand Down

0 comments on commit d26b373

Please sign in to comment.