From b375924f5e40547821e3e2483864b71bcd1f0965 Mon Sep 17 00:00:00 2001 From: okxlin Date: Sun, 4 Jun 2023 21:33:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0renovate-workflows?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/renovate-app-version.sh | 42 +++++++++++++++++++ .github/workflows/renovate-app-version.yml | 49 ++++++++++++++++++++++ .github/workflows/renovate.yml | 25 +++++++++++ 3 files changed, 116 insertions(+) create mode 100644 .github/workflows/renovate-app-version.sh create mode 100644 .github/workflows/renovate-app-version.yml create mode 100644 .github/workflows/renovate.yml diff --git a/.github/workflows/renovate-app-version.sh b/.github/workflows/renovate-app-version.sh new file mode 100644 index 00000000..07c09e49 --- /dev/null +++ b/.github/workflows/renovate-app-version.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# This script copies the version from docker-compose.yml to config.json. + +app_name=$1 +old_version=$2 + +# find all docker-compose files under apps/$app_name (there should be only one) +docker_compose_files=$(find $app_name/$old_version -name docker-compose.yml) + +# Declare an associative array to store excluded versions for each app_name +declare -A excluded_versions +excluded_versions["qBittorrent"]="4.3.5" +excluded_versions["php-unofficial"]="all" +# Add more excluded versions if needed + +for docker_compose_file in $docker_compose_files +do + # Skip if app_name and version match the excluded versions + if [[ "${excluded_versions[$app_name]}" == "all" ]]; then + continue + fi + + # 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) + + # Only apply changes if the format is : + if [[ "$image" == *":"* ]]; then + version=$(cut -d ":" -f2- <<< "$image") + + # Trim the "v" prefix + trimmed_version=${version/#"v"} + + # Skip if app_name and version match the excluded versions + if [[ "${excluded_versions[$app_name]}" == "$trimmed_version" ]]; then + continue + fi + + mv $app_name/$old_version $app_name/$trimmed_version + fi +done diff --git a/.github/workflows/renovate-app-version.yml b/.github/workflows/renovate-app-version.yml new file mode 100644 index 00000000..693a2990 --- /dev/null +++ b/.github/workflows/renovate-app-version.yml @@ -0,0 +1,49 @@ +name: Update app version in Renovate Branches + +on: + push: + branches: [ 'renovate/*' ] + +jobs: + update-app-version: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + 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" --no-verify && git push origin localApps || true + fi + done + diff --git a/.github/workflows/renovate.yml b/.github/workflows/renovate.yml new file mode 100644 index 00000000..4687df06 --- /dev/null +++ b/.github/workflows/renovate.yml @@ -0,0 +1,25 @@ +name: Renovate + +on: + schedule: + - cron: "0 0 * * *" + push: + branches: + - localApps + workflow_dispatch: + inputs: + manual-trigger: + description: 'Manually trigger Renovate' + default: '' + +jobs: + renovate: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3.3.0 + - name: Run Renovate + uses: renovatebot/github-action@v38.1.0 + with: + useSlim: false + token: ${{ secrets.GITHUBTOKEN }}