Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tools: Clean up documentation previews #130

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
728643e
extract branch name creation to action
codeallthethingz Jan 10, 2025
4750bd7
remove target
codeallthethingz Jan 10, 2025
5228a19
simple change
codeallthethingz Jan 10, 2025
6394ade
move to main 2
codeallthethingz Jan 10, 2025
9459a46
action
codeallthethingz Jan 10, 2025
24add09
action
codeallthethingz Jan 10, 2025
1cf02c3
action
codeallthethingz Jan 10, 2025
c0edf5d
action
codeallthethingz Jan 10, 2025
25b43b8
action
codeallthethingz Jan 10, 2025
1bf882e
action
codeallthethingz Jan 10, 2025
db4e1e3
action
codeallthethingz Jan 10, 2025
01b6f00
action
codeallthethingz Jan 10, 2025
8cad38c
action
codeallthethingz Jan 10, 2025
41d404b
action
codeallthethingz Jan 10, 2025
3f1cf6c
action
codeallthethingz Jan 10, 2025
e242384
action
codeallthethingz Jan 10, 2025
d442af5
Merge pull request #1 from codeallthethingz/delete-preview
codeallthethingz Jan 11, 2025
e72b6b5
cleanup preview
codeallthethingz Jan 11, 2025
d0ce77f
revert readme change
codeallthethingz Jan 11, 2025
1ff6c4b
consolidated naming
codeallthethingz Jan 11, 2025
3951f74
cleanup, style, use cache
codeallthethingz Jan 14, 2025
659966b
action
codeallthethingz Jan 14, 2025
5b4c375
action
codeallthethingz Jan 14, 2025
e7b126f
action
codeallthethingz Jan 14, 2025
4a67d45
action
codeallthethingz Jan 14, 2025
bcee7d7
action
codeallthethingz Jan 14, 2025
04c35ab
action
codeallthethingz Jan 14, 2025
7eaf8f7
action
codeallthethingz Jan 14, 2025
274b0b2
action
codeallthethingz Jan 14, 2025
7fb3cbe
action
codeallthethingz Jan 14, 2025
a0fd176
action
codeallthethingz Jan 14, 2025
d369a74
action
codeallthethingz Jan 14, 2025
ecbf120
action
codeallthethingz Jan 14, 2025
ad680a9
action
codeallthethingz Jan 14, 2025
da7b210
action
codeallthethingz Jan 14, 2025
984d195
action
codeallthethingz Jan 14, 2025
eae3d33
action
codeallthethingz Jan 14, 2025
6b034fc
action
codeallthethingz Jan 14, 2025
2762dbb
revert fork settings
codeallthethingz Jan 14, 2025
0afa72c
Merge pull request #4 from codeallthethingz/delete-preview
codeallthethingz Jan 14, 2025
8ba634b
dangling 2
codeallthethingz Jan 14, 2025
285161e
name resync
codeallthethingz Jan 14, 2025
6eb2ae8
Merge branch 'main' into main2
codeallthethingz Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/actions/get_preview_info/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Get Version and Branch and Date'
description: 'Gets Monty version and formats branch name'
inputs:
user_login:
description: 'The GitHub user login'
required: true
outputs:
monty_version:
description: 'The Monty version'
value: ${{ steps.set_vars.outputs.monty_version }}
branch_name:
description: 'The formatted branch name'
value: ${{ steps.set_vars.outputs.branch_name }}
monty_date:
description: 'The current UTC date'
value: ${{ steps.set_vars.outputs.monty_date }}
runs:
using: 'composite'
steps:
- name: Set vars
id: set_vars
shell: bash
working-directory: tbp.monty
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate tbp.monty
echo "monty_version=$(python -m tools.print_version.cli minor)" >> $GITHUB_OUTPUT
echo "branch_name=${{ inputs.user_login }}-$(echo ${GITHUB_HEAD_REF} | tr -c '[:alnum:]' '-' | sed 's/-*$//')" >> $GITHUB_OUTPUT
echo "monty_date=$(date -u +'%Y-%m-%d %H:%M UTC')" >> $GITHUB_OUTPUT
91 changes: 91 additions & 0 deletions .github/workflows/cleanup_docs_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Cleanup Docs Preview

on:
pull_request_target:
types: [closed]
branches:
- main
paths:
- 'docs/**'
- 'tools/github_readme_sync/**'
- '.github/workflows/cleanup_docs_preview.yml'

jobs:
cleanup_docs_preview:
name: cleanup-docs-preview
runs-on: ubuntu-latest
steps:
- name: Checkout tbp.monty
uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
path: tbp.monty

