-
Notifications
You must be signed in to change notification settings - Fork 3.5k
GH action for updating logstash version #18035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
This pull request does not have a backport label. Could you fix it @donoghuc? 🙏
|
Use of updatecli for dep bumps was based on this comment #17945 (comment) |
To test locally: install updatecli
generate config file:
run
|
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.
410469e
to
2514eec
Compare
97eda25
to
0c6def8
Compare
0c6def8
to
1292374
Compare
This was tested with #18050 and produced a PR with a version bump! Ready for review. |
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: Create updatecli configuration |
There was a problem hiding this comment.
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
- 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 | ||
|
There was a problem hiding this comment.
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:
- Pass the logstash version using an env variable in the GH action
- Read the env variable in the updatecli manifest.
- 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
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