|
| 1 | +name: Docs Preview |
| 2 | + |
| 3 | +concurrency: |
| 4 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} |
| 5 | + cancel-in-progress: true |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request_target: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + paths: |
| 12 | + - 'docs/**' |
| 13 | + - 'tools/github_readme_sync/**' |
| 14 | + - '.github/workflows/docs_preview.yml' |
| 15 | + |
| 16 | +permissions: |
| 17 | + pull-requests: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + deploy_docs_preview: |
| 21 | + name: deploy-docs-preview |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Checkout tbp.monty |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + lfs: true |
| 29 | + path: tbp.monty |
| 30 | + |
| 31 | + - name: Create initial PR comment |
| 32 | + uses: ./tbp.monty/.github/actions/pin_comment |
| 33 | + with: |
| 34 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + issue_number: ${{ github.event.pull_request.number }} |
| 36 | + comment_id: docs-preview |
| 37 | + working_directory: tbp.monty |
| 38 | + message: | |
| 39 | + 📚 **Documentation Preview** |
| 40 | +
|
| 41 | + Building documentation preview... ⏳ |
| 42 | +
|
| 43 | + Check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for progress. |
| 44 | + - name: Set up ~/tbp |
| 45 | + run: | |
| 46 | + mkdir -p ~/tbp |
| 47 | + ln -s $GITHUB_WORKSPACE/tbp.monty ~/tbp/tbp.monty |
| 48 | + - name: Set up Python 3.8 |
| 49 | + uses: actions/setup-python@v5 |
| 50 | + with: |
| 51 | + python-version: "3.8" |
| 52 | + - name: Install miniconda |
| 53 | + run: | |
| 54 | + if [ ! -d ~/miniconda ] |
| 55 | + then |
| 56 | + wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh |
| 57 | + bash ~/miniconda.sh -b -p ~/miniconda |
| 58 | + rm ~/miniconda.sh |
| 59 | + fi |
| 60 | + export PATH="$HOME/miniconda/bin:$PATH" |
| 61 | + conda --version |
| 62 | + - name: Create conda environment |
| 63 | + working-directory: tbp.monty |
| 64 | + run: | |
| 65 | + export PATH="$HOME/miniconda/bin:$PATH" |
| 66 | + (conda env list | grep tbp.monty) && conda remove --name tbp.monty --all --yes || true |
| 67 | + conda env create |
| 68 | + source activate tbp.monty |
| 69 | + pip install -e .[dev,github_readme_sync_tool,print_version_tool] |
| 70 | + - 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 |
| 81 | + - name: Deploy docs |
| 82 | + working-directory: tbp.monty |
| 83 | + run: | |
| 84 | + export PATH="$HOME/miniconda/bin:$PATH" |
| 85 | + source activate tbp.monty |
| 86 | + export README_API_KEY=${{ secrets.README_API_KEY }} |
| 87 | + export IMAGE_PATH=${{ vars.IMAGE_PATH }} |
| 88 | + python -m tools.github_readme_sync.cli upload docs "${MONTY_VERSION}-${BRANCH_NAME}" |
| 89 | + - name: Update PR comment on success |
| 90 | + if: success() |
| 91 | + uses: ./tbp.monty/.github/actions/pin_comment |
| 92 | + with: |
| 93 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + issue_number: ${{ github.event.pull_request.number }} |
| 95 | + comment_id: docs-preview |
| 96 | + working_directory: tbp.monty |
| 97 | + message: | |
| 98 | + 📚 **Documentation Preview** |
| 99 | +
|
| 100 | + ✅ 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 }} |
| 102 | +
|
| 103 | + Last updated: ${{ env.MONTY_DATE }} |
| 104 | + - name: Update PR comment on failure |
| 105 | + if: failure() |
| 106 | + uses: ./tbp.monty/.github/actions/pin_comment |
| 107 | + with: |
| 108 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 109 | + issue_number: ${{ github.event.pull_request.number }} |
| 110 | + comment_id: docs-preview |
| 111 | + working_directory: tbp.monty |
| 112 | + message: | |
| 113 | + 📚 **Documentation Preview** |
| 114 | +
|
| 115 | + ❌ Failed to build documentation preview. |
| 116 | +
|
| 117 | + Check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details. |
0 commit comments