Skip to content

JuliaHealth Ecosystem Audit Blog Post #25

JuliaHealth Ecosystem Audit Blog Post

JuliaHealth Ecosystem Audit Blog Post #25

Workflow file for this run

name: PR Preview
on:
pull_request:
types:
- opened
- synchronize
- reopened
- closed
paths:
- "**/*.qmd"
- "**/*.yml"
- "**/*.yaml"
- "assets/**"
- "pages/**"
- "JuliaHealthBlog/**"
- "styles.css"
- "Project.toml"
- "Manifest.toml"
permissions:
contents: write
pull-requests: write
concurrency:
group: preview-pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
preview:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Julia
uses: julia-actions/setup-julia@v2
with:
version: "1"
- name: Cache Julia packages
uses: actions/cache@v4
with:
path: ~/.julia
key: ${{ runner.os }}-julia-${{ hashFiles('Project.toml', 'Manifest.toml') }}
restore-keys: |
${{ runner.os }}-julia-
- name: Instantiate Julia project
run: julia --project=. -e "using Pkg; Pkg.instantiate()"
- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
- name: Render site
uses: quarto-dev/quarto-actions/render@v2
- name: Deploy preview
if: github.event.pull_request.head.repo.full_name == github.repository
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./_site
destination_dir: previews/PR${{ github.event.pull_request.number }}
keep_files: true
commit_message: "ci: update preview for PR #${{ github.event.pull_request.number }} [skip ci]"
- name: Comment preview URL
if: github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@v7
with:
script: |
const previewUrl = `https://juliahealth.org/previews/PR${context.issue.number}/`;
const marker = '<!-- juliahealth-preview-link -->';
const body = `${marker}\nPreview available: ${previewUrl}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
per_page: 100
});
const existing = comments.find(comment =>
comment.user?.type === 'Bot' && comment.body?.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});
}
cleanup:
if: github.event.action == 'closed' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- name: Check out gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
fetch-depth: 0
- name: Remove preview folder
run: |
target="previews/PR${{ github.event.pull_request.number }}"
if [ -d "$target" ]; then
rm -rf "$target"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore: remove preview for PR #${{ github.event.pull_request.number }} [skip ci]"
git push origin HEAD:gh-pages
else
echo "No preview directory to clean."
fi