Skip to content

Conversation

donoghuc
Copy link
Member

This commit adds a GH action for bumping the logstash version. It uses the updatescli based on a suggestion for how the beats team is doing file updates. There is a workflow_dispatch trigger that accepts a new logstash version. Both the versions.yml and lock file are updated. If it is a branch where we are not vendoring a lockfile that file is skipped without failing the workflow step.

Implements https://github.com/elastic/ingest-dev/issues/5977

Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

Copy link
Contributor

mergify bot commented Aug 25, 2025

This pull request does not have a backport label. Could you fix it @donoghuc? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit.
  • If no backport is necessary, please add the backport-skip label

@donoghuc
Copy link
Member Author

Use of updatecli for dep bumps was based on this comment #17945 (comment)

@donoghuc
Copy link
Member Author

To test locally:

install updatecli

brew install updatecli/updatecli/updatecli

generate config file:

# Create the same config the GitHub Action uses
cat > test-updatecli.yml << 'EOF'
name: Update versions.yml

sources:
  logstash_version:
    kind: shell
    spec:
      command: echo "9.3.0"

targets:
  update_logstash_version:
    name: Update logstash version in versions.yml
    kind: yaml
    spec:
      file: versions.yml
      key: $.logstash
    sourceid: logstash_version
  
  update_logstash_core_version:
    name: Update logstash-core version in versions.yml
    kind: yaml
    spec:
      file: versions.yml
      key: $.logstash-core
    sourceid: logstash_version

---
name: Update lock file

sources:
  logstash_version:
    kind: shell
    spec:
      command: echo "9.3.0"

conditions:
  check_lockfile_exists:
    name: Check if lockfile exists
    kind: shell
    disablesourceinput: true
    spec:
      command: test -f Gemfile.jruby-3.1.lock.release

targets:
  update_gemfile_lock_dependency:
    name: Update logstash-core dependency
    kind: file
    spec:
      file: Gemfile.jruby-3.1.lock.release
      matchpattern: 'logstash-core \(= [0-9]+\.[0-9]+\.[0-9]+'
      replacepattern: 'logstash-core (= 9.3.0'
    sourceid: logstash_version
  
  update_gemfile_lock_spec:
    name: Update logstash-core spec
    kind: file
    spec:
      file: Gemfile.jruby-3.1.lock.release
      matchpattern: 'logstash-core \([0-9]+\.[0-9]+\.[0-9]+-java\)'
      replacepattern: 'logstash-core (9.3.0-java)'
    sourceid: logstash_version
EOF

run

➜  logstash git:(bump-ls-version-action) ✗ updatecli apply --config test-updatecli.yml



+++++++++++
+ PREPARE +
+++++++++++

Loading Pipeline "test-updatecli.yml"

SCM repository retrieved: 0


++++++++++++++++++
+ AUTO DISCOVERY +
++++++++++++++++++



++++++++++++
+ PIPELINE +
++++++++++++



#######################
# UPDATE VERSIONS.YML #
#######################

source: source#logstash_version
-----------------------
The shell 🐚 command "/bin/sh /var/folders/cw/q_xjr4md1wj_w_c1xwfrnxdw0000gn/T/updatecli/bin/33b3af0384bd90f14aef112598cfabdf6d6e77168b475723abbaaf5f269b28f2.sh" ran successfully with the following output:
----
9.3.0
----
✔ shell command executed successfully

target: target#update_logstash_core_version
-----------------------------------
⚠ - change detected:
	* key "$.logstash-core" updated from "9.2.0" to "9.3.0", in file "versions.yml"

target: target#update_logstash_version
------------------------------
⚠ - change detected:
	* key "$.logstash" updated from "9.2.0" to "9.3.0", in file "versions.yml"


####################
# UPDATE LOCK FILE #
####################

source: source#logstash_version
-----------------------
The shell 🐚 command "/bin/sh /var/folders/cw/q_xjr4md1wj_w_c1xwfrnxdw0000gn/T/updatecli/bin/33b3af0384bd90f14aef112598cfabdf6d6e77168b475723abbaaf5f269b28f2.sh" ran successfully with the following output:
----
9.3.0
----
✔ shell command executed successfully

