-
Notifications
You must be signed in to change notification settings - Fork 10
208 lines (182 loc) · 7.83 KB
/
ci.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: CI/CD
on: push
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
## Alpine
### Alpine 3.18
- image: "alpine/3.18/8.1/Dockerfile"
tags: [ "spryker/php:8.1-alpine3.18" ]
platforms: [ "linux/amd64", "linux/arm64" ]
- image: "alpine/3.18/8.2/Dockerfile"
tags: [ "spryker/php:8.2-alpine3.18" ]
platforms: [ "linux/amd64", "linux/arm64" ]
- image: "alpine/3.18/8.3/Dockerfile"
tags: [ "spryker/php:8.3-alpine3.18" ]
platforms: [ "linux/amd64", "linux/arm64" ]
### Alpine 3.19
- image: "alpine/3.19/8.1/Dockerfile"
tags: [ "spryker/php:8.1-alpine3.19" ]
platforms: [ "linux/amd64", "linux/arm64" ]
- image: "alpine/3.19/8.2/Dockerfile"
tags: [ "spryker/php:8.2-alpine3.19" ]
platforms: [ "linux/amd64", "linux/arm64" ]
- image: "alpine/3.19/8.3/Dockerfile"
tags: [ "spryker/php:8.3-alpine3.19" ]
platforms: [ "linux/amd64", "linux/arm64" ]
### Alpine 3.20
- image: "alpine/3.20/8.1/Dockerfile"
tags: [ "spryker/php:8.1", "spryker/php:8.1-alpine3.20" ]
platforms: [ "linux/amd64", "linux/arm64" ]
- image: "alpine/3.20/8.2/Dockerfile"
tags: [ "spryker/php:latest", "spryker/php:8.2", "spryker/php:8.2-alpine3.20" ]
platforms: [ "linux/amd64", "linux/arm64" ]
- image: "alpine/3.20/8.3/Dockerfile"
tags: [ "spryker/php:8.3", "spryker/php:8.3-alpine3.20" ]
platforms: [ "linux/amd64", "linux/arm64" ]
## Debian
### Debian bullseye
- image: "debian/bullseye/8.0/Dockerfile"
tags: [ "spryker/php:8.0-debian" ]
platforms: [ "linux/amd64", "linux/arm64" ]
- image: "debian/bullseye/8.1/Dockerfile"
tags: [ "spryker/php:8.1-debian" ]
platforms: [ "linux/amd64", "linux/arm64" ]
- image: "debian/bullseye/8.2/Dockerfile"
tags: [ "spryker/php:8.2-debian" ]
platforms: [ "linux/amd64", "linux/arm64" ]
- image: "debian/bullseye/8.3/Dockerfile"
tags: [ "spryker/php:8.3-debian" ]
platforms: [ "linux/amd64", "linux/arm64" ]
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get the previous commit hash
id: previous_commit
run: |
if [ "${{ github.ref }}" == "refs/heads/master" ]; then
PREV_COMMIT_HASH=$(git rev-parse HEAD^1)
else
PREV_COMMIT_HASH=$(git rev-parse origin/master)
IMAGE_TAG="${{ matrix.tags[0] }}"
echo "Pulling image $IMAGE_TAG"
docker pull "$IMAGE_TAG"
NEW_TAG="${IMAGE_TAG}-${PREV_COMMIT_HASH}"
echo "Re-tagging image to $NEW_TAG"
docker tag "$IMAGE_TAG" "$NEW_TAG"
echo "Removing the pulled image $IMAGE_TAG"
docker rmi "$IMAGE_TAG" || true
fi
echo "PREV_COMMIT_HASH=$PREV_COMMIT_HASH" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Re-tag images with previous commit hash
if: ${{ github.ref == 'refs/heads/master' }}
run: |
PREV_HASH=${{ env.PREV_COMMIT_HASH }}
IMAGE_TAGS="${{ join(matrix.tags, ' ') }}"
for IMAGE_TAG in $IMAGE_TAGS; do
docker pull "$IMAGE_TAG"
NEW_TAG="${IMAGE_TAG}-${PREV_HASH}"
docker tag "$IMAGE_TAG" "$NEW_TAG"
echo "Re-tagged image: $NEW_TAG"
docker push $NEW_TAG
done
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: ${{ github.ref == 'refs/heads/master' }}
load: ${{ github.ref != 'refs/heads/master' }}
file: ${{ matrix.image }}
tags: ${{ join(matrix.tags) }}
platforms: ${{ github.ref == 'refs/heads/master' && join(matrix.platforms) || 'linux/amd64' }}
- name: Current image report
run: |
CURRENT_TAG=${{ matrix.tags[0] }}
bash .github/compare-images.sh $CURRENT_TAG > current-image-report.txt || true
cat current-image-report.txt
- name: Previous image report
run: |
PREVIOUS_TAG="${{ matrix.tags[0] }}-${{ env.PREV_COMMIT_HASH }}"
bash .github/compare-images.sh $PREVIOUS_TAG > previous-image-report.txt || true
cat previous-image-report.txt
- name: Run the diff and format output
run: |
diff_section() {
section="$1"
current_file="current-image-report.txt"
previous_file="previous-image-report.txt"
current_section=$(sed -n "/=== $section ===/,/=== /p" "$current_file" | sed '$d')
previous_section=$(sed -n "/=== $section ===/,/=== /p" "$previous_file" | sed '$d')
if [[ "$section" == "Installed System Packages" ]]; then
# Special formatting for Installed System Packages
diff_output=$(diff <(echo "$previous_section") <(echo "$current_section") | awk '
/^</ { old_line = substr($0, 3); split(old_line, parts, " - "); old_pkg = parts[1]; old_desc = parts[2]; }
/^>/ { new_line = substr($0, 3); split(new_line, parts, " - "); new_pkg = parts[1]; new_desc = parts[2];
if (old_pkg == new_pkg) {
print new_pkg ": " old_pkg " -> " new_pkg;
}
}')
else
# Generic formatting for other sections
diff_output=$(diff <(echo "$previous_section") <(echo "$current_section") | awk '
/^</ { old_line = substr($0, 3); }
/^>/ { new_line = substr($0, 3); print old_line " -> " new_line; }')
fi
echo "$diff_output"
}
# Initialize formatted diff
SECTIONS=("Alpine Version" "Installed PHP Extensions" "Disabled PHP Extensions" "PECL Extensions" "Installed System Packages")
FORMATTED_DIFF=""
for section in "${SECTIONS[@]}"; do
section_diff=$(diff_section "$section")
if [[ -n "$section_diff" ]]; then
FORMATTED_DIFF+="=== $section Diff ===\n"
FORMATTED_DIFF+="$section_diff\n"
fi
done
echo -e "Formatted Diff Output:\n$FORMATTED_DIFF"
# Export the formatted diff for Slack notification
echo "FORMATTED_DIFF<<EOF" >> $GITHUB_ENV
echo -e "$FORMATTED_DIFF" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Send Slack Notification
# if: ${{ github.ref == 'refs/heads/master' && env.DIFF_OUTPUT != '' }}
uses: slackapi/[email protected]
with:
payload: |
{
"attachments": [
{
"pretext": "New version of image *spryker/php:${{ matrix.tags[0] }}* has been published.",
"color": "good",
"fields": [
{
"title": "Release changes for *spryker/php:${{ matrix.tags[0] }}*:",
"value": "${{ env.FORMATTED_DIFF }}",
"short": false
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK