Skip to content

Commit 656b4f2

Browse files
authored
SC-25005&&SC-25004: Fix CI/CD Slack notifications (#142)
* SC-25005&&SC-25004: Fix CI/CD Slack notifications * Revert ignore master * Fix CI/CD workflow
1 parent c4da21a commit 656b4f2

3 files changed

Lines changed: 41 additions & 19 deletions

File tree

.github/workflows/ci.yml

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
name: CI/CD
22

33
on:
4-
# push:
5-
# branches-ignore:
6-
# - master
74
workflow_call:
5+
inputs:
6+
publish:
7+
description: "Publish images to DockerHub and send the release Slack notification (set by the Combined workflow on master merge)."
8+
type: boolean
9+
default: false
10+
release_sha:
11+
description: "Commit SHA to reference in the notification (the merge commit on master)."
12+
type: string
13+
default: ""
814

915
concurrency:
1016
group: ${{ github.workflow }}-${{ github.ref }}
@@ -74,7 +80,11 @@ jobs:
7480
run: |
7581
IMAGE_TAG="${{ matrix.tags[0] }}"
7682
HAS_PREVIOUS=false
77-
if [ "${{ github.ref }}" = "refs/heads/master" ]; then
83+
PUBLISH=false
84+
RELEASE_SHA="${{ inputs.release_sha }}"
85+
if [ -z "$RELEASE_SHA" ]; then RELEASE_SHA="${{ github.sha }}"; fi
86+
if [ "${{ github.ref }}" = "refs/heads/master" ] || [ "${{ inputs.publish }}" = "true" ]; then
87+
PUBLISH=true
7888
PREV_COMMIT_HASH=$(git rev-parse HEAD^1)
7989
if docker pull "$IMAGE_TAG" >/dev/null 2>&1; then HAS_PREVIOUS=true; fi
8090
else
@@ -88,6 +98,8 @@ jobs:
8898
{
8999
echo "PREV_COMMIT_HASH=$PREV_COMMIT_HASH"
90100
echo "HAS_PREVIOUS=$HAS_PREVIOUS"
101+
echo "PUBLISH=$PUBLISH"
102+
echo "RELEASE_SHA=$RELEASE_SHA"
91103
} >> "$GITHUB_ENV"
92104
93105
- name: Set up QEMU
@@ -103,7 +115,7 @@ jobs:
103115
password: ${{ secrets.DOCKER_PASSWORD }}
104116

105117
- name: Re-tag images with previous commit hash
106-
if: ${{ github.ref == 'refs/heads/master' && env.HAS_PREVIOUS == 'true' }}
118+
if: ${{ env.PUBLISH == 'true' && env.HAS_PREVIOUS == 'true' }}
107119
run: |
108120
PREV_HASH=${{ env.PREV_COMMIT_HASH }}
109121
if [ -z "$PREV_HASH" ]; then
@@ -123,14 +135,14 @@ jobs:
123135
id: docker_build
124136
uses: docker/build-push-action@v2
125137
with:
126-
push: ${{ github.ref == 'refs/heads/master' }}
127-
load: ${{ github.ref != 'refs/heads/master' }}
138+
push: ${{ env.PUBLISH == 'true' }}
139+
load: ${{ env.PUBLISH != 'true' }}
128140
file: ${{ matrix.image }}
129141
tags: ${{ join(matrix.tags) }}
130-
platforms: ${{ github.ref == 'refs/heads/master' && join(matrix.platforms) || 'linux/amd64' }}
142+
platforms: ${{ env.PUBLISH == 'true' && join(matrix.platforms) || 'linux/amd64' }}
131143

132144
- name: Pull image for master branch
133-
if: github.ref == 'refs/heads/master'
145+
if: env.PUBLISH == 'true'
134146
run: |
135147
echo "Pulling image for master branch"
136148
docker pull ${{ matrix.tags[0] }}
@@ -156,21 +168,26 @@ jobs:
156168

157169
- name: Fetch Job ID
158170
id: fetch_job_id
159-
if: ${{ github.ref == 'refs/heads/master' && env.FORMATTED_DIFF != '' }}
171+
if: ${{ env.PUBLISH == 'true' && env.FORMATTED_DIFF != '' && steps.docker_build.outcome == 'success' }}
160172
env:
161173
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
162174
run: |
163175
JOBS_JSON=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
164-
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs")
165-
echo "$JOBS_JSON" > jobs-response.json
166-
cat jobs-response.json
167-
JOB_ID=$(echo "$JOBS_JSON" | jq -r --arg name "${{ matrix.image }}" \
168-
'.jobs[] | select(.name | contains($name)) | .id')
169-
echo "Extracted Job ID: $JOB_ID"
170-
echo "::set-output name=job_id::$JOB_ID"
176+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs?per_page=100")
177+
JOB=$(echo "$JOBS_JSON" | jq -r --arg name "${{ matrix.image }}" \
178+
'.jobs[] | select(.name | contains($name))')
179+
JOB_ID=$(echo "$JOB" | jq -r '.id')
180+
MANIFEST_STEP=$(echo "$JOB" | jq -r '.steps[] | select(.name=="Current image report") | .number')
181+
DIFF_STEP=$(echo "$JOB" | jq -r '.steps[] | select(.name=="Run the diff and format output") | .number')
182+
echo "Extracted Job ID: $JOB_ID (manifest step $MANIFEST_STEP, diff step $DIFF_STEP)"
183+
{
184+
echo "job_id=$JOB_ID"
185+
echo "manifest_step=$MANIFEST_STEP"
186+
echo "diff_step=$DIFF_STEP"
187+
} >> "$GITHUB_OUTPUT"
171188
172189
- name: Send Slack Notification
173-
if: ${{ github.ref == 'refs/heads/master' && env.FORMATTED_DIFF != '' }}
190+
if: ${{ env.PUBLISH == 'true' && env.FORMATTED_DIFF != '' && steps.docker_build.outcome == 'success' }}
174191
uses: slackapi/slack-github-action@v1.24.0
175192
with:
176193
payload: |
@@ -181,7 +198,7 @@ jobs:
181198
"fields": [
182199
{
183200
"title": "New version of ${{ matrix.tags[0] }} has been published",
184-
"value": "You can check the:\n- *Manifest*: <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ steps.fetch_job_id.outputs.job_id }}#step:9:1|View Manifest>\n- *Diff*: <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ steps.fetch_job_id.outputs.job_id }}#step:11:7|View Diff>\n\nThis version was built out of <https://github.com/${{ github.repository }}/commit/${{ github.sha }}|${{ github.sha }}>.",
201+
"value": "You can check the:\n- *Manifest*: <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ steps.fetch_job_id.outputs.job_id }}#step:${{ steps.fetch_job_id.outputs.manifest_step }}:1|View Manifest>\n- *Diff*: <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ steps.fetch_job_id.outputs.job_id }}#step:${{ steps.fetch_job_id.outputs.diff_step }}:1|View Diff>\n\nThis version was built out of <https://github.com/${{ github.repository }}/commit/${{ env.RELEASE_SHA }}|${{ env.RELEASE_SHA }}>.",
185202
"short": false
186203
}
187204
]

.github/workflows/combined-workflow.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ on:
99
jobs:
1010
# Step 1: CI/CD
1111
ci-cd:
12+
if: github.event.pull_request.merged == true
1213
uses: ./.github/workflows/ci.yml
1314
secrets: inherit
15+
with:
16+
publish: true
17+
release_sha: ${{ github.event.pull_request.merge_commit_sha }}
1418

1519
# Step 2: Security Scan
1620
security-scan:

debian/bullseye/8.4/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ ARG PHP_BUILD_DEPS="\
4444
libxml2-dev \
4545
libxpm-dev \
4646
libzip-dev \
47+
libssl-dev \
4748
librabbitmq-dev \
4849
libgrpc-dev \
4950
libprotobuf-dev \

0 commit comments

Comments
 (0)