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

Actions: Deploy preview docs #66

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
256de9a
rename title to match slug
codeallthethingz Nov 21, 2024
0fead22
Merge remote-tracking branch 'upstream/main'
codeallthethingz Nov 21, 2024
52c0aa3
Merge remote-tracking branch 'upstream/main'
codeallthethingz Nov 22, 2024
d94d18d
Merge remote-tracking branch 'upstream/main'
codeallthethingz Nov 22, 2024
d3c39ba
Merge remote-tracking branch 'upstream/main'
codeallthethingz Nov 22, 2024
37ad1d4
Merge remote-tracking branch 'upstream/main'
codeallthethingz Nov 24, 2024
f55b0fc
action
codeallthethingz Nov 24, 2024
9f6db94
action
codeallthethingz Nov 24, 2024
500a318
action
codeallthethingz Nov 24, 2024
f7f90fb
action
codeallthethingz Nov 24, 2024
3658610
action
codeallthethingz Nov 24, 2024
8c7ede2
action
codeallthethingz Nov 24, 2024
b53a36e
action
codeallthethingz Nov 24, 2024
b2a05e9
action
codeallthethingz Nov 24, 2024
dd94c47
remove blank line
codeallthethingz Nov 24, 2024
bff7b03
action
codeallthethingz Nov 24, 2024
b87c637
action
codeallthethingz Nov 24, 2024
a2da615
action
codeallthethingz Nov 24, 2024
f4e2566
check to run on PR preview to run on PRT
codeallthethingz Nov 24, 2024
ce25a41
action
codeallthethingz Nov 24, 2024
a40f252
action
codeallthethingz Nov 24, 2024
f4b5ed7
action
codeallthethingz Nov 24, 2024
5830a84
action
codeallthethingz Nov 24, 2024
193fc80
action
codeallthethingz Nov 24, 2024
9d47904
action
codeallthethingz Nov 24, 2024
249831d
action
codeallthethingz Nov 24, 2024
6962eaf
trailing space
codeallthethingz Nov 24, 2024
96d9cf5
Merge remote-tracking branch 'upstream/main'
codeallthethingz Nov 26, 2024
1b3ade7
Merge remote-tracking branch 'upstream/main'
codeallthethingz Nov 26, 2024
e11ce4b
Merge remote-tracking branch 'upstream/main'
codeallthethingz Nov 27, 2024
062dc4a
Merge remote-tracking branch 'upstream/main'
codeallthethingz Nov 27, 2024
799e598
Merge remote-tracking branch 'upstream/main'
codeallthethingz Nov 27, 2024
36f686e
Merge remote-tracking branch 'upstream/main'
codeallthethingz Nov 29, 2024
a5519a1
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 2, 2024
1b8bd68
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 5, 2024
d8e6940
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 6, 2024
5061b45
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 10, 2024
01b065a
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 12, 2024
cf59a4a
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 13, 2024
75b3401
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 13, 2024
d56f25c
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 13, 2024
c49ceb6
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 14, 2024
799dd58
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 20, 2024
294475e
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 30, 2024
44186cf
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 31, 2024
fed5e17
Merge remote-tracking branch 'upstream/main'
codeallthethingz Dec 31, 2024
b4f5d62
Merge remote-tracking branch 'upstream/main'
codeallthethingz Jan 1, 2025
d4256ed
Merge remote-tracking branch 'upstream/main'
codeallthethingz Jan 7, 2025
92c15c2
Merge branch 'main' into test
codeallthethingz Jan 7, 2025
b33f84e
revert
codeallthethingz Jan 8, 2025
7f2d232
action
codeallthethingz Jan 8, 2025
cbb4bb1
action
codeallthethingz Jan 8, 2025
d051645
action
codeallthethingz Jan 8, 2025
cf5d530
action
codeallthethingz Jan 8, 2025
7517448
action
codeallthethingz Jan 8, 2025
bfb8dc1
action
codeallthethingz Jan 8, 2025
1a2ad82
action
codeallthethingz Jan 8, 2025
bef5d17
action
codeallthethingz Jan 8, 2025
07a95f2
action
codeallthethingz Jan 8, 2025
a2c0562
action
codeallthethingz Jan 8, 2025
a9868a4
action
codeallthethingz Jan 8, 2025
afdff48
action
codeallthethingz Jan 8, 2025
8ea1e78
action
codeallthethingz Jan 8, 2025
7db686a
action
codeallthethingz Jan 8, 2025
1ba3a54
action
codeallthethingz Jan 8, 2025
db1cf5c
action
codeallthethingz Jan 8, 2025
62ca765
action
codeallthethingz Jan 8, 2025
4282f77
action
codeallthethingz Jan 8, 2025
b57e49b
action
codeallthethingz Jan 8, 2025
fe54623
action
codeallthethingz Jan 8, 2025
462dd1f
action
codeallthethingz Jan 8, 2025
2929b52
action
codeallthethingz Jan 8, 2025
a3a6b83
action
codeallthethingz Jan 8, 2025
34a399b
action
codeallthethingz Jan 8, 2025
eae7161
action
codeallthethingz Jan 8, 2025
3140ca4
action
codeallthethingz Jan 8, 2025
d8b9dd6
action
codeallthethingz Jan 8, 2025
4a8d92b
action
codeallthethingz Jan 8, 2025
2e3c145
code review changes
codeallthethingz Jan 8, 2025
da6cccf
action
codeallthethingz Jan 8, 2025
1ef1bbf
action
codeallthethingz Jan 8, 2025
1382d22
todos
codeallthethingz Jan 8, 2025
7991971
wrong yml file
codeallthethingz Jan 8, 2025
affe46e
Merge remote-tracking branch 'upstream/main'
codeallthethingz Jan 9, 2025
96a98d8
Merge branch 'main' into deploy-preview-docs
codeallthethingz Jan 9, 2025
1c67290
kebab, pinned comment page length
codeallthethingz Jan 9, 2025
65f6c05
Merge branch 'main' into deploy-preview-docs
codeallthethingz Jan 9, 2025
e2b98f5
renamed
codeallthethingz Jan 9, 2025
860e9cf
don't run preview when docs.yml changes
codeallthethingz Jan 9, 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
83 changes: 83 additions & 0 deletions .github/actions/pin_comment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: "Pin Comment"
description: "Pins a comment by hiding it with HTML comments and a unique ID"

