更新 .gitea/workflows/7zip_update.yml
This commit is contained in:
102
.gitea/workflows/7zip_update.yml
Normal file
102
.gitea/workflows/7zip_update.yml
Normal file
@@ -0,0 +1,102 @@
|
||||
name: Update 7-Zip Binaries
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *' # Daily at midnight UTC
|
||||
workflow_dispatch: # Allow manual trigger
|
||||
|
||||
jobs:
|
||||
update:
|
||||
runs-on: ubuntu-latest # Adjust to your runner OS
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.GITEA_TOKEN }}
|
||||
|
||||
- name: Set up environment
|
||||
run: |
|
||||
# Install dependencies (e.g., curl, git)
|
||||
sudo apt-get update && sudo apt-get install -y curl git jq
|
||||
# Ensure 7zz is available for extraction (download latest if not in PATH)
|
||||
if ! command -v 7zz &> /dev/null; then
|
||||
curl -L https://github.com/ip7z/7zip/releases/latest/download/7zz -o /tmp/7zz
|
||||
chmod +x /tmp/7zz
|
||||
export PATH="/tmp:$PATH"
|
||||
fi
|
||||
|
||||
- name: Fetch latest release
|
||||
id: release
|
||||
run: |
|
||||
RELEASE_INFO=$(curl -s -H "Accept: application/vnd.github+json" \
|
||||
-H "Authorization: token ${{ secrets.GH_TOKEN || '' }}" \
|
||||
https://api.github.com/repos/ip7z/7zip/releases/latest)
|
||||
|
||||
VERSION=$(echo "$RELEASE_INFO" | jq -r .tag_name | sed 's/v//') # e.g., 25.01
|
||||
ASSETS=$(echo "$RELEASE_INFO" | jq -r '.assets[] | "\(.name)|\(.browser_download_url)|\(.size)"')
|
||||
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "assets<<EOF" >> $GITHUB_OUTPUT
|
||||
echo "$ASSETS" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Download and extract binary
|
||||
if: steps.release.outputs.version != ''
|
||||
run: |
|
||||
VERSION=${{ steps.release.outputs.version }}
|
||||
mkdir -p /app/7zip/$VERSION
|
||||
|
||||
# Find binary asset (prefer .7z or .tar.gz containing 7zz)
|
||||
ASSET_URL=""
|
||||
while IFS='|' read -r name url size; do
|
||||
if [[ "$name" == *.7z || "$name" == *.tar.gz ]]; then
|
||||
ASSET_URL="$url"
|
||||
ASSET_NAME="$name"
|
||||
break
|
||||
fi
|
||||
done <<< "${{ steps.release.outputs.assets }}"
|
||||
|
||||
if [ -z "$ASSET_URL" ]; then
|
||||
echo "No binary asset found, skipping."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Downloading $ASSET_NAME..."
|
||||
curl -L -o /tmp/asset "$ASSET_URL"
|
||||
|
||||
echo "Extracting 7zz..."
|
||||
cd /tmp
|
||||
if [[ "$ASSET_NAME" == *.7z ]]; then
|
||||
7zz x asset 7zz -o/app/7zip/$VERSION/
|
||||
elif [[ "$ASSET_NAME" == *.tar.gz ]]; then
|
||||
tar -xzf asset --wildcards '*7zz*' -C /app/7zip/$VERSION/ || (echo "Extraction failed, may not contain 7zz"; exit 1)
|
||||
fi
|
||||
|
||||
chmod +x /app/7zip/$VERSION/7zz
|
||||
echo "Saved 7zz to /app/7zip/$VERSION/"
|
||||
|
||||
- name: Commit changes
|
||||
run: |
|
||||
git config --local user.email "action@github.com"
|
||||
git config --local user.name "GitHub Action"
|
||||
|
||||
BRANCH="update-7zip-${{ steps.release.outputs.version }}"
|
||||
git checkout -b $BRANCH
|
||||
git add /app/7zip/ || true # Add if changes detected
|
||||
git commit -m "Update 7-Zip to version ${{ steps.release.outputs.version }}" || echo "No changes to commit"
|
||||
git push origin $BRANCH
|
||||
|
||||
- name: Create Pull Request
|
||||
if: steps.release.outputs.version != ''
|
||||
run: |
|
||||
BRANCH="update-7zip-${{ steps.release.outputs.version }}"
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"title": "Update 7-Zip to version ${{ steps.release.outputs.version }}",
|
||||
"body": "Automated update of 7zz binary from GitHub release.",
|
||||
"head": "'$BRANCH'",
|
||||
"base": "main"
|
||||
}' \
|
||||
${{ secrets.GITEA_INSTANCE_URL || 'https://gitea.com' }}/api/v1/repos/${{ github.repository }}/pulls
|
||||
@@ -1,159 +0,0 @@
|
||||
name: Sync Nextcloud and Build Docker
|
||||
|
||||
# 触发条件
|
||||
on:
|
||||
schedule:
|
||||
# 每天 18:00(UTC)执行一次(相当于北京时间 02:00),周日强制全量构建
|
||||
- cron: '0 18 * * *'
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'Dockerfile'
|
||||
workflow_dispatch: # 支持手动触发
|
||||
|
||||
# 环境变量(可根据需要自行修改)
|
||||
env:
|
||||
NEXTCLOUD_ZIP: latest.zip
|
||||
NEXTCLOUD_DIR: nextcloud
|
||||
|
||||
jobs:
|
||||
sync-and-build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write # 推送镜像需要
|
||||
steps:
|
||||
|
||||
# ==================== 1. 基础准备 ====================
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # 需要完整历史来比较变更
|
||||
|
||||
- name: Free disk space (optional)
|
||||
run: sudo df -h && sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
|
||||
|
||||
# ==================== 2. 同步 Nextcloud ====================
|
||||
- name: Create nextcloud directory
|
||||
run: mkdir -p ${{ env.NEXTCLOUD_DIR }}
|
||||
|
||||
- name: Download latest.zip
|
||||
id: download
|
||||
run: |
|
||||
curl -fsSL -o ${{ env.NEXTCLOUD_ZIP }} \
|
||||
https://download.nextcloud.com/server/releases/latest.zip || exit 1
|
||||
|
||||
- name: Unzip Nextcloud
|
||||
run: |
|
||||
unzip -qo ${{ env.NEXTCLOUD_ZIP }} -d ${{ env.NEXTCLOUD_DIR }}
|
||||
rm -f ${{ env.NEXTCLOUD_ZIP }}
|
||||
|
||||
# ==================== 3. 检测是否有文件变更 ====================
|
||||
- name: Check for changes
|
||||
id: check_changes
|
||||
run: |
|
||||
# 如果是 push 事件且路径匹配,已在触发器里过滤,这里再做一次细粒度检查
|
||||
if [ "${{ github.event_name }}" = "push" ]; then
|
||||
echo "Push 事件,文件已匹配,直接标记为需要构建"
|
||||
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 比较本地 nextcloud 目录与仓库中已有的差异
|
||||
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||
git fetch --depth=1 origin ${{ github.ref_name }} || true
|
||||
|
||||
# 统计差异文件数
|
||||
CHANGES=$(git diff --name-only HEAD ${{ env.NEXTCLOUD_DIR }} | wc -l)
|
||||
if [ "$CHANGES" -gt 0 ]; then
|
||||
echo "检测到 ${{ env.NEXTCLOUD_DIR }} 目录有 $CHANGES 处变更"
|
||||
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "无文件变更"
|
||||
echo "has_changes=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
# ==================== 4. 判断是否需要构建 Docker ====================
|
||||
- name: Decide whether to build
|
||||
id: should_build
|
||||
run: |
|
||||
# 1. 周日定时任务强制构建
|
||||
if [ "${{ github.event_name }}" = "schedule" ] && [ "$(date +%w)" = "0" ]; then
|
||||
echo "周日定时任务 → 强制构建"
|
||||
echo "build=true" >> $GITHUB_OUTPUT
|
||||
|
||||
# 2. push 触发且路径匹配(已在 trigger 中过滤,这里直接 true)
|
||||
elif [ "${{ github.event_name }}" = "push" ]; then
|
||||
echo "push 触发(Dockerfile)→ 构建"
|
||||
echo "build=true" >> $GITHUB_OUTPUT
|
||||
|
||||
# 3. 手动触发
|
||||
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
echo "手动触发 → 构建"
|
||||
echo "build=true" >> $GITHUB_OUTPUT
|
||||
|
||||
# 4. 有新的 Nextcloud 文件变更
|
||||
elif [ "${{ steps.check_changes.outputs.has_changes }}" = "true" ]; then
|
||||
echo "Nextcloud 同步有变更 → 构建"
|
||||
echo "build=true" >> $GITHUB_OUTPUT
|
||||
|
||||
# 5. 其它情况(包括非周日 schedule 且无变更)
|
||||
else
|
||||
echo "无变更且非强制构建时间 → 跳过构建"
|
||||
echo "build=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
# ==================== 5. 仅在需要时执行 Docker 构建 ====================
|
||||
- name: Set up Docker Buildx
|
||||
if: steps.should_build.outputs.build == 'true'
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Custom Registry
|
||||
if: steps.should_build.outputs.build == 'true'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ secrets.REGISTRY_SERVER }}/${{ gitea.repository_owner }}/nextcloud-docker
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Generate Beijing time version tag
|
||||
if: steps.should_build.outputs.build == 'true'
|
||||
id: version
|
||||
run: |
|
||||
echo "tag=$(TZ='Asia/Shanghai' date '+%Y%m%d-%H%M%S')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build & Push Docker image
|
||||
if: steps.should_build.outputs.build == 'true'
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64 # 可按需调整
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.REGISTRY_SERVER }}/${{ gitea.repository_owner }}/nextcloud-docker:latest
|
||||
${{ secrets.REGISTRY_SERVER }}/${{ gitea.repository_owner }}/nextcloud-docker:${{ steps.version.outputs.tag }}
|
||||
cache-from: type=registry,ref=${{ secrets.REGISTRY_SERVER }}/${{ gitea.repository_owner }}/nextcloud-docker:latest
|
||||
cache-to: type=inline,mode=max
|
||||
|
||||
# ==================== 6. 提交同步的 Nextcloud 文件(可选)================
|
||||
# 如果你希望把下载的 nextcloud 目录也提交回仓库(保持同步记录),打开下面这段
|
||||
# - name: Commit synced Nextcloud files
|
||||
# if: steps.check_changes.outputs.has_changes == 'true'
|
||||
# run: |
|
||||
# git config user.name "github-actions[bot]"
|
||||
# git config user.email "github-actions@users.noreply.github.com"
|
||||
# git add ${{ env.NEXTCLOUD_DIR }}
|
||||
# git commit -m "chore: sync nextcloud $(date '+%Y-%m-%d %H:%M:%S')" || echo "Nothing to commit"
|
||||
# git push origin HEAD:${{ github.ref_name }}
|
||||
|
||||
# ==================== 7. 结束提示 ====================
|
||||
- name: Build summary
|
||||
if: always()
|
||||
run: |
|
||||
echo "=== 工作流执行摘要 ==="
|
||||
echo "触发方式: ${{ github.event_name }}"
|
||||
echo "是否构建: ${{ steps.should_build.outputs.build }}"
|
||||
echo "Nextcloud 变更: ${{ steps.check_changes.outputs.has_changes }}"
|
||||
[ "${{ steps.should_build.outputs.build }}" = "true" ] && echo "镜像标签: ${{ steps.version.outputs.tag }}" || true
|
||||
Reference in New Issue
Block a user