diff --git a/.github/actions/get_preview_info/action.yml b/.github/actions/get_preview_info/action.yml new file mode 100644 index 0000000..2b1d487 --- /dev/null +++ b/.github/actions/get_preview_info/action.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/cleanup_docs_preview.yml b/.github/workflows/cleanup_docs_preview.yml new file mode 100644 index 0000000..0aeaa7c --- /dev/null +++ b/.github/workflows/cleanup_docs_preview.yml @@ -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 + 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 }}" \ No newline at end of file diff --git a/.github/workflows/docs_preview.yml b/.github/workflows/docs_preview.yml index 9856a15..7744db1 100644 --- a/.github/workflows/docs_preview.yml +++ b/.github/workflows/docs_preview.yml @@ -68,16 +68,11 @@ 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: | @@ -85,7 +80,8 @@ jobs: 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 }}" + - name: Update PR comment on success if: success() uses: ./tbp.monty/.github/actions/pin_comment @@ -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