From a545ef8d50f63a6a2aaafa07f3f9eb221951e929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E6=A3=AE?= Date: Wed, 31 Jul 2024 11:54:42 +0800 Subject: [PATCH] =?UTF-8?q?Bot=20=E8=84=9A=E6=9C=AC=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 萌森 --- .github/renovate.json | 20 +++++++ .github/workflows/renovate-app-version.sh | 60 +++++++++++++++---- .github/workflows/renovate-app-version.sh.bac | 50 ++++++++++++---- .../workflows/renovate-app-version.yml.bac | 53 ---------------- 4 files changed, 109 insertions(+), 74 deletions(-) delete mode 100644 .github/workflows/renovate-app-version.yml.bac diff --git a/.github/renovate.json b/.github/renovate.json index 0e298060..95f3f9c4 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -8,6 +8,23 @@ ], "rebaseWhen": "never", "packageRules": [ + { + "packagePatterns": [ + "^actions/checkout", + "renovatebot/github-action" + ], + "managers": [ + "github-actions" + ], + "updateTypes": [ + "minor", + "patch" + ], + "fileMatch": [ + "^\\.github/workflows/renovate-app-version\\.yml$", + "^\\.github/workflows/renovate\\.yml$" + ] + }, { "packageNames": [ "docker-compose" @@ -97,5 +114,8 @@ "versioning": "semver" } ], + "github-actions": { + "enabled": true + }, "prCreation": "immediate" } diff --git a/.github/workflows/renovate-app-version.sh b/.github/workflows/renovate-app-version.sh index 37fe95f3..1f6abcd1 100644 --- a/.github/workflows/renovate-app-version.sh +++ b/.github/workflows/renovate-app-version.sh @@ -4,21 +4,17 @@ app_name=$1 old_version=$2 +# 定义关联数组,将应用名称与其对应的 keys 关联起来 +declare -A app_keys +app_keys=(["immich"]="immich-server immich-machine-learning" ["stream-rec"]="stream-rec-backend stream-rec-frontend") + echo "Processing app: $app_name, old version: $old_version" # Find all docker-compose files under apps/$app_name (there should be only one) docker_compose_files=$(find apps/$app_name/$old_version -name docker-compose.yml) -for docker_compose_file in $docker_compose_files -do - echo "Processing docker-compose file: $docker_compose_file" - - # Assuming that the app version will be from the first docker image - first_service=$(yq '.services | keys | .[0]' $docker_compose_file) - - image=$(yq .services.$first_service.image $docker_compose_file) - - echo "Found image: $image" +process_image() { + local image=$1 # Only apply changes if the format is : if [[ "$image" == *":"* ]]; then @@ -43,11 +39,53 @@ do fi echo "Final version: $cleaned_version" + fi +} - # Move to the new versioned directory +for docker_compose_file in $docker_compose_files +do + echo "Processing docker-compose file: $docker_compose_file" + + # 判断 app_name 是否在关联数组中 + if [[ -n "${app_keys[$app_name]}" ]]; then + echo "$app_name is in the app_keys list." + # 获取对应的 keys + IFS=' ' read -r -a keys <<< "${app_keys[$app_name]}" + for key in "${keys[@]}"; do + echo "Processing key: $key" + first_service=$(yq ".services | keys | .[] | select(. == \"$key\")" $docker_compose_file) + + if [[ -n "$first_service" ]]; then + image=$(yq .services.$first_service.image $docker_compose_file) + echo "Found image for service $first_service: $image" + + # 进行后续处理 + process_image "$image" + else + echo "Key $key not found in $docker_compose_file" + fi + done + + # 在循环完毕后执行版本移动操作 if [[ -n "$cleaned_version" ]]; then mv apps/$app_name/$old_version apps/$app_name/$cleaned_version + echo "Moved $old_version to $cleaned_version" + else + echo "Could not determine version for image: $image" + fi + else + echo "$app_name is not in the app_keys list. Processing first service normally." + first_service=$(yq '.services | keys | .[0]' $docker_compose_file) + image=$(yq .services.$first_service.image $docker_compose_file) + echo "Found image: $image" + + # 进行后续处理 + process_image "$image" + + # 在处理第一个服务后执行版本移动操作 + if [[ -n "$cleaned_version" ]]; then + mv apps/$app_name/$old_version apps/$app_name/$cleaned_version echo "Moved $old_version to $cleaned_version" else echo "Could not determine version for image: $image" diff --git a/.github/workflows/renovate-app-version.sh.bac b/.github/workflows/renovate-app-version.sh.bac index 017b22e7..37fe95f3 100644 --- a/.github/workflows/renovate-app-version.sh.bac +++ b/.github/workflows/renovate-app-version.sh.bac @@ -4,23 +4,53 @@ app_name=$1 old_version=$2 -# find all docker-compose files under apps/$app_name (there should be only one) +echo "Processing app: $app_name, old version: $old_version" + +# Find all docker-compose files under apps/$app_name (there should be only one) docker_compose_files=$(find apps/$app_name/$old_version -name docker-compose.yml) for docker_compose_file in $docker_compose_files do - # Assuming that the app version will be from the first docker image - first_service=$(yq '.services | keys | .[0]' $docker_compose_file) + echo "Processing docker-compose file: $docker_compose_file" - image=$(yq .services.$first_service.image $docker_compose_file) + # Assuming that the app version will be from the first docker image + first_service=$(yq '.services | keys | .[0]' $docker_compose_file) - # Only apply changes if the format is : - if [[ "$image" == *":"* ]]; then - version=$(cut -d ":" -f2- <<< "$image") + image=$(yq .services.$first_service.image $docker_compose_file) - # Trim the "v" prefix - trimmed_version=${version/#"v"} + echo "Found image: $image" - mv apps/$app_name/$old_version apps/$app_name/$trimmed_version + # Only apply changes if the format is : + if [[ "$image" == *":"* ]]; then + version=$(cut -d ":" -f2- <<< "$image") + + echo "Extracted version: $version" + + # Trim the "v" prefix + trimmed_version=${version/#"v"} + + echo "Trimmed version: $trimmed_version" + + # Remove any suffixes (like -ffmpeg) for versioning purposes + cleaned_version=$(echo $trimmed_version | grep -oE '^[0-9]+(\.[0-9]+){0,4}') + + echo "Cleaned version: $cleaned_version" + + # Handle special versions with dates and other formats + if [[ -z "$cleaned_version" && "$trimmed_version" =~ ^RELEASE\.[0-9]{4}-[0-9]{2}-[0-9]{2} ]]; then + # Handle minio version format RELEASE.YYYY-MM-DDTHH-MM-SSZ + cleaned_version=$(echo $trimmed_version | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}') + fi + + echo "Final version: $cleaned_version" + + # Move to the new versioned directory + if [[ -n "$cleaned_version" ]]; then + mv apps/$app_name/$old_version apps/$app_name/$cleaned_version + + echo "Moved $old_version to $cleaned_version" + else + echo "Could not determine version for image: $image" + fi fi done diff --git a/.github/workflows/renovate-app-version.yml.bac b/.github/workflows/renovate-app-version.yml.bac deleted file mode 100644 index 266eb810..00000000 --- a/.github/workflows/renovate-app-version.yml.bac +++ /dev/null @@ -1,53 +0,0 @@ -name: Update app version in Renovate Branches - -on: - push: - branches: [ 'renovate/*' ] - workflow_dispatch: - inputs: - manual-trigger: - description: 'Manually trigger Renovate' - default: '' -jobs: - update-app-version: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 - with: - fetch-depth: 0 - - - name: Configure repo - run: | - git config --local user.email "githubaction@githubaction.com" - git config --local user.name "github-action update-app-version" - - - name: Get list of updated files by the last commit in this branch separated by space - id: updated-files - run: | - echo "::set-output name=files::$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | tr '\n' ' ')" - - - name: Run renovate-app-version.sh on updated files - run: | - IFS=' ' read -ra files <<< "${{ steps.updated-files.outputs.files }}" - - for file in "${files[@]}"; do - if [[ $file == *"docker-compose.yml"* ]]; then - app_name=$(echo $file | cut -d'/' -f 2) - old_version=$(echo $file | cut -d'/' -f 3) - chmod +x .github/workflows/renovate-app-version.sh - .github/workflows/renovate-app-version.sh $app_name $old_version - fi - done - - - name: Commit & Push Changes - run: | - IFS=' ' read -ra files <<< "${{ steps.updated-files.outputs.files }}" - - for file in "${files[@]}"; do - if [[ $file == *"docker-compose.yml"* ]]; then - app_name=$(echo $file | cut -d'/' -f 2) - git add "apps/$app_name/*" && git commit -m "Update app version [skip ci]" --no-verify && git push || true - fi - done -