Skip to content

Deploy to IC Mainnet #219

Deploy to IC Mainnet

Deploy to IC Mainnet #219

Workflow file for this run

name: Deploy to IC Mainnet
on:
push:
branches: [ main ]
paths-ignore:
- 'README.md'
- 'PLAN.md'
- 'docs/**'
- 'data/**'
- 'scripts/**'
pull_request:
branches: [ main ]
paths-ignore:
- 'README.md'
- 'PLAN.md'
- 'docs/**'
- 'data/**'
- 'scripts/**'
schedule:
# Run daily at 12:00 UTC (8:00 PM Shanghai time) to publish scheduled posts
- cron: '0 12 * * *'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for publishable posts
id: check_posts
run: |
echo "Checking for posts ready to publish..."
# Get current date in ISO format
CURRENT_DATE=$(date -u +"%Y-%m-%d")
echo "Current date: $CURRENT_DATE"
# Find all markdown files in content/posts
POST_COUNT=0
READY_TO_PUBLISH=false
# Check each post's frontmatter for date and draft status
while IFS= read -r post_file; do
# Extract date from frontmatter (handle both quoted and unquoted dates)
POST_DATE=$(grep -m 1 "^date:" "$post_file" | sed -E 's/date: *"?([0-9]{4}-[0-9]{2}-[0-9]{2}).*/\1/')
# Extract draft status (default to false if not present)
DRAFT_STATUS=$(grep -m 1 "^draft:" "$post_file" | sed -E 's/draft: *(true|false).*/\1/')
# If draft status is empty, assume false (not a draft)
if [ -z "$DRAFT_STATUS" ]; then
DRAFT_STATUS="false"
fi
# Check if post is ready to publish (date <= today AND not a draft)
if [ -n "$POST_DATE" ] && [ "$POST_DATE" \< "$CURRENT_DATE" ] || [ "$POST_DATE" = "$CURRENT_DATE" ]; then
if [ "$DRAFT_STATUS" = "false" ]; then
echo "✓ Ready to publish: $post_file (date: $POST_DATE)"
READY_TO_PUBLISH=true
POST_COUNT=$((POST_COUNT + 1))
fi
fi
done < <(find content/posts -name "*.md" -type f)
if [ "$READY_TO_PUBLISH" = "true" ]; then
echo "Found $POST_COUNT post(s) ready to publish"
echo "should_deploy=true" >> $GITHUB_OUTPUT
else
echo "No posts ready to publish - skipping deployment"
echo "should_deploy=false" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
if: steps.check_posts.outputs.should_deploy == 'true'
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup Hugo
if: steps.check_posts.outputs.should_deploy == 'true'
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
extended: true
- name: Install DFX via dfxvm
if: steps.check_posts.outputs.should_deploy == 'true'
run: |
# Download and install dfxvm directly
DFXVM_VERSION="1.0.1"
DFXVM_DIR="$HOME/.local/share/dfx"
mkdir -p "$DFXVM_DIR/bin"
# Download dfxvm for Linux
curl -L "https://github.com/dfinity/dfxvm/releases/download/v${DFXVM_VERSION}/dfxvm-x86_64-unknown-linux-gnu.tar.gz" -o dfxvm.tar.gz
# Extract and install dfxvm
tar -xzf dfxvm.tar.gz
mv dfxvm-x86_64-unknown-linux-gnu/dfxvm "$DFXVM_DIR/bin/"
chmod +x "$DFXVM_DIR/bin/dfxvm"
# Add to PATH and export for current session
echo "$DFXVM_DIR/bin" >> $GITHUB_PATH
export PATH="$DFXVM_DIR/bin:$PATH"
# Install and set DFX 0.24.3 as default
dfxvm default 0.24.3
# Find where dfx was installed and add to PATH
export PATH="$HOME/.local/share/dfx/versions/0.24.3:$PATH"
# Verify dfx installation
$HOME/.local/share/dfx/versions/0.24.3/dfx --version
# Set DFX path for subsequent steps
echo "DFX_PATH=$HOME/.local/share/dfx/versions/0.24.3" >> $GITHUB_ENV
- name: Build Hugo Site
if: steps.check_posts.outputs.should_deploy == 'true'
run: |
# Clean any existing build
rm -rf public/
# Build for production with proper settings
hugo --minify --environment production --gc --buildDrafts=false --buildFuture=false
- name: Import DFX Identity
if: steps.check_posts.outputs.should_deploy == 'true'
run: |
export PATH="$DFX_PATH:$PATH"
echo "${{ secrets.DFX_IDENTITY_GUIZISHANREN_PEM }}" > identity.pem
dfx identity import guizishanren identity.pem --disable-encryption || true
dfx identity use guizishanren
- name: Deploy to IC
if: steps.check_posts.outputs.should_deploy == 'true'
env:
DFX_NETWORK: ic
PATH: ${{ env.DFX_PATH }}:${{ env.PATH }}
run: |
# Deploy to IC
dfx deploy --network ic --yes