Skip to content

Create preview.yml

Create preview.yml #4

Workflow file for this run

name: Jekyll Site Preview
on:
pull_request:
types: [opened, synchronize]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
container:
image: jekyll/jekyll:3.8
options: --user root
permissions:
contents: write
pull-requests: write
pages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up environment
run: |
gem install bundler:2.1.4
bundle config --global silence_root_warning true
- name: Build Jekyll site
run: |
bundle install
bundle exec jekyll build
env:
JEKYLL_ENV: production
- name: Setup git
run: |
apt-get update
apt-get install -y git
- name: Deploy preview
run: |
BRANCH_NAME="preview-pr-${{ github.event.pull_request.number }}"
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git checkout -b $BRANCH_NAME
mv _site/* ./
rm -rf _site
git add .
git commit -m "Deploy PR preview"
git push origin $BRANCH_NAME --force
- name: Comment PR
uses: actions/github-script@v7
with:
script: |
const prNumber = context.issue.number;
const repoName = context.repo.repo;
const ownerName = context.repo.owner;
const previewUrl = `https://${ownerName}.github.io/${repoName}/preview-pr-${prNumber}/`;
github.rest.issues.createComment({
owner: ownerName,
repo: repoName,
issue_number: prNumber,
body: `📝 Preview this PR at: ${previewUrl}`
});