Skip to content

Commit 95c4614

Browse files
ci: clean up documentation previews (#130)
1 parent 2d843e1 commit 95c4614

File tree

3 files changed

+129
-13
lines changed

3 files changed

+129
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: 'Get Version and Branch and Date'
2+
description: 'Gets Monty version and formats branch name'
3+
inputs:
4+
user_login:
5+
description: 'The GitHub user login'
6+
required: true
7+
outputs:
8+
monty_version:
9+
description: 'The Monty version'
10+
value: ${{ steps.set_vars.outputs.monty_version }}
11+
branch_name:
12+
description: 'The formatted branch name'
13+
value: ${{ steps.set_vars.outputs.branch_name }}
14+
monty_date:
15+
description: 'The current UTC date'
16+
value: ${{ steps.set_vars.outputs.monty_date }}
17+
runs:
18+
using: 'composite'
19+
steps:
20+
- name: Set vars
21+
id: set_vars
22+
shell: bash
23+
working-directory: tbp.monty
24+
run: |
25+
export PATH="$HOME/miniconda/bin:$PATH"
26+
source activate tbp.monty
27+
echo "monty_version=$(python -m tools.print_version.cli minor)" >> $GITHUB_OUTPUT
28+
echo "branch_name=${{ inputs.user_login }}-$(echo ${GITHUB_HEAD_REF} | tr -c '[:alnum:]' '-' | sed 's/-*$//')" >> $GITHUB_OUTPUT
29+
echo "monty_date=$(date -u +'%Y-%m-%d %H:%M UTC')" >> $GITHUB_OUTPUT
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Cleanup Docs Preview
2+
3+
on:
4+
pull_request_target:
5+
types: [closed]
6+
branches:
7+
- main
8+
paths:
9+
- 'docs/**'
10+
- 'tools/github_readme_sync/**'
11+
- '.github/workflows/cleanup_docs_preview.yml'
12+
13+
jobs:
14+
cleanup_docs_preview:
15+
name: cleanup-docs-preview
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout tbp.monty
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
lfs: true
23+
path: tbp.monty
24+
25+
- name: Generate cache key
26+
id: generate_cache_key
27+
run: |
28+
mkdir -p ~/tbp
29+
ln -s $GITHUB_WORKSPACE/tbp.monty ~/tbp/tbp.monty
30+
shasum -a 256 ~/tbp/tbp.monty/environment_arm64.yml | awk '{print $1}' > ~/tbp/environment_arm64.sha
31+
shasum -a 256 ~/tbp/tbp.monty/environment.yml | awk '{print $1}' > ~/tbp/environment.sha
32+
shasum -a 256 ~/tbp/tbp.monty/pyproject.toml | awk '{print $1}' > ~/tbp/pyproject.toml.sha
33+
echo "monty-${RUNNER_OS}-$(cat ~/tbp/environment_arm64.sha)-$(cat ~/tbp/environment.sha)-$(cat ~/tbp/pyproject.toml.sha)" > ~/tbp/conda_env_cache_key.txt
34+
echo "conda_env_cache_key_sha=$(cat ~/tbp/conda_env_cache_key.txt | shasum -a 256 | awk '{print $1}')" >> $GITHUB_OUTPUT
35+
36+
- name: Set up Python 3.8
37+
uses: actions/setup-python@v5
38+
with:
39+
python-version: "3.8"
40+
41+
- name: Restore cache
42+
id: restore_cache
43+
uses: actions/cache/restore@v4
44+
with:
45+
path: |
46+
~/miniconda
47+
key: ${{ steps.generate_cache_key.outputs.conda_env_cache_key_sha }}
48+
49+
- name: Install miniconda
50+
if: steps.restore_cache.outputs.cache-hit != 'true'
51+
run: |
52+
if [ ! -d ~/miniconda ]
53+
then
54+
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
55+
bash ~/miniconda.sh -b -p ~/miniconda
56+
rm ~/miniconda.sh
57+
fi
58+
59+
- name: Create conda environment
60+
if: steps.restore_cache.outputs.cache-hit != 'true'
61+
working-directory: tbp.monty
62+
run: |
63+
export PATH="$HOME/miniconda/bin:$PATH"
64+
(conda env list | grep tbp.monty) && conda remove --name tbp.monty --all --yes || true
65+
conda env create
66+
source activate tbp.monty
67+
pip install -e .[dev,github_readme_sync_tool,print_version_tool]
68+
pip list
69+
conda list
70+
71+
- name: Save cache
72+
if: steps.restore_cache.outputs.cache-hit != 'true'
73+
uses: actions/cache/save@v4
74+
with:
75+
path: |
76+
~/miniconda
77+
key: ${{ steps.restore_cache.outputs.cache-primary-key }}
78+
79+
- name: Get version and branch
80+
id: preview_info
81+
uses: ./tbp.monty/.github/actions/get_preview_info
82+
with:
83+
user_login: ${{ github.event.pull_request.user.login }}
84+
85+
- name: Delete docs preview
86+
working-directory: tbp.monty
87+
run: |
88+
export PATH="$HOME/miniconda/bin:$PATH"
89+
source activate tbp.monty
90+
export README_API_KEY=${{ secrets.README_API_KEY }}
91+
python -m tools.github_readme_sync.cli delete "${{ steps.preview_info.outputs.monty_version }}-${{ steps.preview_info.outputs.branch_name }}"

.github/workflows/docs_preview.yml

+9-13
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,20 @@ jobs:
6868
source activate tbp.monty
6969
pip install -e .[dev,github_readme_sync_tool,print_version_tool]
7070
- name: Get version and branch
71-
working-directory: tbp.monty
72-
run: |
73-
export PATH="$HOME/miniconda/bin:$PATH"
74-
source activate tbp.monty
75-
echo "MONTY_VERSION=$(python -m tools.print_version.cli minor)" >> $GITHUB_ENV
76-
# Make branch name safe for semver by replacing invalid chars with dash
77-
# Remove trailing dash if present
78-
echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr -c '[:alnum:]' '-' | sed 's/-*$//')" >> $GITHUB_ENV
79-
# Get current date in ISO format
80-
echo "MONTY_DATE=$(date -u +'%Y-%m-%d %H:%M UTC')" >> $GITHUB_ENV
71+
id: preview_info
72+
uses: ./tbp.monty/.github/actions/get_preview_info
73+
with:
74+
user_login: ${{ github.event.pull_request.user.login }}
75+
8176
- name: Deploy docs
8277
working-directory: tbp.monty
8378
run: |
8479
export PATH="$HOME/miniconda/bin:$PATH"
8580
source activate tbp.monty
8681
export README_API_KEY=${{ secrets.README_API_KEY }}
8782
export IMAGE_PATH=${{ vars.IMAGE_PATH }}
88-
python -m tools.github_readme_sync.cli upload docs "${MONTY_VERSION}-${BRANCH_NAME}"
83+
python -m tools.github_readme_sync.cli upload docs "${{ steps.preview_info.outputs.monty_version }}-${{ steps.preview_info.outputs.branch_name }}"
84+
8985
- name: Update PR comment on success
9086
if: success()
9187
uses: ./tbp.monty/.github/actions/pin_comment
@@ -98,9 +94,9 @@ jobs:
9894
📚 **Documentation Preview**
9995
10096
✅ A preview of the documentation changes in this PR is available for maintainers at:
101-
${{ vars.DOCS_URL_PREFIX }}v${{ env.MONTY_VERSION }}-${{ env.BRANCH_NAME }}
97+
${{ vars.DOCS_URL_PREFIX }}v${{ steps.preview_info.outputs.monty_version }}-${{ steps.preview_info.outputs.branch_name }}
10298
103-
Last updated: ${{ env.MONTY_DATE }}
99+
Last updated: ${{ steps.preview_info.outputs.monty_date }}
104100
- name: Update PR comment on failure
105101
if: failure()
106102
uses: ./tbp.monty/.github/actions/pin_comment

0 commit comments

Comments
 (0)