Skip to content

Commit

Permalink
🌱 auto update chart version (stolostron#100)
Browse files Browse the repository at this point in the history
* 🌱 auto update chart version

Signed-off-by: zhujian <[email protected]>

* upgrade checkout action tool version to v4

Signed-off-by: zhujian <[email protected]>

* check if chart version file changed

Signed-off-by: zhujian <[email protected]>

---------

Signed-off-by: zhujian <[email protected]>
  • Loading branch information
zhujian7 authored Mar 6, 2024
1 parent 29793de commit f6e2b3c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 23 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/go-postsubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/go-presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
89 changes: 73 additions & 16 deletions .github/workflows/go-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,30 @@ 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:
name: prepare release env
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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 }}",
},
})
Expand All @@ -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 }}

0 comments on commit f6e2b3c

Please sign in to comment.