Skip to content

Commit a120461

Browse files
IONOS(ci): Update to integrate feedback
Signed-off-by: Aliza Held <aliza.held@strato.de>
1 parent acf0d8c commit a120461

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

.github/workflows/promote-artifact.yml

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ name: Promote QA-approved artifacts to stable branch
66

77
on:
88
workflow_dispatch:
9-
9+
inputs:
10+
sha:
11+
description: 'Commit SHA to promote from ionos-dev to ionos-stable and copy artifacts for'
12+
required: true
13+
type: string
1014
env:
1115
REGISTRY: ghcr.io
12-
SHA: ${{ github.sha }}
16+
SHA: ${{ inputs.sha }}
1317
ARTIFACTORY_REPOSITORY_SNAPSHOT: ionos-productivity-ncwserver-snapshot
18+
ARTIFACTORY_REPOSITORY_RELEASE: ionos-productivity-ncwserver-release
1419
CACHE_VERSION: v1.0
1520

1621
permissions:
@@ -31,9 +36,14 @@ jobs:
3136
- name: Verify SHA is in ionos-dev
3237
id: verify_sha
3338
run: |
34-
git checkout ionos-stable
35-
git fetch origin ionos-stable ionos-dev
36-
#verify SHA is on ionos-dev
39+
set -euo pipefail
40+
git fetch origin ionos-dev ionos-stable
41+
git checkout -B ionos-stable origin/ionos-stable
42+
if ! git rev-parse --verify "$SHA^{commit}" >/dev/null 2>&1; then
43+
echo "Error: SHA is not a valid commit: $SHA"
44+
exit 1
45+
fi
46+
# verify SHA is on ionos-dev
3747
if ! git merge-base --is-ancestor "$SHA" origin/ionos-dev; then
3848
echo "Error: SHA does not exist on ionos-dev: $SHA"
3949
exit 1
@@ -42,12 +52,13 @@ jobs:
4252
- name: Fast-forward merge
4353
id: ff_merge
4454
run: |
55+
set -euo pipefail
4556
# Merge will fail if not possible
4657
if ! git merge --ff-only "$SHA"; then
4758
echo "Fast-forward merge not possible"
4859
exit 1
4960
else
50-
git push origin ionos-stable
61+
git push origin HEAD:ionos-stable
5162
fi
5263
5364
promote-artifact:
@@ -72,18 +83,44 @@ jobs:
7283
- name: Find artifacts matching the SHA
7384
id: find_artifact
7485
run: |
75-
if ! jf rt search "ionos-productivity-ncwserver-snapshot/dev/*/$SHA/*.tar.gz"; then
86+
# Expected Artifactory layout:
87+
# ionos-productivity-ncwserver-snapshot/
88+
# dev/<branch-name>/$SHA/<artifact-files>
89+
#
90+
# We search for a single .tar.gz artifact for the given SHA and
91+
# derive its containing directory. This avoids using wildcards
92+
# for the branch component when copying to the release repo.
93+
set -e
94+
SEARCH_RESULT=$(jf rt search --format=json --limit=2 "${{ env.ARTIFACTORY_REPOSITORY_SNAPSHOT }}/dev/*/$SHA/*.tar.gz")
95+
MATCH_COUNT=$(echo "$SEARCH_RESULT" | jq '.results | length')
96+
97+
if [ "$MATCH_COUNT" -eq 0 ]; then
7698
echo "No artifact with SHA $SHA found."
7799
exit 1
78-
else
79-
echo "Artifact found for SHA $SHA"
80100
fi
81-
101+
102+
if [ "$MATCH_COUNT" -gt 1 ]; then
103+
echo "Multiple artifacts found for SHA $SHA; expected exactly one."
104+
echo "$SEARCH_RESULT"
105+
exit 1
106+
fi
107+
108+
ARTIFACT_REPO=$(echo "$SEARCH_RESULT" | jq -r '.results[0].repo')
109+
ARTIFACT_PATH=$(echo "$SEARCH_RESULT" | jq -r '.results[0].path')
110+
# Derive the directory that contains all artifacts for this SHA
111+
ARTIFACT_DIR_PATH=$(dirname "$ARTIFACT_PATH")
112+
ARTIFACT_DIR="$ARTIFACT_REPO/$ARTIFACT_DIR_PATH"
113+
114+
echo "Using artifact directory: $ARTIFACT_DIR"
115+
# Expose the directory as a step output for the copy step
116+
echo "artifact_dir=$ARTIFACT_DIR" >> "$GITHUB_OUTPUT"
82117
- name: Copy artifact to target
83118
id: copy_artifact
84119
run: |
85120
jf rt copy \
86-
"ionos-productivity-ncwserver-snapshot/dev/*/$SHA/*" \
87-
"ionos-productivity-ncwserver-release/$SHA/" \
88-
--flat=false
121+
"${{ steps.find_artifact.outputs.artifact_dir }}/*" \
122+
"${{ env.ARTIFACTORY_REPOSITORY_RELEASE }}/stable/${SHA}/"
89123
124+
- name: Confirm promoted artifacts
125+
run: |
126+
jf rt search --format=table "${{ env.ARTIFACTORY_REPOSITORY_RELEASE }}/stable/${SHA}/*"

0 commit comments

Comments
 (0)