From a2d9b8988ac0fa69169c4acd18ec3e3756f98de1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E6=A3=AE?= Date: Mon, 22 Jul 2024 12:43:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20renovate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 萌森 --- .github/workflows/renovate-app-version.sh | 34 +++++++++--- .github/workflows/renovate-app-version.yml | 7 +-- .../workflows/renovate-app-version.yml.bac | 53 +++++++++++++++++++ 3 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/renovate-app-version.yml.bac diff --git a/.github/workflows/renovate-app-version.sh b/.github/workflows/renovate-app-version.sh index c9f74829..37fe95f3 100644 --- a/.github/workflows/renovate-app-version.sh +++ b/.github/workflows/renovate-app-version.sh @@ -4,33 +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 + 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" + # 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 [[ "$trimmed_version" =~ ^[0-9]+(\.[0-9]+){0,3}$ ]]; then - # Extract the version part which can be 1 to 4 segments - trimmed_version=$(echo $trimmed_version | grep -oE '^[0-9]+(\.[0-9]+){0,4}') - elif [[ "$trimmed_version" =~ ^RELEASE\.[0-9]{4}-[0-9]{2}-[0-9]{2} ]]; then + 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 - trimmed_version=$(echo $trimmed_version | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}') + 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 - mv apps/$app_name/$old_version apps/$app_name/$trimmed_version + 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 b/.github/workflows/renovate-app-version.yml index 266eb810..6f258579 100644 --- a/.github/workflows/renovate-app-version.yml +++ b/.github/workflows/renovate-app-version.yml @@ -8,6 +8,7 @@ on: manual-trigger: description: 'Manually trigger Renovate' default: '' + jobs: update-app-version: runs-on: ubuntu-latest @@ -26,15 +27,16 @@ jobs: id: updated-files run: | echo "::set-output name=files::$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | tr '\n' ' ')" + echo "Updated files: ${{ steps.updated-files.outputs.files }}" - 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) + echo "Running script for app: $app_name, old version: $old_version" chmod +x .github/workflows/renovate-app-version.sh .github/workflows/renovate-app-version.sh $app_name $old_version fi @@ -43,11 +45,10 @@ jobs: - 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) + echo "Committing changes for app: $app_name" git add "apps/$app_name/*" && git commit -m "Update app version [skip ci]" --no-verify && git push || true fi done - diff --git a/.github/workflows/renovate-app-version.yml.bac b/.github/workflows/renovate-app-version.yml.bac new file mode 100644 index 00000000..266eb810 --- /dev/null +++ b/.github/workflows/renovate-app-version.yml.bac @@ -0,0 +1,53 @@ +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 +