This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
106 lines (90 loc) · 4.05 KB
/
base-legacy-image-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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@v4
- name: Compare base-legacy image platform and tag
id: compare_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_legacy.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']
});