Skip to content

Commit fbd7bf8

Browse files
maasthaCopilot
andauthored
chore: Improve script to access release artifacts for Papertrail (#3436)
* improvements * clean * Update build/ci/papertrail.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * increase time --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 24e5134 commit fbd7bf8

File tree

2 files changed

+46
-47
lines changed

2 files changed

+46
-47
lines changed

build/ci/evergreen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exec_timeout_secs: 4200
1+
exec_timeout_secs: 5600
22
stepback: true
33
command_type: system
44
pre_error_fails_task: true

build/ci/papertrail.yml

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -47,71 +47,70 @@ functions:
4747
script: |
4848
export GH_TOKEN="${github_token}"
4949
50-
release_tag=$(gh release list --limit 1 --json tagName | jq -r '.[0].tagName')
51-
echo "DEBUG: extracted release_tag: $release_tag"
50+
git fetch --tags
51+
release_tag=$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' | sort -rV | head -n1)
5252
53-
version="$(echo "$release_tag" | cut -c2-)"
54-
echo "Tracing artifacts for version: $version"
53+
max_attempts=9 # release can take longer if QA tests are run (>1 hour)
54+
sleep_interval=600
5555
56-
if [[ -z "$release_tag" || "$release_tag" == "null" ]]; then
57-
echo "ERROR: Failed to extract valid release tag"
58-
exit 1
59-
fi
56+
echo "Waiting for 'release' job in workflow release.yml to succeed"
6057
61-
echo "Waiting 20 minutes before checking for release artifacts..."
62-
sleep 1200
58+
for ((attempt = 1; attempt <= max_attempts; attempt++)); do
59+
echo "Poll #$attempt"
6360
64-
echo "Checking for terraform-provider .zip artifacts in GitHub release..."
61+
# get the latest release workflow run
62+
run_id=$(gh run list --workflow release.yml --branch master --limit 1 --json databaseId --jq '.[0].databaseId')
63+
run_json=$(gh run view "$run_id" --json name,jobs)
6564
66-
max_attempts=5
67-
attempt=1
68-
artifact_found=false
65+
conclusion=$(jq -r '.jobs[] | select(.name=="release") | .conclusion' <<<"$run_json")
66+
version=$(jq -r '.name | match("v[0-9]+\\.[0-9]+\\.[0-9]+") | .string' <<<"$run_json")
6967
70-
while [ $attempt -le $max_attempts ]; do
71-
echo "Attempt $attempt: checking for artifacts..."
72-
gh release view "${release_tag}" --json assets --jq '.assets[].name' | grep -q 'terraform-provider-mongodbatlas.*\.zip'
73-
if [ $? -eq 0 ]; then
74-
echo "Artifacts found. Proceeding to download..."
75-
artifact_found=true
76-
break
68+
echo "conclusion=$conclusion version=$version"
69+
70+
# checking the latest tag version (that triggered this task) matches the version in the release workflow run name
71+
if [[ "$version" != "$release_tag" ]]; then
72+
echo "ERROR: version from run name ($version) != release tag ($release_tag)"
73+
exit 1
7774
fi
7875
79-
echo "Artifacts not available yet. Sleeping for 2 minutes before retry..."
80-
sleep 120
81-
attempt=$((attempt + 1))
76+
if [[ "$conclusion" == "success" ]]; then
77+
echo "✅ release job succeeded for $version"
78+
break
79+
80+
elif [[ "$conclusion" == "failure" || "$conclusion" == "cancelled" ]]; then
81+
echo "❌ release job failed (conclusion: $conclusion)"
82+
exit 1
83+
84+
else
85+
echo "Waiting for release to complete; sleeping $sleep_interval seconds"
86+
sleep "$sleep_interval"
87+
fi
8288
done
8389
84-
if [ "$artifact_found" != true ]; then
85-
echo "ERROR: No terraform-provider .zip artifacts found after waiting. Exiting..."
86-
gh release view "${release_tag}" --json assets --jq '.assets[].name'
90+
if ((attempt > max_attempts)) && [[ "$conclusion" != "success" ]]; then
91+
echo "ERROR: release job still not successful after $max_attempts polls"
8792
exit 1
8893
fi
8994
95+
echo "Downloading provider artifacts for $version"
9096
mkdir -p release_artifacts
91-
gh release download "${release_tag}" -p "terraform-provider-mongodbatlas*.zip" -D ./release_artifacts/
92-
93-
echo "Downloaded artifacts:"
94-
ls -la release_artifacts/
97+
gh release download "$release_tag" --pattern "terraform-provider-mongodbatlas*" --dir release_artifacts
9598
96-
echo "Removing any source code archives..."
97-
rm -f release_artifacts/Source* release_artifacts/source* 2>/dev/null || true
99+
rm -f release_artifacts/[Ss]ource* || true
98100
99-
echo "Final artifacts to trace:"
100-
ls -la release_artifacts/
101-
102-
artifact_count=$(ls -1 release_artifacts/*.zip 2>/dev/null | wc -l)
103-
if [ $artifact_count -eq 0 ]; then
104-
echo "ERROR: No terraform-provider .zip artifacts found for release ${release_tag}"
105-
echo "Available files in release:"
106-
gh release view "${release_tag}" --json assets --jq '.assets[].name'
101+
count=$(find release_artifacts -name 'terraform-provider-mongodbatlas*' | wc -l)
102+
echo "Found $count files"
103+
((count > 0)) || {
104+
echo "ERROR: no artifacts downloaded for $version"
107105
exit 1
108-
fi
106+
}
109107
110-
echo "Found $artifact_count terraform-provider artifacts to trace"
111-
112-
cat <<EOT >trace-expansions.yml
108+
cat >trace-expansions.yml <<EOF
113109
release_version: "$version"
114-
EOT
110+
EOF
111+
112+
echo "✅ Done."
113+
115114
116115
117116
- command: expansions.update

0 commit comments

Comments
 (0)