MacVim Documentation Build #511
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: MacVim Documentation Build | |
on: | |
push: | |
schedule: | |
- cron: "50 3 * * *" # 3:50 am UTC every day. Just a random time intentionally picked to be not during busy hours. | |
workflow_dispatch: | |
# Allow one concurrent deployment | |
concurrency: | |
group: "pages" | |
cancel-in-progress: true | |
env: | |
MACVIM_REPO: 'macvim-dev/macvim' | |
MACVIM_DIR: ${{ format('{0}/macvim', github.workspace) }} | |
jobs: | |
# Build the page and upload it as an artifact | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
docs_commit: ${{ steps.setup-env-vars.outputs.docs_commit }} | |
macvim_commit: ${{ steps.setup-env-vars.outputs.macvim_commit }} | |
macvim_commit_cache_hit: ${{ steps.restore-cache-macvim-commit.outputs.cache-hit }} | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Checkout MacVim | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ env.MACVIM_REPO }} | |
path: 'macvim' | |
- name: Set up commit / version environmental vars | |
id: setup-env-vars | |
run: | | |
printf 'docs_commit=%s\n' $(git rev-parse HEAD) >> $GITHUB_OUTPUT | |
cd "$MACVIM_DIR" | |
printf 'MACVIM_COMMIT=%s\n' $(git rev-parse HEAD) >> $GITHUB_ENV | |
printf 'MACVIM_VERSION=%s\n' $(${GITHUB_WORKSPACE}/scripts/extract_macvim_version ./src) >> $GITHUB_ENV | |
printf 'VIM_VERSION=%s\n' $(${GITHUB_WORKSPACE}/scripts/extract_vim_version ./src) >> $GITHUB_ENV | |
printf 'macvim_commit=%s\n' $(git rev-parse HEAD) >> $GITHUB_OUTPUT | |
# We cache the last built commit info, so that we could choose not to | |
# deploy if we have already built this version already. This is useful to | |
# prevent the daily workflow stomping previously generated versions. | |
# Useful for preserving browser caching. | |
# We do make an exception for manual dispatch as that usually means we | |
# want to re-built the page. | |
- name: Check cached version info to see if current commit has been built before | |
id: restore-cache-macvim-commit | |
if: ${{ github.event_name != 'workflow_dispatch' }} | |
uses: actions/cache/restore@v4 | |
with: | |
path: ${{ github.workspace }}/macvim-built-commit.txt | |
key: macvim-built-commit-${{ steps.setup-env-vars.outputs.docs_commit}}-${{ steps.setup-env-vars.outputs.macvim_commit }} | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
cache: 'pip' | |
cache-dependency-path: 'vimhelp/requirements.txt' | |
- name: Set up vimhelp | |
run: | | |
pip install -r vimhelp/requirements.txt | |
- name: Build the documentation | |
run: | | |
echo "MacVim commit: ${MACVIM_COMMIT}" | |
echo "MacVim release: ${MACVIM_VERSION}" | |
echo "Vim version: ${VIM_VERSION}" | |
version_string="r${MACVIM_VERSION} (Vim ${VIM_VERSION})" | |
echo "Version string: $version_string" | |
cd vimhelp | |
python3 scripts/h2h.py -i "$MACVIM_DIR/runtime/doc" -o ../build --project macvim --web-version --output-tags-json --version "$version_string" --commit "$MACVIM_COMMIT" | |
- name: Generate sitemap | |
run: | | |
cd build | |
${GITHUB_WORKSPACE}/scripts/generate_sitemap > sitemap.txt | |
- name: Upload page artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: build | |
# Deploy the artifact to the page | |
deploy: | |
needs: build | |
# Only allow deployment if on main branch (environmental protection would | |
# block it otherwise anyway), and if we haven't already built this version | |
# already. | |
if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'workflow_dispatch' || needs.build.outputs.macvim_commit_cache_hit != 'true') }} | |
permissions: | |
pages: write # to deploy to Pages | |
id-token: write # to verify the deployment originates from an appropriate source | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
# Deployment is good. Finish caching the commit info so we won't run | |
# again until either this repo or MacVim got updated. | |
- name: Generate built commit version info marker | |
if: ${{ needs.build.outputs.macvim_commit_cache_hit != 'true' && github.event_name != 'workflow_dispatch' }} | |
run: | | |
# This file is just a marker. Save the current date in case we are curious later when the last version was built. | |
date > "${GITHUB_WORKSPACE}/macvim-built-commit.txt" | |
- name: Update cache with commit version info | |
id: save-cache-macvim-commit | |
uses: actions/cache/save@v4 | |
if: ${{ needs.build.outputs.macvim_commit_cache_hit != 'true' && github.event_name != 'workflow_dispatch' }} | |
with: | |
path: ${{ github.workspace }}/macvim-built-commit.txt | |
key: macvim-built-commit-${{ needs.build.outputs.docs_commit }}-${{ needs.build.outputs.macvim_commit }} |