- name: Generate cache key
id: generate_cache_key
run: |
mkdir -p ~/tbp
ln -s $GITHUB_WORKSPACE/tbp.monty ~/tbp/tbp.monty
shasum -a 256 ~/tbp/tbp.monty/environment_arm64.yml | awk '{print $1}' > ~/tbp/environment_arm64.sha
shasum -a 256 ~/tbp/tbp.monty/environment.yml | awk '{print $1}' > ~/tbp/environment.sha
shasum -a 256 ~/tbp/tbp.monty/pyproject.toml | awk '{print $1}' > ~/tbp/pyproject.toml.sha
echo "monty-${RUNNER_OS}-$(cat ~/tbp/environment_arm64.sha)-$(cat ~/tbp/environment.sha)-$(cat ~/tbp/pyproject.toml.sha)" > ~/tbp/conda_env_cache_key.txt
echo "conda_env_cache_key_sha=$(cat ~/tbp/conda_env_cache_key.txt | shasum -a 256 | awk '{print $1}')" >> $GITHUB_OUTPUT

- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: "3.8"

- name: Restore cache
id: restore_cache
uses: actions/cache/restore@v4
with:
path: |
~/miniconda
key: ${{ steps.generate_cache_key.outputs.conda_env_cache_key_sha }}

- name: Install miniconda
if: steps.restore_cache.outputs.cache-hit != 'true'
run: |
if [ ! -d ~/miniconda ]
then
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p ~/miniconda
rm ~/miniconda.sh
fi

- name: Create conda environment
codeallthethingz marked this conversation as resolved.
Show resolved Hide resolved
if: steps.restore_cache.outputs.cache-hit != 'true'
working-directory: tbp.monty
run: |
export PATH="$HOME/miniconda/bin:$PATH"
(conda env list | grep tbp.monty) && conda remove --name tbp.monty --all --yes || true
conda env create
source activate tbp.monty
pip install -e .[dev,github_readme_sync_tool,print_version_tool]
pip list
conda list

- name: Save cache
if: steps.restore_cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
~/miniconda
key: ${{ steps.restore_cache.outputs.cache-primary-key }}

- name: Get version and branch
id: preview_info
uses: ./tbp.monty/.github/actions/get_preview_info
with:
user_login: ${{ github.event.pull_request.user.login }}

- name: Delete docs preview
working-directory: tbp.monty
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate tbp.monty
export README_API_KEY=${{ secrets.README_API_KEY }}
python -m tools.github_readme_sync.cli delete "${{ steps.preview_info.outputs.monty_version }}-${{ steps.preview_info.outputs.branch_name }}"
22 changes: 9 additions & 13 deletions .github/workflows/docs_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,20 @@ jobs:
source activate tbp.monty
pip install -e .[dev,github_readme_sync_tool,print_version_tool]
- name: Get version and branch
working-directory: tbp.monty
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate tbp.monty
echo "MONTY_VERSION=$(python -m tools.print_version.cli minor)" >> $GITHUB_ENV
# Make branch name safe for semver by replacing invalid chars with dash
# Remove trailing dash if present
echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr -c '[:alnum:]' '-' | sed 's/-*$//')" >> $GITHUB_ENV
# Get current date in ISO format
echo "MONTY_DATE=$(date -u +'%Y-%m-%d %H:%M UTC')" >> $GITHUB_ENV
id: preview_info
uses: ./tbp.monty/.github/actions/get_preview_info
with:
user_login: ${{ github.event.pull_request.user.login }}

- name: Deploy docs
working-directory: tbp.monty
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate tbp.monty
export README_API_KEY=${{ secrets.README_API_KEY }}
export IMAGE_PATH=${{ vars.IMAGE_PATH }}
python -m tools.github_readme_sync.cli upload docs "${MONTY_VERSION}-${BRANCH_NAME}"
python -m tools.github_readme_sync.cli upload docs "${{ steps.preview_info.outputs.monty_version }}-${{ steps.preview_info.outputs.branch_name }}"
codeallthethingz marked this conversation as resolved.
Show resolved Hide resolved

- name: Update PR comment on success
if: success()
uses: ./tbp.monty/.github/actions/pin_comment
Expand All @@ -98,9 +94,9 @@ jobs:
📚 **Documentation Preview**

✅ A preview of the documentation changes in this PR is available for maintainers at:
${{ vars.DOCS_URL_PREFIX }}v${{ env.MONTY_VERSION }}-${{ env.BRANCH_NAME }}
${{ vars.DOCS_URL_PREFIX }}v${{ steps.preview_info.outputs.monty_version }}-${{ steps.preview_info.outputs.branch_name }}

Last updated: ${{ env.MONTY_DATE }}
Last updated: ${{ steps.preview_info.outputs.monty_date }}
- name: Update PR comment on failure
if: failure()
uses: ./tbp.monty/.github/actions/pin_comment
Expand Down
Loading