Skip to content

Sync Waline with Official Repository and Build #12

Sync Waline with Official Repository and Build

Sync Waline with Official Repository and Build #12

Workflow file for this run

name: Sync Waline with Official Repository and Build
on:
schedule:
- cron: '0 0 * * 0' # 每周日运行
workflow_dispatch: # 允许手动触发
jobs:
sync-and-build:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout local repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout official Waline repository
uses: actions/checkout@v4
with:
repository: walinejs/waline
path: official
ref: main
- name: Compare version numbers
id: compare-versions
run: |
$localVersion = Get-Content -Path "waline/package.json" | ConvertFrom-Json | Select-Object -ExpandProperty version
$officialVersion = Get-Content -Path "official/packages/server/package.json" | ConvertFrom-Json | Select-Object -ExpandProperty version
Write-Host "Local version: $localVersion"
Write-Host "Official version: $officialVersion"
if ($localVersion -ne $officialVersion) {
Write-Host "Versions differ, proceeding with sync"
echo "needs-sync=true" >> $env:GITHUB_OUTPUT
echo "local-version=$localVersion" >> $env:GITHUB_OUTPUT
echo "official-version=$officialVersion" >> $env:GITHUB_OUTPUT
} else {
Write-Host "Versions match, skipping sync"
echo "needs-sync=false" >> $env:GITHUB_OUTPUT
}
shell: pwsh
- name: Sync files
if: steps.compare-versions.outputs.needs-sync == 'true'
run: |
# 创建同步目录
New-Item -ItemType Directory -Path "sync" -Force
# 复制官方 packages/server 全部内容到 sync 目录
Copy-Item -Path "official/packages/server/*" -Destination "sync" -Recurse -Force
# 删除不需要同步的文件(例如本地专用的 Dockerfile 和 config.js)
Remove-Item -Path "sync/Dockerfile" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "sync/config.js" -Force -ErrorAction SilentlyContinue
# 用本地版本完全覆盖 dashboard.js 和 index.js,保留所有定制内容
Copy-Item -Path "waline/src/middleware/dashboard.js" -Destination "sync/src/middleware/dashboard.js" -Force
Copy-Item -Path "waline/src/controller/index.js" -Destination "sync/src/controller/index.js" -Force
# 将 sync 所有文件复制回本地 waline 目录
Copy-Item -Path "sync/*" -Destination "waline" -Recurse -Force
# 更新本地 package.json 的版本号为官方版本
$localPackageJson = Get-Content -Path "waline/package.json" | ConvertFrom-Json
$officialPackageJson = Get-Content -Path "official/packages/server/package.json" | ConvertFrom-Json
$localPackageJson.version = $officialPackageJson.version
$localPackageJson | ConvertTo-Json -Depth 100 | Set-Content -Path "waline/package.json"
Write-Host "Sync completed. Local version updated to $($officialPackageJson.version)"
shell: pwsh
- name: Commit and push changes
if: steps.compare-versions.outputs.needs-sync == 'true'
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add .
git commit -m "chore: sync with walinejs/waline@${{ steps.compare-versions.outputs.official-version }}"
git push
shell: bash
- name: Get new commit SHA
if: steps.compare-versions.outputs.needs-sync == 'true'
id: get-sha
run: |
NEW_SHA=$(git rev-parse --short HEAD)
echo "NEW_SHA=$NEW_SHA" >> $GITHUB_OUTPUT
shell: bash
- name: Pack webhook plugin
if: steps.compare-versions.outputs.needs-sync == 'true'
run: |
cd waline-plugin-webhook
npm pack
mv waline-plugin-webhook-*.tgz ../
shell: bash
- name: Set Docker image tag
if: steps.compare-versions.outputs.needs-sync == 'true'
id: set-tag
run: |
SHORT_SHA="${{ steps.get-sha.outputs.NEW_SHA }}"
echo "IMAGE_NAME=waline" >> $GITHUB_OUTPUT
echo "TAGS=tbeducn/waline:$SHORT_SHA,tbeducn/waline:latest" >> $GITHUB_OUTPUT
shell: bash
- name: Set up Docker QEMU
if: steps.compare-versions.outputs.needs-sync == 'true'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: steps.compare-versions.outputs.needs-sync == 'true'
uses: docker/setup-buildx-action@v3
- name: Check for required secrets
if: steps.compare-versions.outputs.needs-sync == 'true'
shell: bash
run: |
echo "Checking if DOCKER secrets are provided..."
if [ -z "${{ secrets.DOCKER_USERNAME }}" ]; then
echo "Error: DOCKER_USERNAME secret is required"
exit 1
fi
if [ -z "${{ secrets.DOCKER_PASSWORD }}" ]; then
echo "Error: DOCKER_PASSWORD secret is required"
exit 1
fi
echo "Secrets are provided"
echo "Registry: Docker Hub"
- name: Login to Docker Hub
if: steps.compare-versions.outputs.needs-sync == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Waline image
if: steps.compare-versions.outputs.needs-sync == 'true'
uses: docker/build-push-action@v6.14.0
with:
context: .
file: waline/Dockerfile
push: true
tags: ${{ steps.set-tag.outputs.TAGS }}
platforms: linux/amd64