Skip to content

Update sync-agent-version-to-main.yml #18

Update sync-agent-version-to-main.yml

Update sync-agent-version-to-main.yml #18

# This workflow is used to create a PR with the existing agent version from the test branch to main
name: Sync Agent Version to main
# Controls when the workflow will run
on:
push:
branches: [ "test" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
open-pr:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
# Runs a set of commands using the runners shell
- name: Copy AgentBootrap to main
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
echo "Showing content of current AgentBootstrap"
cat instana/com.instana.agent.bootstrap.AgentBootstrap.cfg
rm -f /tmp/com.instana.agent.bootstrap.AgentBootstrap.cfg
cp instana/com.instana.agent.bootstrap.AgentBootstrap.cfg /tmp/
echo "Checking out main branch"
git fetch origin main
git checkout main
echo "Creating new branch from main"
git checkout -b promote-test-to-main
echo "Copy updated config to new branch"
rm -f instana/com.instana.agent.bootstrap.AgentBootstrap.cfg
cp -f /tmp/com.instana.agent.bootstrap.AgentBootstrap.cfg instana/com.instana.agent.bootstrap.AgentBootstrap.cfg
echo "Setting git author"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config --global user.name "${GITHUB_ACTOR}"
echo "Commiting change"
git add instana/com.instana.agent.bootstrap.AgentBootstrap.cfg
git commit -m "chore: Sync AgentBootstrap from current test branch"
echo "Push change to feature branch"
git push origin -f promote-test-to-main
UPDATED_VERSION=$(cat instana/com.instana.agent.bootstrap.AgentBootstrap.cfg | grep "version = " | grep -v "#" | cut -c11-)
PR_TITLE="chore(deps): Update Instana Agent Production to v${UPDATED_VERSION}"
PR_BODY="Automated sync of instana/com.instana.agent.bootstrap.AgentBootstrap.cfg from branch \"test\" to \"main\". Make sure that the test environment works as expected before approving and merging the change. Merging will trigger an production update including an agent restart. This update was driven by [this GitHub Action Workflow](https://github.com/konrad-ohms/instana-agent-gitops-config/blob/test/.github/workflows/sync-agent-version-to-main.yml). Available tags can be found on the [instana/agent-updates](https://github.com/instana/agent-updates/tags) repository."
gh pr create -B main --title "${PR_TITLE}" --body "${PR_BODY}" --label "production" || \
gh pr edit -B main --title "${PR_TITLE}" --body "${PR_BODY}" --add-label "production"