inputs:
message:
description: "The message to pin"
required: true
token:
description: "GitHub token"
required: true
issue_number:
description: "The issue or PR number"
required: true
comment_id:
description: "Unique identifier for this pinned comment"
required: true
working_directory:
description: "Path to the repository working directory"
required: true

runs:
using: "composite"
steps:
- name: Pin comment
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
env:
GITHUB_TOKEN: ${{ inputs.token }}
MESSAGE: ${{ inputs.message }}
ISSUE_NUMBER: ${{ inputs.issue_number }}
COMMENT_ID: ${{ inputs.comment_id }}
WORKING_DIRECTORY: ${{ inputs.working_directory }}
run: |
# Change to working directory
cd "${WORKING_DIRECTORY}"

# Create comment with hidden marker and ID
COMMENT="<!--pin-comment-marker-${COMMENT_ID}-->
${MESSAGE}"

# Properly escape the comment for JSON
ESCAPED_COMMENT=$(echo "$COMMENT" | jq -R -s '.')

# Find and delete old comment with same ID using GitHub token
echo "Searching for existing pinned comment with ID: ${COMMENT_ID}"
response=$(curl -s -w "%{http_code}" -H "Authorization: token ${GITHUB_TOKEN}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${ISSUE_NUMBER}/comments?per_page=100")
status_code=${response: -3}
comments=${response:0:-3}

if [ "$status_code" != "200" ]; then
echo "Failed to fetch comments. Status code: ${status_code}"
exit 1
fi

old_comment_id=$(echo "$comments" | jq -r ".[] | select(.body | startswith(\"<!--pin-comment-marker-${COMMENT_ID}-->\")) | .id")

# Update old comment if found
if [ ! -z "$old_comment_id" ]; then
echo "Updating existing comment with ID: ${old_comment_id}"
response=$(curl -s -w "%{http_code}" -X PATCH -H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"body\":${ESCAPED_COMMENT}}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/comments/${old_comment_id}")
status_code=${response: -3}

if [ "$status_code" != "200" ]; then
echo "Failed to update comment. Status code: ${status_code}"
exit 1
fi
else
# Create new pinned comment using GitHub API directly
echo "Creating new pinned comment"
response=$(curl -s -w "%{http_code}" -X POST -H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"body\":${ESCAPED_COMMENT}}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${ISSUE_NUMBER}/comments")
status_code=${response: -3}

if [ "$status_code" != "201" ]; then
echo "Failed to create comment. Status code: ${status_code}"
exit 1
fi
fi
117 changes: 117 additions & 0 deletions .github/workflows/docs_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Docs Preview

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

on:
pull_request_target:
branches:
- main
paths:
- 'docs/**'
- 'tools/github_readme_sync/**'
- '.github/workflows/docs_preview.yml'

permissions:
pull-requests: write

jobs:
deploy_docs_preview:
name: deploy-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: Create initial PR comment
uses: ./tbp.monty/.github/actions/pin_comment
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue_number: ${{ github.event.pull_request.number }}
comment_id: docs-preview
working_directory: tbp.monty
message: |
📚 **Documentation Preview**

Building documentation preview... ⏳

Check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for progress.
- name: Set up ~/tbp
run: |
mkdir -p ~/tbp
ln -s $GITHUB_WORKSPACE/tbp.monty ~/tbp/tbp.monty
- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: "3.8"
- name: Install miniconda
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
export PATH="$HOME/miniconda/bin:$PATH"
conda --version
- name: Create conda environment
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]
- 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
- 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}"
- name: Update PR comment on success
if: success()
uses: ./tbp.monty/.github/actions/pin_comment
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue_number: ${{ github.event.pull_request.number }}
comment_id: docs-preview
working_directory: tbp.monty
message: |
📚 **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 }}

Last updated: ${{ env.MONTY_DATE }}
- name: Update PR comment on failure
if: failure()
uses: ./tbp.monty/.github/actions/pin_comment
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue_number: ${{ github.event.pull_request.number }}
comment_id: docs-preview
working_directory: tbp.monty
message: |
📚 **Documentation Preview**

❌ Failed to build documentation preview.

Check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
Loading