Skip to content

Commit

Permalink
Extract the bump-agent-versions workflow into a script (#4521)
Browse files Browse the repository at this point in the history
When the script is in the multiline YAML it breaks the desired
formatting of the commit message.
Also editing this script separately is a better developer experience.
  • Loading branch information
rdner authored Apr 5, 2024
1 parent 09b7410 commit 3dab14d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/bump-agent-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -e

version_requirements=$(mage integration:updateVersions)
changes=$(git status -s -uno .agent-versions.json)
if [ -z "$changes" ]
then
echo "The versions file didn't change, skipping..."
else
echo "The versions file changed"
open=$(gh pr list --repo "$GITHUB_REPOSITORY" --label="update-versions" --limit 1 --state open --base "$GITHUB_REF_NAME")
if [ -n "$open" ]
then
echo "Another PR for $GITHUB_REF_NAME is in review, skipping..."
exit 0
fi
git diff -p
git config --global user.name 'apmmachine'
git config --global user.email '[email protected]'
git add ".agent-versions.json"
git commit -m "[$GITHUB_REF_NAME](automation) Update .agent-versions.json" -m "This file is used for picking agent versions in integration tests.\n\nThe file's content is based on responses from https://www.elastic.co/api/product_versions and https://snapshots.elastic.co\n\nThe current update is generated based on the following requirements:\n\`\`\`json\n$version_requirements\n\`\`\`"
git push --set-upstream origin "update-agent-versions-$GITHUB_RUN_ID"
gh pr create \
--base "$GITHUB_REF_NAME" \
--fill-first \
--head "update-agent-versions-$GITHUB_RUN_ID" \
--label 'Team:Elastic-Agent' \
--label 'update-versions' \
--label 'skip-changelog' \
--label 'backport-skip' \
--repo $GITHUB_REPOSITORY
fi
31 changes: 1 addition & 30 deletions .github/workflows/bump-agent-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,4 @@ jobs:
- name: Update versions file
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version_requirements=$(mage integration:updateVersions)
changes=$(git status -s -uno .agent-versions.json)
if [ -z "$changes" ]
then
echo "The versions file didn't change, skipping..."
else
echo "The versions file changed"
open=$(gh pr list --repo "$GITHUB_REPOSITORY" --label="update-versions" --limit 1 --state open --base "$GITHUB_REF_NAME")
if [ -n "$open" ]
then
echo "Another PR for $GITHUB_REF_NAME is in review, skipping..."
exit 0
fi
git diff -p
git config --global user.name 'apmmachine'
git config --global user.email '[email protected]'
git add ".agent-versions.json"
git commit -m "[$GITHUB_REF_NAME](automation) Update .agent-versions.json" -m "This file is used for picking agent versions in integration tests.\n\nThe file's content is based on responses from https://www.elastic.co/api/product_versions and https://snapshots.elastic.co\n\nThe current update is generated based on the following requirements:\n\`\`\`json\n$version_requirements\n\`\`\`"
git push --set-upstream origin "update-agent-versions-$GITHUB_RUN_ID"
gh pr create \
--base "$GITHUB_REF_NAME" \
--fill-first \
--head "update-agent-versions-$GITHUB_RUN_ID" \
--label 'Team:Elastic-Agent' \
--label 'update-versions' \
--label 'skip-changelog' \
--label 'backport-skip' \
--repo $GITHUB_REPOSITORY
fi
run: ./.github/workflows/bump-agent-versions.sh

0 comments on commit 3dab14d

Please sign in to comment.