From 770c2cdde82bc5364016278605a80c3ebdba18ed Mon Sep 17 00:00:00 2001 From: Timo Reichl Date: Wed, 6 Sep 2023 21:04:41 +0200 Subject: [PATCH] Split base image check for base-legacy and base-csgo Signed-off-by: Timo Reichl --- .github/workflows/base-csgo-image-check.yml | 106 ++++++++++++++++++ .github/workflows/base-image-check.yml | 100 ----------------- .github/workflows/base-legacy-image-check.yml | 106 ++++++++++++++++++ 3 files changed, 212 insertions(+), 100 deletions(-) create mode 100644 .github/workflows/base-csgo-image-check.yml delete mode 100644 .github/workflows/base-image-check.yml create mode 100644 .github/workflows/base-legacy-image-check.yml diff --git a/.github/workflows/base-csgo-image-check.yml b/.github/workflows/base-csgo-image-check.yml new file mode 100644 index 0000000..b997e19 --- /dev/null +++ b/.github/workflows/base-csgo-image-check.yml @@ -0,0 +1,106 @@ +name: Check for newer base-csgo image every night + +on: + schedule: + - cron: "0 0 * * *" + +jobs: + compare-base-csgo-image-tag: + permissions: write-all + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - name: Compare base-csgo image platform and tag + id: compare-base-csgo + run: | + # Get base-csgo SteamRT platform variant + export STEAMRT_PLATFORM_VARIANT=$(docker compose config base-csgo | grep 'STEAMRT_PLATFORM_VARIANT' | cut -d ':' -f 2 | xargs) + export STEAMRT_PLATFORM_VERSION=$(docker compose config base-csgo | grep 'STEAMRT_PLATFORM_VERSION' | cut -d ':' -f 2 | xargs) + + # Get image repository + current_repository=$(eval echo $(sed -rn '/FROM /p' image/base/Dockerfile | cut -d ' ' -f 2 | cut -d ':' -f 1)) + + # Use crane to list all available remote tags based on the base-csgo image tag prefix + # https://github.com/google/go-containerregistry/tree/main/cmd/crane + remote_tags=$(docker run --rm gcr.io/go-containerregistry/crane:v0.15.2 ls ${current_repository} | grep -v -e '[[a-z]]*') + + # Compare current tag to remote tags + new_tag=$(python3 ./scripts/compare_tags.py "${STEAMRT_PLATFORM_VERSION}" "${remote_tags}") + + if [[ ! -z "${new_tag}" ]]; then + echo "CI_PR_NEW_BASE_CSGO_IMAGE_TAG=${new_tag}" >> $GITHUB_ENV + echo "createpr_csgo=1" >> $GITHUB_OUTPUT + else + echo "No newer tag found." + echo "createpr_csgo=0" >> $GITHUB_OUTPUT + fi + + - name: Check if pull request exists for newer base-csgo image + if: ${{ steps.compare.outputs.createpr_csgo == 1 }} + id: checkpr_csgo + uses: actions/github-script@v6 + with: + script: | + const { repo, owner } = context.repo; + const result = await github.rest.pulls.list({ + owner, + repo, + head: 'actions/bump-base-csgo-image-tag', + base: 'main', + state: 'open' + }); + + if (result.length > 0) + { + return 'skip' + } + + return 'continue' + result-encoding: string + + - name: Push new branch with updated base-csgo image + if: ${{ steps.checkpr_csgo.outputs.result == 'continue' }} + run: | + # Install yq + apt-get update + apt-get install -y --no-install-recommends yq + + # Prepare git user + git config user.name github-actions + git config user.email github-actions@users.noreply.github.com + + # Checkout new branch from main + git fetch origin main + git checkout main + git checkout -b actions/bump-base-csgo-image-tag + + # Replace base-csgo image tag + cat docker-compose.yml | yq -M -y '.services."base-csgo".build.args.STEAMRT_PLATFORM_VERSION = "${CI_PR_NEW_BASE_CSGO_IMAGE_TAG}"' > docker-compose-new.yml + rm -rf docker-compose.yml + mv docker-compose-new.yml docker-compose.yml + + # Add, commit and push changes to the branch + git add docker-compose.yml + git commit -m "Bump base-csgo image tag to ${CI_PR_NEW_BASE_CSGO_IMAGE_TAG}" + git push origin actions/bump-base-csgo-image-tag -f + + - name: Create pull request for newer base-csgo image + if: ${{ steps.checkpr_csgo.outputs.result == 'continue' }} + uses: actions/github-script@v6 + with: + script: | + const { repo, owner } = context.repo; + const result = await github.rest.pulls.create({ + title: `[Bump] base-csgo image tag to ${process.env.CI_PR_NEW_BASE_CSGO_IMAGE_TAG}`, + owner, + repo, + head: 'actions/bump-base-csgo-image-tag', + base: 'main' + }); + github.rest.issues.addLabels({ + owner, + repo, + issue_number: result.data.number, + labels: ['improvement', 'bump base-csgo image tag'] + }); diff --git a/.github/workflows/base-image-check.yml b/.github/workflows/base-image-check.yml deleted file mode 100644 index e1b9329..0000000 --- a/.github/workflows/base-image-check.yml +++ /dev/null @@ -1,100 +0,0 @@ -name: Check for newer base image every night - -on: - schedule: - - cron: "0 0 * * *" - -jobs: - compare-base-image-tag: - permissions: write-all - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - - name: Compare base image tag - id: compare - run: | - # Get current base image tag - current_tag=$(grep 'ARG STEAMRT_PLATFORM_VERSION' image/base/Dockerfile | cut -d '=' -f 2) - - # Get current base image repository - current_repository=$(sed -rn '/FROM /p' image/base/Dockerfile | cut -d ' ' -f 2 | cut -d ':' -f 1) - - # Use crane to list all available remote tags based on the base image tag prefix - # https://github.com/google/go-containerregistry/tree/main/cmd/crane - remote_tags=$(docker run --rm gcr.io/go-containerregistry/crane:v0.15.2 ls ${current_repository} | grep -v -e '[[a-z]]*') - - # Compare current tag to remote tags - new_tag=$(python3 ./scripts/compare_tags.py "${current_tag}" "${remote_tags}") - - if [[ ! -z "${new_tag}" ]]; then - echo "CI_PR_OLD_BASE_IMAGE_TAG=${current_tag}" >> $GITHUB_ENV - echo "CI_PR_NEW_BASE_IMAGE_TAG=${new_tag}" >> $GITHUB_ENV - echo "createpr=1" >> $GITHUB_OUTPUT - else - echo "No newer tag found." - echo "createpr=0" >> $GITHUB_OUTPUT - fi - - - name: Check if pull request exists for newer base image - if: ${{ steps.compare.outputs.createpr == 1 }} - id: checkpr - uses: actions/github-script@v6 - with: - script: | - const { repo, owner } = context.repo; - const result = await github.rest.pulls.list({ - owner, - repo, - head: 'actions/bump-base-image', - base: 'main', - state: 'open' - }); - - if (result.length > 0) - { - return 'skip' - } - - return 'continue' - result-encoding: string - - - name: Push new branch with updated base image - if: ${{ steps.checkpr.outputs.result == 'continue' }} - run: | - # Prepare git user - git config user.name github-actions - git config user.email github-actions@github.com - - # Checkout new branch from main - git fetch origin main - git checkout main - git checkout -b actions/bump-base-image-tag - - # Replace base image tag - sed -i "s/ARG STEAMRT_PLATFORM_VERSION=${CI_PR_OLD_BASE_IMAGE_TAG}/ARG STEAMRT_PLATFORM_VERSION=${CI_PR_NEW_BASE_IMAGE_TAG}/" image/base/Dockerfile - - # Add, commit and push changes to the branch - git add image/base/Dockerfile - git commit -m "Bump base image tag to ${CI_PR_NEW_BASE_IMAGE_TAG}" - git push origin actions/bump-base-image-tag -f - - - name: Create pull request for newer base image - if: ${{ steps.checkpr.outputs.result == 'continue' }} - uses: actions/github-script@v6 - with: - script: | - const { repo, owner } = context.repo; - const result = await github.rest.pulls.create({ - title: `[Bump] Base image tag to ${process.env.CI_PR_NEW_BASE_IMAGE_TAG}`, - owner, - repo, - head: 'actions/bump-base-image-tag', - base: 'main' - }); - github.rest.issues.addLabels({ - owner, - repo, - issue_number: result.data.number, - labels: ['improvement', 'bump base image tag'] - }); diff --git a/.github/workflows/base-legacy-image-check.yml b/.github/workflows/base-legacy-image-check.yml new file mode 100644 index 0000000..ccfcedb --- /dev/null +++ b/.github/workflows/base-legacy-image-check.yml @@ -0,0 +1,106 @@ +name: Check for newer base-legacy image every night + +on: + schedule: + - cron: "0 0 * * *" + +jobs: + compare-base-legacy-image-tag: + permissions: write-all + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - name: Compare base-legacy image platform and tag + id: compare-base-legacy + run: | + # Get base-legacy SteamRT platform variant + export STEAMRT_PLATFORM_VARIANT=$(docker compose config base-legacy | grep 'STEAMRT_PLATFORM_VARIANT' | cut -d ':' -f 2 | xargs) + export STEAMRT_PLATFORM_VERSION=$(docker compose config base-legacy | grep 'STEAMRT_PLATFORM_VERSION' | cut -d ':' -f 2 | xargs) + + # Get image repository + current_repository=$(eval echo $(sed -rn '/FROM /p' image/base/Dockerfile | cut -d ' ' -f 2 | cut -d ':' -f 1)) + + # Use crane to list all available remote tags based on the base-legacy image tag prefix + # https://github.com/google/go-containerregistry/tree/main/cmd/crane + remote_tags=$(docker run --rm gcr.io/go-containerregistry/crane:v0.15.2 ls ${current_repository} | grep -v -e '[[a-z]]*') + + # Compare current tag to remote tags + new_tag=$(python3 ./scripts/compare_tags.py "${STEAMRT_PLATFORM_VERSION}" "${remote_tags}") + + if [[ ! -z "${new_tag}" ]]; then + echo "CI_PR_NEW_BASE_LEGACY_IMAGE_TAG=${new_tag}" >> $GITHUB_ENV + echo "createpr_legacy=1" >> $GITHUB_OUTPUT + else + echo "No newer tag found." + echo "createpr_legacy=0" >> $GITHUB_OUTPUT + fi + + - name: Check if pull request exists for newer base-legacy image + if: ${{ steps.compare.outputs.createpr_legacy == 1 }} + id: checkpr_legacy + uses: actions/github-script@v6 + with: + script: | + const { repo, owner } = context.repo; + const result = await github.rest.pulls.list({ + owner, + repo, + head: 'actions/bump-base-legacy-image-tag', + base: 'main', + state: 'open' + }); + + if (result.length > 0) + { + return 'skip' + } + + return 'continue' + result-encoding: string + + - name: Push new branch with updated base-legacy image + if: ${{ steps.checkpr_legacy.outputs.result == 'continue' }} + run: | + # Install yq + apt-get update + apt-get install -y --no-install-recommends yq + + # Prepare git user + git config user.name github-actions + git config user.email github-actions@users.noreply.github.com + + # Checkout new branch from main + git fetch origin main + git checkout main + git checkout -b actions/bump-base-legacy-image-tag + + # Replace base-legacy image tag + cat docker-compose.yml | yq -M -y '.services."base-legacy".build.args.STEAMRT_PLATFORM_VERSION = "${CI_PR_NEW_BASE_LEGACY_IMAGE_TAG}"' > docker-compose-new.yml + rm -rf docker-compose.yml + mv docker-compose-new.yml docker-compose.yml + + # Add, commit and push changes to the branch + git add docker-compose.yml + git commit -m "Bump base-legacy image tag to ${CI_PR_NEW_BASE_LEGACY_IMAGE_TAG}" + git push origin actions/bump-base-legacy-image-tag -f + + - name: Create pull request for newer base-legacy image + if: ${{ steps.checkpr_legacy.outputs.result == 'continue' }} + uses: actions/github-script@v6 + with: + script: | + const { repo, owner } = context.repo; + const result = await github.rest.pulls.create({ + title: `[Bump] base-legacy image tag to ${process.env.CI_PR_NEW_BASE_LEGACY_IMAGE_TAG}`, + owner, + repo, + head: 'actions/bump-base-legacy-image-tag', + base: 'main' + }); + github.rest.issues.addLabels({ + owner, + repo, + issue_number: result.data.number, + labels: ['improvement', 'bump base-legacy image tag'] + });