-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (70 loc) · 2.85 KB
/
md-html-deploy.yml
File metadata and controls
81 lines (70 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: Workflow to convert Markdown files to HTML and deploy to GitHub Pages
on:
pull_request:
branches:
- main
# push:
# branches:
# - main # Trigger the workflow on push to the main branch
# - dev # Trigger the workflow on push to the dev branch
# - feature/* # Trigger the workflow on push to any feature branch
jobs:
build-and-deploy:
runs-on: ubuntu-latest # Use the latest Ubuntu environment
steps:
# Step 1: Checkout the repository
- name: Checkout repository
uses: actions/checkout@v2
# Step 2: Check for lock file
- name: Check for lock file
run: |
if [ -f .lock ]; then
echo "Another workflow is running. Exiting."
exit 1
fi
touch .lock
# Step 3: Set up Node.js environment
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14' # Specify the Node.js version
# Step 4: Install npm dependencies
- name: Install dependencies
run: npm install
# Step 5: Install pandoc for Markdown to HTML conversion
- name: Install pandoc
run: sudo apt-get install -y pandoc
# Step 6: Convert all Markdown files to HTML while preserving directory structure
- name: Convert Markdown to HTML
run: |
mkdir -p _site # Create the _site directory if it doesn't exist
# Find all Markdown files and convert them to HTML, preserving directory structure
find . -name "*.md" -type f | while read file; do
# Create the corresponding directory in _site
mkdir -p "_site/$(dirname "$file")"
# Convert the Markdown file to HTML and save it in the corresponding directory
pandoc "$file" --standalone --toc -o "_site/${file%.md}.html"
done
# Step 7: Deploy the generated HTML files to GitHub Pages
- name: Deploy to GitHub Pages
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Configure Git with a bot email and name
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
# Ensure all changes are staged
git add -A
# Commit changes if there are any
if git diff-index --quiet HEAD --; then
echo "No changes to commit"
else
git commit -m 'Deploy static HTML files'
fi
# Push changes to the pull request branch
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
git push origin HEAD:${{ github.event.pull_request.head.ref }} || echo "Push failed due to conflicts"
# Step 8: Remove lock file
- name: Remove lock file
if: always()
run: rm -f .lock