kubectl-update #288
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: kubectl-update | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 0 1 * *' # (At 00:00 on day-of-month 1) | |
| jobs: | |
| check-update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Generate token | |
| id: generate_token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ secrets.UPDATE_BOT_APP_ID }} | |
| private-key: ${{ secrets.UPDATE_BOT_PRIVATE_KEY }} | |
| - name: Check for Kubernetes updates | |
| id: check-update | |
| run: | | |
| CURRENT_KUBE_VERSION=$(sed -n -r -e "s/.*KUBE_VERSION=\"(.*)\"/\1/p" ./docker/kubectl/Dockerfile) | |
| LATEST_KUBE_VERSION=$(curl -LS https://dl.k8s.io/release/stable.txt) | |
| echo "current=$CURRENT_KUBE_VERSION" >> $GITHUB_ENV | |
| echo "latest=$LATEST_KUBE_VERSION" >> $GITHUB_ENV | |
| - name: Apply update & Create commit | |
| if: env.current != env.latest | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git switch -c actions/kubectl-${{ env.latest }} | |
| sed -i -r -e "s/(KUBE_VERSION=)\".*\"/\1\"${{ env.latest }}\"/g" ./docker/kubectl/Dockerfile | |
| git add ./docker/kubectl/Dockerfile | |
| git commit -m "Bump kubectl from ${{ env.current }} to ${{ env.latest }} in /docker/kubectl" | |
| git push --set-upstream origin actions/kubectl-${{ env.latest }} | |
| - name: Create pull request | |
| if: env.current != env.latest | |
| run: | | |
| gh pr create -B main -H actions/kubectl-${{ env.latest }} \ | |
| --title 'Bump kubectl from ${{ env.current }} to ${{ env.latest }} in /docker/kubectl' \ | |
| --body 'Bumps kubectl from `${{ env.current }}` to `${{ env.latest }}`.' | |
| env: | |
| GH_TOKEN: ${{ steps.generate_token.outputs.token }} |