|
| 1 | +name: Check PR |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - synchronize |
| 8 | + - reopened |
| 9 | + - labeled |
| 10 | + - unlabeled |
| 11 | + branches: |
| 12 | + - master |
| 13 | + |
| 14 | +jobs: |
| 15 | + |
| 16 | + lint: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v2 |
| 21 | + |
| 22 | + - name: Lint |
| 23 | + run: ./.github/scripts/lint.sh |
| 24 | + |
| 25 | + eval: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + needs: |
| 28 | + - lint |
| 29 | + |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v2 |
| 32 | + - uses: azure/setup-helm@v4.3.0 |
| 33 | + - uses: bmuschko/setup-kubeconform@v1 |
| 34 | + |
| 35 | + - name: Eval |
| 36 | + run: | |
| 37 | + .github/scripts/eval.sh |
| 38 | +
|
| 39 | + check-labels: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + needs: |
| 42 | + - lint |
| 43 | + - eval |
| 44 | + |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v2 |
| 47 | + |
| 48 | + - uses: actions/setup-java@v1 |
| 49 | + with: |
| 50 | + java-version: '11' |
| 51 | + java-package: jdk |
| 52 | + |
| 53 | + - id: match-label |
| 54 | + name: Match semver labels |
| 55 | + uses: zwaldowski/match-label-action@v1 |
| 56 | + with: |
| 57 | + allowed: major, minor, patch |
| 58 | + |
| 59 | + - uses: zwaldowski/semver-release-action@v2 |
| 60 | + name: Semver release |
| 61 | + with: |
| 62 | + dry_run: true |
| 63 | + bump: ${{ steps.match-label.outputs.match }} |
| 64 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + |
| 66 | + comment: |
| 67 | + runs-on: ubuntu-latest |
| 68 | + needs: |
| 69 | + - "check-labels" |
| 70 | + |
| 71 | + if: always() |
| 72 | + steps: |
| 73 | + - uses: technote-space/workflow-conclusion-action@v2 |
| 74 | + - name: Checkout |
| 75 | + uses: actions/checkout@v1 |
| 76 | + |
| 77 | + - name: Comment PR |
| 78 | + if: env.WORKFLOW_CONCLUSION == 'failure' |
| 79 | + uses: thollander/actions-comment-pull-request@1.0.2 |
| 80 | + with: |
| 81 | + message: "Please apply one of the following labels to the PR: 'patch', 'minor', 'major'." |
| 82 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + |
| 84 | + prepare-release: |
| 85 | + needs: ["check-labels", "comment"] |
| 86 | + |
| 87 | + runs-on: ubuntu-latest |
| 88 | + |
| 89 | + steps: |
| 90 | + - uses: actions/checkout@v3 |
| 91 | + with: |
| 92 | + fetch-depth: 0 |
| 93 | + |
| 94 | + - id: bump |
| 95 | + uses: zwaldowski/match-label-action@v4 |
| 96 | + with: |
| 97 | + allowed: major,minor,patch |
| 98 | + |
| 99 | + - name: Get changed files |
| 100 | + id: changed-files |
| 101 | + uses: tj-actions/changed-files@v14.6 |
| 102 | + |
| 103 | + |
| 104 | + # prepare yaml parser |
| 105 | + - uses: actions/setup-go@v4 |
| 106 | + - name: Install yq |
| 107 | + run: | |
| 108 | + go install github.com/mikefarah/yq/v4@latest |
| 109 | + yq --version |
| 110 | +
|
| 111 | + - uses: actions/checkout@v3 |
| 112 | + with: |
| 113 | + ref: ${{ github.head_ref }} |
| 114 | + path: current-branch |
| 115 | + |
| 116 | + - uses: actions/checkout@v3 |
| 117 | + with: |
| 118 | + ref: 'master' |
| 119 | + path: master |
| 120 | + |
| 121 | + - name: Update versions |
| 122 | + shell: bash |
| 123 | + run: | |
| 124 | + declare -A changedCharts |
| 125 | +
|
| 126 | + for file in ${{ steps.changed-files.outputs.all_changed_and_modified_files }}; do |
| 127 | +
|
| 128 | + echo "$file was changed" |
| 129 | + baseFolder=$(cut -d'/' -f1 <<< "$file") |
| 130 | + if [ $baseFolder = "charts" ] && [ $file != "charts/README.md" ]; then |
| 131 | + chartName=$(cut -d'/' -f2 <<< "$file") |
| 132 | + changedCharts[$chartName]=$chartName |
| 133 | + fi |
| 134 | + done |
| 135 | +
|
| 136 | + for c in "${changedCharts[@]}"; do |
| 137 | + # get version from chart yaml |
| 138 | + version=$(yq e '.version' "master/charts/$c/Chart.yaml") |
| 139 | + major=$(cut -d'.' -f1 <<< "$version") |
| 140 | + minor=$(cut -d'.' -f2 <<< "$version") |
| 141 | + patch=$(cut -d'.' -f3 <<< "$version") |
| 142 | +
|
| 143 | + prType=${{ steps.bump.outputs.match }} |
| 144 | + echo Update version $version with type $prType |
| 145 | + if [ $prType = "major" ]; then |
| 146 | + echo Update major |
| 147 | + major=$((major+1)) |
| 148 | + minor=0 |
| 149 | + patch=0 |
| 150 | + elif [ $prType = "minor" ]; then |
| 151 | + echo Update minor |
| 152 | + minor=$((minor+1)) |
| 153 | + patch=0 |
| 154 | + elif [ $prType = "patch" ]; then |
| 155 | + echo Update patch |
| 156 | + patch=$((patch+1)) |
| 157 | + fi |
| 158 | + echo Update version to $major.$minor.$patch for $c |
| 159 | + yq e -i '.version = "'$major.$minor.$patch'"' current-branch/charts/$c/Chart.yaml |
| 160 | + done |
| 161 | +
|
| 162 | + - name: Commit files |
| 163 | + continue-on-error: true |
| 164 | + run: | |
| 165 | + cd current-branch |
| 166 | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 167 | + git config --local user.name "github-actions[bot]" |
| 168 | + git status |
| 169 | + echo commit |
| 170 | + git commit -m "Update helm chart versions" -a |
| 171 | + echo status update |
| 172 | + git status |
| 173 | +
|
| 174 | + - name: Push changes |
| 175 | + continue-on-error: true |
| 176 | + uses: ad-m/github-push-action@master |
| 177 | + with: |
| 178 | + directory: current-branch |
| 179 | + branch: ${{ github.head_ref }} |
0 commit comments