Skip to content

Commit c5e9707

Browse files
authored
Automate fetching the latest package version (#4768)
So, we don't have to manually edit the environment variable when the snapshot becomes available.
1 parent 302ec2c commit c5e9707

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

.buildkite/scripts/steps/integration_tests.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ MAGE_SUBTARGET="${3:-""}"
99

1010

1111
# Override the agent package version using a string with format <major>.<minor>.<patch>
12-
# NOTE: use only after version bump when the new version is not yet available, for example:
13-
# OVERRIDE_AGENT_PACKAGE_VERSION="8.10.3" otherwise OVERRIDE_AGENT_PACKAGE_VERSION="".
14-
OVERRIDE_AGENT_PACKAGE_VERSION="8.14.0"
12+
# There is a time when the snapshot is not built yet, so we cannot use the latest version automatically
13+
# This file is managed by an automation (mage integration:UpdateAgentPackageVersion) that check if the snapshot is ready.
14+
OVERRIDE_AGENT_PACKAGE_VERSION="$(cat .package-version)"
1515

1616
if [[ -n "$OVERRIDE_AGENT_PACKAGE_VERSION" ]]; then
1717
OVERRIDE_TEST_AGENT_VERSION=${OVERRIDE_AGENT_PACKAGE_VERSION}"-SNAPSHOT"
+9-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
#!/bin/bash
22
set -e
33

4+
package_version=$(mage integration:updatePackageVersion)
45
version_requirements=$(mage integration:updateVersions)
5-
changes=$(git status -s -uno .agent-versions.json)
6+
changes=$(git status -s -uno .agent-versions.json .package-version)
67
if [ -z "$changes" ]
78
then
8-
echo "The versions file didn't change, skipping..."
9+
echo "The version files didn't change, skipping..."
910
else
10-
echo "The versions file changed"
11+
echo "The version file(s) changed"
12+
git diff -p
1113
open=$(gh pr list --repo "$GITHUB_REPOSITORY" --label="update-versions" --limit 1 --state open --base "$GITHUB_REF_NAME")
1214
if [ -n "$open" ]
1315
then
1416
echo "Another PR for $GITHUB_REF_NAME is in review, skipping..."
1517
exit 0
1618
fi
17-
git diff -p
18-
git add ".agent-versions.json"
19+
git add .agent-versions.json .package-version
1920

2021
nl=$'\n' # otherwise the new line character is not recognized properly
21-
commit_desc="This file is used for picking agent versions in integration tests.${nl}${nl}The file's content is based on responses from https://www.elastic.co/api/product_versions and https://snapshots.elastic.co${nl}${nl}The current update is generated based on the following requirements:${nl}${nl}\`\`\`json${nl}${version_requirements}${nl}\`\`\`"
22+
commit_desc="These files are used for picking agent versions in integration tests.${nl}${nl}The content is based on responses from https://www.elastic.co/api/product_versions and https://snapshots.elastic.co${nl}${nl}The current update is generated based on the following requirements:${nl}${nl}Package version: ${package_version}${nl}${nl}\`\`\`json${nl}${version_requirements}${nl}\`\`\`"
2223

23-
git commit -m "[$GITHUB_REF_NAME][Automation] Update .agent-versions.json" -m "$commit_desc"
24+
git commit -m "[$GITHUB_REF_NAME][Automation] Update versions" -m "$commit_desc"
2425
git push --set-upstream origin "update-agent-versions-$GITHUB_RUN_ID"
2526
pr=$(gh pr create \
2627
--base "$GITHUB_REF_NAME" \
@@ -33,5 +34,5 @@ else
3334
--label 'backport-skip' \
3435
--repo $GITHUB_REPOSITORY)
3536
echo "pr=$pr" >> "$GITHUB_OUTPUT" # set the step output for Slack notifications
36-
echo "Created a PR with the file update: $pr"
37+
echo "Created a PR with the an update: $pr"
3738
fi

.github/workflows/bump-agent-versions.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
version: v1.13.0
4040
install-only: true
4141

42-
- name: Update versions file
42+
- name: Update versions
4343
id: update
4444
env:
4545
GH_TOKEN: ${{ env.GITHUB_TOKEN }}
@@ -51,7 +51,7 @@ jobs:
5151
url: ${{ secrets.VAULT_ADDR }}
5252
roleId: ${{ secrets.VAULT_ROLE_ID }}
5353
secretId: ${{ secrets.VAULT_SECRET_ID }}
54-
message: ":traffic_cone: Elastic Agent versions file update failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
54+
message: ":traffic_cone: Elastic Agent version update failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
5555
channel: "#ingest-notifications"
5656

5757
# if a PR was created as a result of this job, we notify on the Slack channel
@@ -61,5 +61,5 @@ jobs:
6161
url: ${{ secrets.VAULT_ADDR }}
6262
roleId: ${{ secrets.VAULT_ROLE_ID }}
6363
secretId: ${{ secrets.VAULT_SECRET_ID }}
64-
message: "Update for Elastic Agent versions file has been created: ${{ steps.update.outputs.pr }}"
64+
message: "Update for Elastic Agent versions has been created: ${{ steps.update.outputs.pr }}"
6565
channel: "#ingest-notifications"

.package-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.14.0

magefile.go

+28
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,34 @@ func (Integration) UpdateVersions(ctx context.Context) error {
20452045
return nil
20462046
}
20472047

2048+
// UpdatePackageVersion update the file that contains the latest available snapshot version
2049+
func (Integration) UpdatePackageVersion(ctx context.Context) error {
2050+
const packageVersionFilename = ".package-version"
2051+
2052+
sc := snapshots.NewSnapshotsClient()
2053+
versions, err := sc.FindLatestSnapshots(ctx, []string{"master"})
2054+
if err != nil {
2055+
return fmt.Errorf("failed to fetch a manifest for the latest snapshot: %w", err)
2056+
}
2057+
if len(versions) != 1 {
2058+
return fmt.Errorf("expected a single version, got %v", versions)
2059+
}
2060+
packageVersion := versions[0].CoreVersion()
2061+
file, err := os.OpenFile(packageVersionFilename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
2062+
if err != nil {
2063+
return fmt.Errorf("failed to open %s for write: %w", packageVersionFilename, err)
2064+
}
2065+
defer file.Close()
2066+
_, err = file.WriteString(packageVersion)
2067+
if err != nil {
2068+
return fmt.Errorf("failed to write the package version file %s: %w", packageVersionFilename, err)
2069+
}
2070+
2071+
fmt.Println(packageVersion)
2072+
2073+
return nil
2074+
}
2075+
20482076
var stateDir = ".integration-cache"
20492077
var stateFile = "state.yml"
20502078

0 commit comments

Comments
 (0)