From 132439e0e8456e5bc5135b069bf69117afebe371 Mon Sep 17 00:00:00 2001 From: Ravi Singal <62086374+ravisingal@users.noreply.github.com> Date: Mon, 29 Jul 2024 09:06:44 +0530 Subject: [PATCH] chore: add action to update base image (#33) * chore: add action to update base image * rename action * update action --- .github/workflows/update-docker-args.yml | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/update-docker-args.yml diff --git a/.github/workflows/update-docker-args.yml b/.github/workflows/update-docker-args.yml new file mode 100644 index 0000000..d4f9a10 --- /dev/null +++ b/.github/workflows/update-docker-args.yml @@ -0,0 +1,58 @@ +name: Update Docker Args +on: + schedule: + - cron: 0 1 * * 1 + workflow_dispatch: +jobs: + update-docker-args: + runs-on: ubuntu-22.04 + permissions: + contents: write + pull-requests: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Update Docker Args + shell: bash + id: args + run: | + BASE_IMAGE="gcr.io/distroless/cc-debian12" + BASE_IMAGE_TAG="debug" + BASE_IMAGE_DIGEST=$(gcloud container images list-tags $BASE_IMAGE --format json | jq --arg tag "$BASE_IMAGE_TAG" -r '.[] | {digest: .digest, tag: .tags[]} | select(.tag == $tag) | .digest') + if [ -n "$BASE_IMAGE_DIGEST" ]; then + echo -n "${BASE_IMAGE}:${BASE_IMAGE_TAG}@${BASE_IMAGE_DIGEST}" > java-11/base.image + echo -n "${BASE_IMAGE}:${BASE_IMAGE_TAG}@${BASE_IMAGE_DIGEST}" > java-21/base.image + echo "digest=${BASE_IMAGE_DIGEST}" >> $GITHUB_OUTPUT + else + echo "digest=null" >> $GITHUB_OUTPUT + fi + + - name: Create Pull Request + if: steps.args.outputs.digest != 'null' + uses: peter-evans/create-pull-request@v6 + id: create-pull-request + with: + token: ${{ secrets.GITHUB_TOKEN }} + title: Update docker args (Automated) + body: | + # Autogenerated docker args update: + digest: ${{ steps.args.outputs.digest }} + commit-message: Update docker args + delete-branch: true + branch-suffix: timestamp + + - name: Enable Pull Request Automerge + if: steps.args.outputs.digest != 'null' + uses: peter-evans/enable-pull-request-automerge@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + pull-request-number: ${{ steps.create-pull-request.outputs.pull-request-number }} + merge-method: squash + + # - name: Approve Pull Request + # if: steps.args.outputs.digest != 'null' + # uses: juliangruber/approve-pull-request-action@v2 + # with: + # github-token: ${{ secrets.GITHUB_TOKEN }} + # number: ${{ steps.create-pull-request.outputs.pull-request-number }}