condition: condition#check_lockfile_exists
-------------------------------
The shell 🐚 command "/bin/sh /var/folders/cw/q_xjr4md1wj_w_c1xwfrnxdw0000gn/T/updatecli/bin/c4efa96ffd6665bfcc18724aff4523a9b7e976d0a59d6da437e1263a76b5f8c6.sh" exited on error (exit code 1) with the following output:
----
----

command stderr output was:
----
----
shell command failed. Expected exit code 0 but got 1
✗ shell condition of type "console/output" not passing

target: target#update_gemfile_lock_spec
-------------------------------

target: target#update_gemfile_lock_dependency
-------------------------------------


ACTIONS
========


=============================

SUMMARY:



- Update lock file:
	Source:
		✔ [logstash_version]
	Condition:
		✗ [check_lockfile_exists] Check if lockfile exists
	Target:
		- [update_gemfile_lock_dependency] Update logstash-core dependency
		- [update_gemfile_lock_spec] Update logstash-core spec


⚠ Update versions.yml:
	Source:
		✔ [logstash_version]
	Target:
		⚠ [update_logstash_core_version] Update logstash-core version in versions.yml
		⚠ [update_logstash_version] Update logstash version in versions.yml


Run Summary
===========
Pipeline(s) run:
  * Changed:	1
  * Failed:	0
  * Skipped:	1
  * Succeeded:	0
  * Total:	2

This commit adds a GH action for bumping the logstash version. It uses the
updatescli based on a suggestion for how the beats team is doing file updates.
There is a workflow_dispatch trigger that accepts a new logstash version. Both
the versions.yml and lock file are updated. If it is a branch where we are not
vendoring a lockfile that file is skipped without failing the workflow step.
@donoghuc donoghuc force-pushed the bump-ls-version-action branch 2 times, most recently from 97eda25 to 0c6def8 Compare August 27, 2025 23:08
@donoghuc donoghuc force-pushed the bump-ls-version-action branch from 0c6def8 to 1292374 Compare August 27, 2025 23:09
@donoghuc
Copy link
Member Author

This was tested with #18050 and produced a PR with a version bump! Ready for review.

@donoghuc donoghuc marked this pull request as ready for review August 27, 2025 23:10
@donoghuc donoghuc requested review from a team as code owners August 27, 2025 23:10

- uses: actions/checkout@v4

- name: Create updatecli configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, this snippet should be moved to a static file, then we can easily test the updatecli manifest locally without the need to use the CI.

We use that pattern across different places, for instance, I recently created elastic/elastic-agent#9686

Comment on lines +93 to +123
- name: Configure Git
run: |
git config --global user.email "[email protected]"
git config --global user.name "logstashmachine"

- name: Set branch name
run: |
T=$(date +%s)
echo "BRANCH=bump-logstash-${{ github.event.inputs.logstash_version }}-${T}" >> $GITHUB_ENV

- name: Create branch and commit changes
run: |
git checkout -b $BRANCH
git add -u
git status
if [[ -z $(git status --porcelain) ]]; then echo "No changes. We're done."; exit 0; fi
git commit -m "Bump loggstash version: ${{ github.event.inputs.logstash_version }}" -a
git push origin $BRANCH

- name: Create Pull Request
run: |
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-X POST \
-d "{
\"title\": \"Bump logstash version: ${{ github.event.inputs.logstash_version }}\",
\"head\": \"${BRANCH}\",
\"base\": \"${{ github.ref_name }}\",
\"body\": \"Automated update of logstash versions to ${{ github.event.inputs.logstash_version }}\"
}" \
https://api.github.com/repos/${{ github.repository }}/pulls

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updatecli does care about creating PRs automatically, see https://www.updatecli.io/docs/plugins/actions/github/

