Skip to content

feat: Integrate Bootstrap 5.3.3 via npm and Hugo modules #282

feat: Integrate Bootstrap 5.3.3 via npm and Hugo modules

feat: Integrate Bootstrap 5.3.3 via npm and Hugo modules #282

## Updates demo site (https://github.com/zetxek/adritian-demo)
## taken from https://stackoverflow.com/a/68213855/570087
name: PR demo site (on PR)
## This will open a PR which will open a vercel preview URL in the demo site
on:
pull_request:
branches: [main]
workflow_dispatch:
jobs:
update-demo:
env:
SOURCE_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
PR_NUMBER: ${{ github.event.number }}
HUGO_VERSION: 0.141.0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: zetxek/adritian-demo
token: ${{ secrets.PRIVATE_TOKEN_GITHUB }}
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: ${{ env.HUGO_VERSION }}
extended: true
- name: Send pull-request
shell: bash
run: |
LATEST_TAG=$(git describe --tags --always)
SOURCE_REPOSITORY="zetxek/adritian-free-hugo-theme"
LATEST_COMMIT=${{ github.event.pull_request.head.sha || github.sha }}
REPOSITORY="zetxek/adritian-demo"
FOLDER="bin/$REPOSITORY"
PR_URL="https://github.com/$SOURCE_REPOSITORY/pull/$PR_NUMBER"
BRANCH_NAME="theme-update/update-theme-to-$LATEST_TAG"
BASE_BRANCH="main"
ASSIGNEE="zetxek"
echo "Latest tag: $LATEST_TAG"
echo "Latest commit: $LATEST_COMMIT"
echo "PR URL: $PR_URL"
git config --global --add --bool push.autoSetupRemote true
# Clone the demo repository
git clone \
--depth=1 \
--branch=main \
https://some-user:${{ secrets.PRIVATE_TOKEN_GITHUB }}@github.com/$REPOSITORY \
$FOLDER
cd $FOLDER
# Setup git identity
git config user.email "actions@github.com"
git config user.name "GitHub Actions - update theme module"
# Create feature branch
git checkout -b $BRANCH_NAME
# Initialize Hugo module if needed
if [ ! -f "go.mod" ]; then
hugo mod init github.com/zetxek/adritian-demo
fi
# Get the specific commit of the theme
hugo mod get github.com/zetxek/adritian-free-hugo-theme@$LATEST_COMMIT
hugo mod tidy
# Commit changes
git add go.mod go.sum
COMMIT_MSG="preview: update theme module to commit \`$LATEST_COMMIT\`"
git commit -m "$COMMIT_MSG" && git push --force || echo "No changes to commit"
# Push branch
git push origin $BRANCH_NAME --force
# Setup GitHub CLI
echo "${{ secrets.PRIVATE_TOKEN_GITHUB }}" > token.txt
gh auth login --with-token < token.txt
# Check if PR exists
PR_EXISTS=$(gh pr list --state open --base $BASE_BRANCH --head $BRANCH_NAME --json number | jq '.[0].number // empty')
echo "PR_EXISTS: $PR_EXISTS"
if [ -n "$PR_EXISTS" ]; then
echo "PR Exists. Updating pull-request..."
gh pr view
echo "✅ Pull-request updated!"
else
echo "✨ Creating new pull-request..."
PR_TITLE="preview: update theme to commit \`$LATEST_COMMIT\`"
PR_BODY="⚠️ The source PR is not merged yet - this is a preview PR.
🤖 This automated PR updates the theme module to a PR in the source repo: $PR_URL.
🔗 Triggered by https://github.com/zetxek/adritian-free-hugo-theme/actions/workflows/update-demo-pr.yml"
PR_RESULT=$(gh pr create \
--title "$PR_TITLE" \
--body "$PR_BODY" \
--head $BRANCH_NAME \
--base $BASE_BRANCH \
--assignee $ASSIGNEE \
--label preview)
if [ $? -ne 0 ]; then
echo "Error creating PR: $PR_RESULT"
exit 0
fi
echo "✅ Pull-request created!"
fi