|
| 1 | +name: check-helm |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 4 * * *" |
| 6 | + workflow_dispatch: |
| 7 | +jobs: |
| 8 | + check-helm-repo: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + env: |
| 11 | + TOOL_REPO: helm/helm |
| 12 | + GH_TOKEN: ${{ secrets.HELM_CHECK_TOKEN }} |
| 13 | + steps: |
| 14 | + - name: Check Out Code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + - name: Get latest HELM version |
| 17 | + run: | |
| 18 | + echo "REPO_HELM_VERSION=$(cat src/main/resources/tools.json | jq -r .tools.helm.version)" >> $GITHUB_ENV |
| 19 | + baseUrl="https://mirror.openshift.com/pub/openshift-v4/clients/helm" |
| 20 | + echo "LATEST_TOOL_URL=$(echo ${baseUrl})" >> $GITHUB_ENV |
| 21 | + echo "LATEST_TOOL_RELEASE=$(curl -s -L ${baseUrl} | grep "${baseUrl}" | sed "s|${baseUrl}||" | grep -v "latest" | sed 's/[^"]*"\([^"]*\).*/\1/' | sed "s|/||g" | sort -V | tail -n 1)" >> $GITHUB_ENV |
| 22 | + - name: Find existing PR for HELM version |
| 23 | + run: | |
| 24 | + echo PR_EXISTS=$(gh pr --repo ${{ github.repository }} list --state open --search "fix: update helm ${{env.LATEST_TOOL_RELEASE}} in:title" --json url | jq length) >> $GITHUB_ENV |
| 25 | + - name: Update tools.json with latest helm version |
| 26 | + if: ${{ (env.LATEST_TOOL_RELEASE != env.REPO_HELM_VERSION) && (env.PR_EXISTS == 0) }} |
| 27 | + run: | |
| 28 | + jq --indent 4 '.tools.helm.version = "${{ env.LATEST_TOOL_RELEASE }}"' src/main/resources/tools.json | jq --indent 4 '.tools.helm.versionMatchRegExpr = "${{ env.LATEST_TOOL_RELEASE }}"' > src/main/resources/tools.json.new |
| 29 | + mv src/main/resources/tools.json.new src/main/resources/tools.json |
| 30 | + for platform in win osx \"osx-aarch64\" lnx ; do |
| 31 | + old_url=`jq -r .tools.helm.platforms.${platform}.url src/main/resources/tools.json` |
| 32 | + new_url=`echo ${old_url} | sed "s|${{ env.REPO_HELM_VERSION }}|${{ env.LATEST_TOOL_RELEASE }}|"` |
| 33 | + checksum_url=`echo "${new_url}.sha256"` |
| 34 | + checksum=`curl -s -L ${checksum_url} | sed "s| ||g"` |
| 35 | + jq --indent 4 ".tools.helm.platforms.${platform}.url = \"${new_url}\"" src/main/resources/tools.json \ |
| 36 | + | jq --indent 4 ".tools.helm.platforms.${platform}..sha256sum = \"${checksum}\"" > src/main/resources/tools.json.new |
| 37 | + mv src/main/resources/tools.json.new src/main/resources/tools.json |
| 38 | + done |
| 39 | + - name: Create pull request |
| 40 | + if: ${{ (env.LATEST_TOOL_RELEASE != env.REPO_HELM_VERSION) && (env.PR_EXISTS == 0) }} |
| 41 | + run: | |
| 42 | + git config --global user.email "[email protected]" |
| 43 | + git config --global user.name "openshifttools-bot" |
| 44 | + git checkout -b "helm-${{ env.LATEST_TOOL_RELEASE }}" |
| 45 | + git commit -am "fix: Update helm to ${{ env.LATEST_TOOL_RELEASE }}" |
| 46 | + git push origin "helm-${{ env.LATEST_TOOL_RELEASE }}" |
| 47 | + gh pr create --title "fix: Update helm to ${{ env.LATEST_TOOL_RELEASE }}" --body "See ${{ env.LATEST_TOOL_URL }}" |
0 commit comments