In a nutshell:

  1. Pass the logstash version using an env variable in the GH action
  2. Read the env variable in the updatecli manifest.
  3. Create a PR automatically with the changes
---
name: Update logstash version

scms:
  default:
    kind: github
    spec:
      user: '{{ requiredEnv "GITHUB_ACTOR" }}'
      username: '{{ requiredEnv "GITHUB_ACTOR" }}'
      owner: '{{ .scm.owner }}'
      repository: '{{ .scm.repository }}'
      token: '{{ requiredEnv "GITHUB_TOKEN" }}'
      branch: '{{ requiredEnv "BRANCH_NAME" }}'
      commitusingapi: true
      force: false

actions:
  default:
    title: 'Bump logstash version {{ requiredEnv "LOGSTASH_VERSION" }}'
    kind: github/pullrequest
    scmid: default
    spec:
      automerge: false
      labels:
      - automation
      description: |-
        ### What
        Update logstash version

targets:
  update_gemfile_lock_dependency:
    name: Update logstash-core dependency
    kind: file
    spec:
      file: Gemfile.jruby-3.1.lock.release
      matchpattern: 'logstash-core \(= [0-9]+\.[0-9]+\.[0-9]+'
      replacepattern: 'logstash-core (= {{ requiredEnv "LOGSTASH_VERSION" }}'
  
  update_gemfile_lock_spec:
    name: Update logstash-core spec
    kind: file
    spec:
      file: Gemfile.jruby-3.1.lock.release
      matchpattern: 'logstash-core \([0-9]+\.[0-9]+\.[0-9]+-java\)'
      replacepattern: 'logstash-core ({{ requiredEnv "LOGSTASH_VERSION" }}-java)'

  update_logstash_version:
    name: Update logstash version in versions.yml
    kind: yaml
    disablesourceinput: true
    spec:
      file: versions.yml
      key: $.logstash
      value: '{{ requiredEnv "LOGSTASH_VERSION" }}'
  
  update_logstash_core_version:
    name: Update logstash-core version in versions.yml
    kind: yaml
    disablesourceinput: true
    spec:
      file: versions.yml
      key: $.logstash-core
      value: '{{ requiredEnv "LOGSTASH_VERSION" }}'

and then use the GH action

---
name: bump-logstash-version

on:
  workflow_dispatch:
  schedule:
    - cron: "0 20 * * 1-6"

permissions:
  contents: read

env:
  JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"

jobs:
  bump:
    permissions:
      contents: write
      pull-requests: write
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - uses: elastic/oblt-actions/updatecli/run@v1
        with:
          command: apply --config updatecli/updatecli-bump-logstash.yml --values .ci/updatecli/values.d/scm.yml
          version-file: .updatecli-version
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_BRANCH: "main"
          LOGSTASH_VERSION: "${{ github.event.inputs.logstash_version }}"

      - if: ${{ failure()  }}
        uses: elastic/oblt-actions/slack/send@v1
        with:
          bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
          channel-id: "CHANGEME"
          message: ":traffic_cone: updatecli failed for `${{ github.repository }}@${{ github.ref_name }}`, @CHANGEME please look what's going on <${{ env.JOB_URL }}|here>"

You can create also the scm file

scm:
  enabled: true
  owner: elastic
  repository: logstash
  commitusingapi: true
  # begin updatecli-compose policy values
  user: 'github-actions[bot]'
  email: '41898282+github-actions[bot]@users.noreply.github.com'
  # end updatecli-compose policy values

and finally you can test locally:

$ export GITHUB_TOKEN=$(gh auth token)
$ export GITHUB_ACTOR=v1v
$ export LOGSTASH_VERSION=main
$ export LOGSTASH_VERSION=1.2.3
$ updatecli diff \
    --config updatecli/updatecli-bump-logstash.yml \
    --values updatecli/values.d/scm.yml

# Apply changes (requires write access to elastic-agent repo)
updatecli apply \
    --config updatecli/updatecli-bump-logstash.yml \
    --values updatecli/values.d/scm.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants