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

Add docsite #225

Merged
merged 5 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ indent_size = 2
[*.{rb,js}]
max_line_length = 80

[README.md]
[*.md]
max_line_length = unset
178 changes: 178 additions & 0 deletions .github/workflows/super_diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
types:
- opened
- closed
- reopened
- synchronize
concurrency:
Expand All @@ -15,6 +16,7 @@ concurrency:
jobs:
analyze:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || github.event.action != 'closed' }}
steps:
- uses: actions/checkout@v4
- name: Download actionlint
Expand Down Expand Up @@ -88,3 +90,179 @@ jobs:
- test
steps:
- run: echo "Analysis and tests passed. Ready to merge."

collect-release-info:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Run command
id: command
run: scripts/collect-release-info.rb
outputs:
IS_NEW_RELEASE: ${{ steps.command.outputs.IS_NEW_RELEASE }}
RELEASE_VERSION: ${{ steps.command.outputs.RELEASE_VERSION }}

collect-docsite-release-info:
runs-on: ubuntu-latest
needs:
- collect-release-info
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run command
id: command
run: |
set -x

if [[ "$IS_NEW_RELEASE" == "true" ]]; then
DOCSITE_RELEASE_VERSION="$RELEASE_VERSION"
DOCSITE_DESTINATION_PATH="releases/$RELEASE_VERSION"
HAS_CHANGES_TO_DOCS="true"
else
DOCSITE_RELEASE_VERSION="$COMMIT_ID"
DOCSITE_DESTINATION_PATH="branches/$BRANCH_NAME/$COMMIT_ID"
# Check if there any changes to docs/
if git diff --quiet --merge-base "origin/$GITHUB_BASE_REF" -- docs; then
HAS_CHANGES_TO_DOCS="false"
else
HAS_CHANGES_TO_DOCS="true"
fi
fi

{
echo "DOCSITE_RELEASE_VERSION=$DOCSITE_RELEASE_VERSION"
echo "DOCSITE_DESTINATION_PATH=$DOCSITE_DESTINATION_PATH"
echo "HAS_CHANGES_TO_DOCS=$HAS_CHANGES_TO_DOCS"
} >> "$GITHUB_OUTPUT"
env:
IS_NEW_RELEASE: ${{ needs.collect-release-info.outputs.IS_NEW_RELEASE }}
RELEASE_VERSION: ${{ needs.collect-release-info.outputs.RELEASE_VERSION }}
BRANCH_NAME: ${{ github.head_ref }}
COMMIT_ID: ${{ github.event.pull_request.head.sha }}
outputs:
DOCSITE_RELEASE_VERSION: ${{ steps.command.outputs.DOCSITE_RELEASE_VERSION }}
DOCSITE_DESTINATION_PATH: ${{ steps.command.outputs.DOCSITE_DESTINATION_PATH }}
HAS_CHANGES_TO_DOCS: ${{ steps.command.outputs.HAS_CHANGES_TO_DOCS }}

build-docsite:
runs-on: ubuntu-latest
needs:
- analyze
- collect-release-info
- collect-docsite-release-info
if: ${{ github.event_name == 'pull_request' && ((needs.collect-release-info.outputs.IS_NEW_RELEASE == 'false' && needs.collect-docsite-release-info.outputs.HAS_CHANGES_TO_DOCS == 'true') || (needs.collect-release-info.outputs.IS_NEW_RELEASE == 'true' && github.event.merged)) }}
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
- name: Install Python dependencies
run: poetry install
- name: Build docsite
run: poetry run mkdocs build
- name: Save site/ for later jobs
uses: actions/cache/save@v3
with:
path: site
key: docsite-${{ github.sha }}

