|
83 | 83 | message: "Please apply one of the following labels to the PR: 'patch', 'minor', 'major'."
|
84 | 84 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
85 | 85 |
|
| 86 | + prepare-release: |
| 87 | + needs: ["check-labels", "comment"] |
| 88 | + |
| 89 | + runs-on: ubuntu-latest |
| 90 | + |
| 91 | + steps: |
| 92 | + - uses: actions/checkout@v3 |
| 93 | + with: |
| 94 | + fetch-depth: 0 |
| 95 | + |
| 96 | + - id: bump |
| 97 | + uses: zwaldowski/match-label-action@v4 |
| 98 | + with: |
| 99 | + allowed: major,minor,patch |
| 100 | + |
| 101 | + - name: Get changed files |
| 102 | + id: changed-files |
| 103 | + uses: tj-actions/[email protected] |
| 104 | + |
| 105 | + |
| 106 | + # prepare yaml parser |
| 107 | + - uses: actions/setup-go@v4 |
| 108 | + - name: Install yq |
| 109 | + run: | |
| 110 | + go install github.com/mikefarah/yq/v4@latest |
| 111 | + yq --version |
| 112 | +
|
| 113 | + - uses: actions/checkout@v3 |
| 114 | + with: |
| 115 | + ref: ${{ github.head_ref }} |
| 116 | + path: current-branch |
| 117 | + |
| 118 | + - uses: actions/checkout@v3 |
| 119 | + with: |
| 120 | + ref: 'main' |
| 121 | + path: main |
| 122 | + |
| 123 | + - name: Update versions |
| 124 | + shell: bash |
| 125 | + run: | |
| 126 | + declare -A changedCharts |
| 127 | +
|
| 128 | + for file in ${{ steps.changed-files.outputs.all_changed_and_modified_files }}; do |
| 129 | +
|
| 130 | + echo "$file was changed" |
| 131 | + baseFolder=$(cut -d'/' -f1 <<< "$file") |
| 132 | + if [ $baseFolder = "charts" ] && [ $file != "charts/README.md" ]; then |
| 133 | + chartName=$(cut -d'/' -f2 <<< "$file") |
| 134 | + changedCharts[$chartName]=$chartName |
| 135 | + fi |
| 136 | + done |
| 137 | +
|
| 138 | + for c in "${changedCharts[@]}"; do |
| 139 | + # get version from chart yaml |
| 140 | + version=$(yq e '.version' "main/charts/$c/Chart.yaml") |
| 141 | + major=$(cut -d'.' -f1 <<< "$version") |
| 142 | + minor=$(cut -d'.' -f2 <<< "$version") |
| 143 | + patch=$(cut -d'.' -f3 <<< "$version") |
| 144 | +
|
| 145 | + prType=${{ steps.bump.outputs.match }} |
| 146 | + echo Update version $version with type $prType |
| 147 | + if [ $prType = "major" ]; then |
| 148 | + echo Update major |
| 149 | + major=$((major+1)) |
| 150 | + minor=0 |
| 151 | + patch=0 |
| 152 | + elif [ $prType = "minor" ]; then |
| 153 | + echo Update minor |
| 154 | + minor=$((minor+1)) |
| 155 | + patch=0 |
| 156 | + elif [ $prType = "patch" ]; then |
| 157 | + echo Update patch |
| 158 | + patch=$((patch+1)) |
| 159 | + fi |
| 160 | + echo Update version to $major.$minor.$patch for $c |
| 161 | + yq e -i '.version = "'$major.$minor.$patch'"' current-branch/charts/$c/Chart.yaml |
| 162 | + done |
| 163 | +
|
| 164 | + - name: Commit files |
| 165 | + continue-on-error: true |
| 166 | + run: | |
| 167 | + cd current-branch |
| 168 | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 169 | + git config --local user.name "github-actions[bot]" |
| 170 | + git status |
| 171 | + echo commit |
| 172 | + git commit -m "Update helm chart versions" -a |
| 173 | + echo status update |
| 174 | + git status |
| 175 | +
|
| 176 | + - name: Push changes |
| 177 | + continue-on-error: true |
| 178 | + uses: ad-m/github-push-action@master |
| 179 | + with: |
| 180 | + directory: current-branch |
| 181 | + branch: ${{ github.head_ref }} |
0 commit comments