Skip to content

Commit

Permalink
fixed preview workflow and added current version in navbar! (#488)
Browse files Browse the repository at this point in the history
* update preview workflow

* testing preview workflow

* testing preview workflow

* testing preview workflow

* testing preview workflow

* tests

* test2

* test2

* test2

* test2

* thollander comment workflow

* thollander comment workflow

* thollander comment workflow

* thollander comment workflow

* vcheck workflow test for forks

* vcheck skip

* added vdropdown with current version in navbar

* hotfix in _quarto.yml

* ajusted vdropdown a bit

* updated comments

* removed version and changelog from sidebar

* testing new workflow

* updated vcheck

* updated version in _quarto.yml

* updated version in _quarto.yml

* Changed sed to awk

* updated vcheck

* updated publish.yml

* .

* .

* updated vcheck

* updated vcheck

* another suggestion workflow

* updated suggestion workflow

* manual approach

* json parsing fixed

* continue on error previous worklow

* finally its done😊

* Update .github/workflows/vcheck.yml

Co-authored-by: Hong Ge <[email protected]>

---------

Co-authored-by: Hong Ge <[email protected]>
  • Loading branch information
shravanngoswamii and yebai authored Jul 6, 2024
1 parent 7a8fc92 commit b4d5b5b
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 100 deletions.
92 changes: 26 additions & 66 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

Expand Down Expand Up @@ -48,91 +48,51 @@ jobs:
_freeze/
key: ${{ runner.os }}-primes-${{ github.run_id }}

- name: Checkout gh-pages branch
uses: actions/checkout@v3
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
ref: gh-pages
path: gh-pages
branch: gh-pages
folder: _site
target-folder: pr-previews/${{ github.event.pull_request.number }}
clean: false
commit-message: Deploy preview for PR ${{ github.event.pull_request.number }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy Preview to GitHub Pages
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
PREVIEW_DIR="pr-previews/${PR_NUMBER}"
mkdir -p gh-pages/${PREVIEW_DIR}
cp -r _site/* gh-pages/${PREVIEW_DIR}
cd gh-pages
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Deploy preview for PR ${PR_NUMBER}"
git push
comment-preview-url:
needs: build-and-preview
if: needs.build-and-preview.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Comment Preview URL
uses: thollander/actions-comment-pull-request@v2
with:
message: |
<!-- preview-url-comment -->
Preview the changes: https://turinglang.org/docs/pr-previews/${{ github.event.pull_request.number }}
Please avoid using the search feature and navigation bar in PR previews!
comment_tag: preview-url-comment
env:
GH_PAT: ${{ secrets.GH_PAT }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

delete-preview-directory:
if: github.event.action == 'closed' || github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: gh-pages

- name: Remove PR Preview Directory
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
PREVIEW_DIR="pr-previews/${PR_NUMBER}"
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git pull origin gh-pages
rm -rf ${PREVIEW_DIR}
git add .
git commit -m "Remove preview for merged PR #${PR_NUMBER}"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

comment-preview-url:
needs: build-and-preview
if: needs.build-and-preview.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Comment Preview URL
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number;
const repoName = context.repo.repo;
const previewUrl = `https://turinglang.org/${repoName}/pr-previews/${prNumber}`;
const commentBody = `Preview the changes: ${previewUrl}, Please avoid using the search feature and navigation bar in PR previews!`;
const botUsername = 'github-actions[bot]';
// Check for existing comments by the bot
const existingComments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});

const botComment = existingComments.data.find(
(comment) => comment.user.login === botUsername
);

if (botComment) {
// Update the existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody,
});
} else {
// Create a new comment
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody,
});
}

29 changes: 20 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,26 @@ jobs:
run: |
jq -s '.[0] + .[1]' _site/search_original.json fixed_main_search.json > _site/search.json
- name: Read VERSION file
id: read_version
run: echo "version=$(cat VERSION)" >> $GITHUB_ENV
- name: Extract version from _quarto.yml
id: extract_version
run: |
minor_version=$(grep -oP 'text:\s+"v\K\d+\.\d+' _quarto.yml)
echo "minor_version=$minor_version" >> $GITHUB_ENV
- name: Fetch latest version from GitHub
id: fetch_latest_version
- name: Fetch latest bugfix version for the extracted minor version
id: fetch_latest_bugfix
run: |
repo_url="https://api.github.com/repos/TuringLang/Turing.jl/tags"
tags=$(curl -s $repo_url | jq -r '.[].name')
stable_tags=$(echo "$tags" | grep -Eo 'v[0-9]+\.[0-9]+\.[0-9]+$')
latest_bugfix=$(echo "$stable_tags" | grep "^v${{ env.minor_version }}" | sort -rV | head -n 1)
echo "version=$latest_bugfix" >> $GITHUB_ENV
- name: Fetch the actual latest bugfix version
id: fetch_latest_bugfix_actual
run: |
latest_version=$(curl --silent "https://api.github.com/repos/TuringLang/Turing.jl/releases/latest" | jq -r .tag_name)
echo "latest_version=$latest_version" >> $GITHUB_ENV
latest=$(curl --silent "https://api.github.com/repos/TuringLang/Turing.jl/releases/latest" | jq -r .tag_name)
echo "LATEST=$latest" >> $GITHUB_ENV
- name: Deploy versioned docs
uses: JamesIves/github-pages-deploy-action@v4
Expand All @@ -83,9 +94,9 @@ jobs:
clean: false

- name: Deploy latest docs to root
if: env.version == env.latest_version
if: env.version == env.LATEST
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: _site
clean: false
clean: false
40 changes: 23 additions & 17 deletions .github/workflows/vcheck.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
name: Check Turing.jl Version
on:
pull_request:
paths: ['VERSION']
paths: ['_quarto.yml']
workflow_dispatch:

permissions:
contents: read
pull-requests: write

jobs:
check-version:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get current version
id: current_version
run: echo "VERSION=$(cat VERSION)" >> $GITHUB_OUTPUT
- name: Extract current minor version
id: extract_minor_version
run: |
minor_version=$(grep -oP 'text:\s+"v\K\d+\.\d+' _quarto.yml)
echo "MINOR_VERSION=$minor_version" >> $GITHUB_OUTPUT
- name: Get latest Turing.jl version
id: latest_version
- name: Fetch latest minor version
id: fetch_latest_minor
run: |
latest=$(curl --silent "https://api.github.com/repos/TuringLang/Turing.jl/releases/latest" | jq -r .tag_name)
repo_url="https://api.github.com/repos/TuringLang/Turing.jl/releases/latest"
latest=$(curl -s $repo_url | jq -r .tag_name)
actual_latest_minor=${latest%.*}
echo "LATEST_MINOR=$actual_latest_minor" >> $GITHUB_OUTPUT
echo "LATEST=$latest" >> $GITHUB_OUTPUT
- name: Update VERSION file if outdated
- name: Update _quarto.yml if outdated
run: |
if [ "${{ steps.current_version.outputs.VERSION }}" != "${{ steps.latest_version.outputs.LATEST }}" ]; then
echo "${{ steps.latest_version.outputs.LATEST }}" > VERSION
minor_version=${{ steps.extract_minor_version.outputs.MINOR_VERSION }}
latest_minor=${{ steps.fetch_latest_minor.outputs.LATEST_MINOR }}
if [ "$minor_version" != "$latest_minor" ]; then
awk -v old="v$minor_version" -v new="$latest_minor" '{gsub(old, new); print}' _quarto.yml > temp.yml && mv temp.yml _quarto.yml
echo "Updated _quarto.yml to latest minor version: $latest_minor"
fi
- name: Suggest changes
uses: parkerbxyz/suggest-changes@v1
- name: Suggest Changes
uses: getsentry/action-git-diff-suggestions@main
with:
comment: 'If this PR is not intended to update any previous release, please update the VERSION file to the latest version.'
message: 'The version in _quarto.yml is outdated. Please update to the latest version.'
github-token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

17 changes: 10 additions & 7 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ website:
text: News
- href: https://turinglang.org/team/
text: Team
right:
# Current version
- text: "v0.33"
menu:
- text: Changelog
href: https://turinglang.org/docs/changelog.html
- text: All Versions
href: https://turinglang.org/docs/versions.html
tools:
- icon: twitter
href: https://x.com/TuringLang
Expand All @@ -42,7 +50,7 @@ website:
text: Turing GitHub

sidebar:
- id: documentation
- text: documentation
collapse-level: 1
contents:
- section: "Documentation"
Expand Down Expand Up @@ -111,11 +119,6 @@ website:
- tutorials/docs-07-for-developers-variational-inference/index.qmd
- text: "Implementing Samplers"
href: tutorials/docs-17-implementing-samplers/index.qmd

- text: "Versions"
href: versions.qmd
contents:
- changelog.qmd

page-footer:
background: "#073c44"
Expand All @@ -132,7 +135,7 @@ website:
aria-label: Turing GitHub

back-to-top-navigation: true
repo-url: https://github.com/TuringLang/TuringTutorials
repo-url: https://github.com/TuringLang/docs
repo-actions: [edit, issue]
repo-branch: master
repo-link-target: _blank
Expand Down
8 changes: 8 additions & 0 deletions theming/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@
.nav-footer-center {
display: flex;
justify-content: center;
}

.dropdown-menu {
text-align: center;
min-width: 100px !important;
border-radius: 5px;
max-height: 250px;
overflow: scroll;
}

0 comments on commit b4d5b5b

Please sign in to comment.