publish-docsite:
runs-on: ubuntu-latest
needs:
- collect-release-info
- collect-docsite-release-info
- build-docsite
steps:
- uses: actions/checkout@v4
with:
ref: gh-pages
- name: Restore cache from previous job
uses: actions/cache/restore@v3
with:
path: site
key: docsite-${{ github.sha }}
- name: Update redirect in index (for a release)
if: ${{ needs.collect-release-info.outputs.IS_NEW_RELEASE == 'true' }}
run: |
cat <<-EOT > index.html
<!DOCTYPE html>
<html>
<head>
<title>SuperDiff Documentation</title>
<meta http-equiv="refresh" content="0; url='https://mcmire.github.com/super_diff/releases/${RELEASE_VERSION}'" />
</head>
<body>
<p>
This page has moved to a different URL.
Please click
<a href="https://mcmire.github.com/super_diff/releases/${RELEASE_VERSION}">
this link
</a>
if you are not redirected.
</p>
</body>
</html>
EOT
- name: Copy site/ to ${{ needs.collect-docsite-release-info.outputs.DOCSITE_DESTINATION_PATH }}
run: |
mkdir -p "$(dirname "$DOCSITE_DESTINATION_PATH")"
mv site "$DOCSITE_DESTINATION_PATH"
env:
DOCSITE_DESTINATION_PATH: ${{ needs.collect-docsite-release-info.outputs.DOCSITE_DESTINATION_PATH }}
- name: Publish new version of docsite
run: |
git add -A .
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git commit -m "Publish docs at $DOCSITE_DESTINATION_PATH"
git push
env:
DOCSITE_DESTINATION_PATH: ${{ needs.collect-docsite-release-info.outputs.DOCSITE_DESTINATION_PATH }}
- name: Announce publishing of docsite as a comment on the PR
run: |
gh pr comment "$PULL_REQUEST_NUMBER" --body ":book: A new version of the docsite has been published at: <https://mcmire.github.io/super_diff/$DOCSITE_DESTINATION_PATH>"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST_NUMBER: ${{ github.event.number }}
DOCSITE_DESTINATION_PATH: ${{ needs.collect-docsite-release-info.outputs.DOCSITE_DESTINATION_PATH }}

unpublish_docsite:
runs-on: ubuntu-latest
needs:
- collect-release-info
- collect-docsite-release-info
if: ${{ github.event_name == 'pull_request' && needs.collect-release-info.outputs.IS_NEW_RELEASE == 'false' && github.event.action == 'closed' }}
steps:
- uses: actions/checkout@v4
with:
ref: gh-pages
- name: Set DOCSITE_DESTINATION_PARENT_PATH
run: |
set -x
DOCSITE_DESTINATION_PARENT_PATH="$(dirname "$DOCSITE_DESTINATION_PATH")"
echo "DOCSITE_DESTINATION_PARENT_PATH=$DOCSITE_DESTINATION_PARENT_PATH" >> "GITHUB_ENV"
env:
DOCSITE_DESTINATION_PATH: ${{ needs.collect-docsite-release-info.outputs.DOCSITE_DESTINATION_PATH }}
- name: Remove ${{ env.DOCSITE_DESTINATION_PARENT_PATH }} on gh-pages
run: |
set -x
if [[ "$DOCSITE_DESTINATION_PARENT_PATH" == "releases" || "$DOCSITE_DESTINATION_PARENT_PATH" == "branches" ]]; then
echo "Not removing $DOCSITE_DESTINATION_PARENT_PATH."
exit 1
fi
rm -rf "$DOCSITE_DESTINATION_PARENT_PATH"
- name: Re-push docsite if necessary
run: |
git add -A .
if ! git diff --cached --quiet; then
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git commit -m "Remove $DOCSITE_DESTINATION_PARENT_PATH"
git push
fi
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ zeus.server-start.log
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Ignore Python stuff
poetry.lock

# Ignore mkdocs stuff
site
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.yarn/cache
.yarn/releases
gemfiles
site
tmp
vendor/bundle
yarn.lock
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.2
33 changes: 0 additions & 33 deletions ARCHITECTURE.md

This file was deleted.

72 changes: 0 additions & 72 deletions CONTRIBUTING.md

This file was deleted.

Loading
Loading