Skip to content

Commit

Permalink
update gh actions to allow deploying from fork repo (#913)
Browse files Browse the repository at this point in the history
* update gh actions to allow deploying from fork repo

* format
  • Loading branch information
oscarlevin authored Feb 4, 2025
1 parent f4ed272 commit b4e4a80
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 18 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/deploy-nightly-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: deploy-nightly

on:
# schedule:
# # * is a special character in YAML so you have to quote this string.
# - cron: "00 6 * * *"
# Allows you to run this workflow manually from the Actions tab.
workflow_dispatch:
inputs:
core-repo:
description: "The repository to use for the core commit."
required: false
type: choice
default: "PreTeXtbook/pretext"
options:
- "PreTeXtbook/pretext"
- "oscarlevin/pretext"

jobs:
tests:
name: Run tests
uses: ./.github/workflows/tests.yml

deploy:
needs: tests
name: Deploy to pypi
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it.
- uses: actions/checkout@v4

# Sets up python3
- uses: actions/setup-python@v4
with:
python-version: 3.8

# Setup poetry
- name: Install poetry 1.8.4
run: |
python -m pip install --upgrade pip
python -m pip install poetry==1.8.4
- name: Install build dependencies
run: sudo apt-get -y install libcairo2-dev pkg-config python3-dev

- name: Install dependencies
shell: bash
run: python -m poetry install --all-extras

- name: Run prep-nightly script and publish if ready
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
echo "Updating core commit and version; building"
output=$(poetry run python scripts/prep_nightly.py ${{ inputs.core-repo }})
echo "Finished steps to prep nightly deployment"
if [[ $output == *"Ready to deploy"* ]]; then
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build
echo "Published to pypi"
fi
7 changes: 3 additions & 4 deletions .github/workflows/deploy-nightly.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: deploy-nightly


on:
schedule:
# * is a special character in YAML so you have to quote this string.
- cron: "00 6 * * *"
#schedule:
# # * is a special character in YAML so you have to quote this string.
# - cron: "00 6 * * *"
# Allows you to run this workflow manually from the Actions tab.
workflow_dispatch:

Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/deploy-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ on:
options:
- "main"
- "legacy-support"
core-repo:
description: "The repository to use for the core commit."
required: false
type: choice
default: "PreTeXtbook/pretext"
options:
- "PreTeXtbook/pretext"
- "oscarlevin/pretext"


jobs:
tests:
Expand Down Expand Up @@ -62,7 +71,7 @@ jobs:
run: poetry version ${{ inputs.level }}

- name: Build package
run: poetry run python scripts/build_package.py
run: poetry run python scripts/build_package.py ${{ inputs.core-repo }}

- name: Discover current version
run: |
Expand Down
7 changes: 4 additions & 3 deletions scripts/build_package.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import subprocess
import sys
import fetch_core


def main() -> None:
import pretext

arguments = sys.argv[1:]
print(f"Building package for version {pretext.VERSION}.")

# ensure up-to-date "static" resources
fetch_core.main()
fetch_core.main(arguments)
# bundle_resources.main() not needed; now part of fetch_core.main()

input()
# Build package
subprocess.run(["poetry", "build"], shell=True)
print("Completed poetry build of pretext")
Expand Down
18 changes: 11 additions & 7 deletions scripts/fetch_core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
from pathlib import Path
import subprocess
import requests
Expand All @@ -18,14 +19,17 @@ def update_css(ptx_dir) -> None:
print(f"current working directory: {os.getcwd()}")


def main() -> None:
def main(args=None) -> None:
print(args)
if args:
print(f"Arguments: {args}")
repo_name = args[0]
else:
repo_name = "PreTeXtBook/pretext"
# grab copy of necessary PreTeXtBook/pretext files from specified commit

print(f"Requesting core PreTeXtBook/pretext commit {CORE_COMMIT} from GitHub.")
print(f"Requesting core {repo_name} commit {CORE_COMMIT} from GitHub.")
core_zip_path = Path("pretext").resolve() / "resources" / "core.zip"
r = requests.get(
f"https://github.com/PreTeXtBook/pretext/archive/{CORE_COMMIT}.zip"
)
r = requests.get(f"https://github.com/{repo_name}/archive/{CORE_COMMIT}.zip")
# remove current core/pretext.py file in case it is a link
utils.remove_path(Path("pretext").resolve() / "core" / "pretext.py")

Expand Down Expand Up @@ -95,4 +99,4 @@ def main() -> None:


if __name__ == "__main__":
main()
main(sys.argv[1:])
7 changes: 4 additions & 3 deletions scripts/prep_nightly.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
import sys
from urllib.request import urlopen
import json
from datetime import datetime
Expand Down Expand Up @@ -31,7 +32,7 @@ def should_release(coredate: datetime, clidate: datetime) -> bool:
return False


def main() -> None:
def main(args) -> None:
last_core_commit = commit_data("pretext")
last_cli_commit = commit_data("pretext-cli")

Expand Down Expand Up @@ -69,9 +70,9 @@ def main() -> None:
# Need to wait to import build_package until now so it gets the updated version CORE_COMMIT and version.
import build_package

build_package.main()
build_package.main(args)
print("Ready to deploy")


if __name__ == "__main__":
main()
main(sys.argv[1:])

0 comments on commit b4e4a80

Please sign in to comment.