From f6e2b3c696d6362301c3d5c5724a428ad46fcf4e Mon Sep 17 00:00:00 2001 From: Jian Zhu Date: Wed, 6 Mar 2024 16:42:23 +0800 Subject: [PATCH] :seedling: auto update chart version (#100) * :seedling: auto update chart version Signed-off-by: zhujian * upgrade checkout action tool version to v4 Signed-off-by: zhujian * check if chart version file changed Signed-off-by: zhujian --------- Signed-off-by: zhujian --- .github/workflows/go-postsubmit.yml | 5 +- .github/workflows/go-presubmit.yml | 10 ++-- .github/workflows/go-release.yml | 89 +++++++++++++++++++++++------ 3 files changed, 81 insertions(+), 23 deletions(-) diff --git a/.github/workflows/go-postsubmit.yml b/.github/workflows/go-postsubmit.yml index 6322dc3..f9b5d40 100644 --- a/.github/workflows/go-postsubmit.yml +++ b/.github/workflows/go-postsubmit.yml @@ -12,6 +12,7 @@ env: GO_VERSION: '1.21' GO_REQUIRED_MIN_VERSION: '' GOPATH: '/home/runner/work/managed-serviceaccount/managed-serviceaccount/go' + defaults: run: working-directory: go/src/open-cluster-management.io/managed-serviceaccount @@ -25,7 +26,7 @@ jobs: arch: [ amd64, arm64 ] steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 1 path: go/src/open-cluster-management.io/managed-serviceaccount @@ -52,7 +53,7 @@ jobs: needs: [ images ] steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 1 path: go/src/open-cluster-management.io/managed-serviceaccount diff --git a/.github/workflows/go-presubmit.yml b/.github/workflows/go-presubmit.yml index f858416..14d77a2 100644 --- a/.github/workflows/go-presubmit.yml +++ b/.github/workflows/go-presubmit.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: install Go uses: actions/setup-go@v2 with: @@ -35,7 +35,7 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: install Go uses: actions/setup-go@v2 with: @@ -56,7 +56,7 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: install Go uses: actions/setup-go@v2 with: @@ -69,7 +69,7 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: install Go uses: actions/setup-go@v2 with: @@ -104,7 +104,7 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: install Go uses: actions/setup-go@v2 with: diff --git a/.github/workflows/go-release.yml b/.github/workflows/go-release.yml index 581a6d7..feb2820 100644 --- a/.github/workflows/go-release.yml +++ b/.github/workflows/go-release.yml @@ -8,13 +8,9 @@ env: # Common versions GO_VERSION: '1.21' GO_REQUIRED_MIN_VERSION: '' - GOPATH: '/home/runner/work/managed-serviceaccount/managed-serviceaccount/go' GITHUB_REF: ${{ github.ref }} CHART_NAME: managed-serviceaccount - -defaults: - run: - working-directory: go/src/open-cluster-management.io/managed-serviceaccount + CHART_VERSION_FILE_PATH: ./charts/managed-serviceaccount/Chart.yaml jobs: env: @@ -22,21 +18,20 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 1 - path: go/src/open-cluster-management.io/managed-serviceaccount - name: get release version run: | echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - name: get major release version run: | echo "MAJOR_RELEASE_VERSION=${RELEASE_VERSION%.*}" >> $GITHUB_ENV - echo "TRIMED_RELEASE_VERSION=${RELEASE_VERSION#v}" >> $GITHUB_ENV + echo "TRIMMED_RELEASE_VERSION=${RELEASE_VERSION#v}" >> $GITHUB_ENV outputs: MAJOR_RELEASE_VERSION: ${{ env.MAJOR_RELEASE_VERSION }} RELEASE_VERSION: ${{ env.RELEASE_VERSION }} - TRIMED_RELEASE_VERSION: ${{ env.TRIMED_RELEASE_VERSION }} + TRIMMED_RELEASE_VERSION: ${{ env.TRIMMED_RELEASE_VERSION }} images: name: images runs-on: ubuntu-latest @@ -46,10 +41,9 @@ jobs: arch: [ amd64, arm64 ] steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 1 - path: go/src/open-cluster-management.io/managed-serviceaccount - name: install Go uses: actions/setup-go@v2 with: @@ -73,10 +67,9 @@ jobs: needs: [ env, images ] steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 1 - path: go/src/open-cluster-management.io/managed-serviceaccount - name: create run: | echo ${{ secrets.DOCKER_PASSWORD }} | docker login quay.io --username ${{ secrets.DOCKER_USER }} --password-stdin @@ -98,10 +91,9 @@ jobs: needs: [ env, image-manifest ] steps: - name: checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 1 - path: go/src/open-cluster-management.io/managed-serviceaccount - name: setup helm uses: azure/setup-helm@v1 - name: chart package @@ -137,7 +129,7 @@ jobs: ref: 'main', inputs: { repo: "${{ github.repository }}", - version: "${{ needs.env.outputs.TRIMED_RELEASE_VERSION }}", + version: "${{ needs.env.outputs.TRIMMED_RELEASE_VERSION }}", "chart-name": "${{ env.CHART_NAME }}", }, }) @@ -146,3 +138,68 @@ jobs: console.error(error); core.setFailed(error); } + increase-chart-version: + runs-on: ubuntu-latest + needs: [ env, release ] + steps: + - name: checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: calculate next version + id: calculate_next_version + run: | + echo "Current version: $CURRENT_VERSION" + # Extract the major and minor version components + MAJOR=$(echo $CURRENT_VERSION | cut -d '.' -f 1) + MINOR=$(echo $CURRENT_VERSION | cut -d '.' -f 2) + # Increment the minor version + NEXT_MINOR=$((MINOR + 1)) + # Construct the next version + NEXT_VERSION="$MAJOR.$NEXT_MINOR.0" + echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT + env: + CURRENT_VERSION: ${{ needs.env.outputs.TRIMMED_RELEASE_VERSION }} + + - name: update chart version file + id: update_chart_version + run: | + echo "Updating chart version file from $CURRENT_VERSION to $NEXT_VERSION" + sed -i "s/version: $CURRENT_VERSION/version: $NEXT_VERSION/" ${{ env.CHART_VERSION_FILE_PATH }} + git diff + FILE_CHANGED=$(git diff --exit-code --quiet && echo false || echo true) + echo "Chart version file changed: $FILE_CHANGED" + echo "file_changed=$FILE_CHANGED" >> $GITHUB_OUTPUT + env: + CURRENT_VERSION: ${{ needs.env.outputs.TRIMMED_RELEASE_VERSION }} + NEXT_VERSION: ${{ steps.calculate_next_version.outputs.next_version }} + + - name: check if pull request already exists + id: check_pull_request + if : steps.update_chart_version.outputs.file_changed == 'true' + run: | + gh pr list --state open > pr_list.txt + cat pr_list.txt + PR_EXIST=$(grep -q "Update chart version to ${{ steps.calculate_next_version.outputs.next_version }}" pr_list.txt && echo true || echo false) + echo "pr_exists=$PR_EXIST" >> $GITHUB_OUTPUT + echo "Pull request for version ${{ steps.calculate_next_version.outputs.next_version }} exists: $PR_EXIST" + rm -rf pr_list.txt + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: create pull request + if: steps.update_chart_version.outputs.file_changed == 'true' && steps.check_pull_request.outputs.pr_exists != 'true' + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: | + Update chart version to ${{ steps.calculate_next_version.outputs.next_version }} + title: ":seedling: Update chart version to ${{ steps.calculate_next_version.outputs.next_version }}" + body: "Automatically updating chart version to ${{ steps.calculate_next_version.outputs.next_version }}" + branch: update-chart-version-${{ steps.calculate_next_version.outputs.next_version }} + signoff: true + base: main + env: + CURRENT_VERSION: ${{ needs.env.outputs.TRIMMED_RELEASE_VERSION }} + NEXT_VERSION: ${{ steps.calculate_next_version.outputs.next_version }}