-
Notifications
You must be signed in to change notification settings - Fork 325
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
updatecli: dynamic specs #3497
updatecli: dynamic specs #3497
Conversation
This reverts commit 2844d77.
sourceid: sha | ||
kind: shell | ||
spec: | ||
command: 'tar -xzf {{ requiredEnv "GITHUB_WORKSPACE" }}/gherkin-specs.tgz && git --no-pager diff # required to ignore the sourceid being appended' |
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.
The tricky thing here is to use #
since the value of the sourceid: sha
is appended to the command
and then produce some unexpected output.
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.
I think if you omit the sourceid
option, the value is not appended
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.
I think if you omit the sourceid option, the value is not appended
That was expected, but It was not the case for some reason.
Given
diff --git a/.ci/updatecli/updatecli.d/update-specs.yml b/.ci/updatecli/updatecli.d/update-specs.yml
index 0be8fa56a..ca40c47ef 100644
--- a/.ci/updatecli/updatecli.d/update-specs.yml
+++ b/.ci/updatecli/updatecli.d/update-specs.yml
@@ -77,7 +77,6 @@ targets:
agent-json-schema:
name: APM agent json server schema {{ source "sha" }}
scmid: default
- sourceid: sha
kind: shell
spec:
command: 'tar -xzf {{ requiredEnv "GITHUB_WORKSPACE" }}/json-schema.tgz && git --no-pager diff # required to ignore the sourceid being appended'
When running:
GITHUB_WORKSPACE=/tmp PATH=/opt/homebrew/bin:$PATH GIT_USER="foo" GIT_EMAIL="[email protected]" GITHUB_TOKEN=$(gh auth token) updatecli apply --config .ci/updatecli/updatecli.d/update-specs.yml --values .ci/updatecli/values.yml --push=false --debug
Then it failed with the below error:
+++++++++++
+ PREPARE +
+++++++++++
Loading Pipeline ".ci/updatecli/updatecli.d/update-specs.yml"
ERROR: empty 'sourceid' for target "agent-json-schema"
ERROR: Skipping manifest in position '\x00' from ".ci/updatecli/updatecli.d/update-specs.yml": targets validation error:
wrong updatecli configuration
ERROR: failed loading pipeline(s)
* ".ci/updatecli/updatecli.d/update-specs.yml" - targets validation error:
wrong updatecli configuration
0 pipeline(s) successfully loaded
SCM repository retrieved: 0
++++++++++++++++++
+ AUTO DISCOVERY +
++++++++++++++++++
ERROR: ✗ no valid pipeline found
ERROR: command failed: no valid pipeline found
While if I run this PR as is then:
TARGETS
========
agent-json-schema
-----------------
DEBUG: No shell success criteria defined, updatecli fallbacks to historical workflow
DEBUG: stage: git-checkout
DEBUG: checkout branch "updatecli_update-schema-specs", based on "main" to directory "/var/folders/t7/ghqdh8cx2g12pwb_w0ncmw900000gn/T/updatecli/github/elastic/apm-agent-java"
DEBUG:
DEBUG: branch 'updatecli_update-schema-specs' doesn't exist, creating it from branch 'main'
DEBUG: branch "updatecli_update-schema-specs" successfully created
DEBUG: command: /bin/sh /var/folders/t7/ghqdh8cx2g12pwb_w0ncmw900000gn/T/updatecli/bin/c3007d0e8db2c2ace0ca4104b167b411531c865a1844a662c648deeecede55b8.sh
DEBUG: Environment variables
DEBUG: * UPDATECLI_PIPELINE_STAGE=target
DEBUG: * DRY_RUN=false
The shell 🐚 command "/bin/sh /var/folders/t7/ghqdh8cx2g12pwb_w0ncmw900000gn/T/updatecli/bin/c3007d0e8db2c2ace0ca4104b167b411531c865a1844a662c648deeecede55b8.sh" ran successfully with the following output:
----
----
DEBUG: command stderr output was:
----
----
No change detected
✔ - ran shell command "tar -xzf /tmp/json-schema.tgz && git --no-pager diff # required to ignore the sourceid being appended 80b6af8d97e18344df38968bc5b9588961e89492"
DEBUG: Checking if local changes have been done that should be published
DEBUG: no changes detected between branches "main" and "updatecli_update-schema-specs"
ACTIONS
========
=============================
REPORTS:
✔ update-specs:
Source:
✔ [agent-specs-tarball]
✔ [pull_request]
✔ [sha]
Target:
✔ [agent-json-schema] APM agent json server schema 80b6af8d97e18344df38968bc5b9588961e89492
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.
but according to https://www.updatecli.io/docs/plugins/resource/shell/#_shell_condition:
💡 The source associated to this condition (the default source or through the key sourceID) is appended as the last argument to the command line unless the attribute disablesourceinput is set to true.
diff --git a/.ci/updatecli/updatecli.d/update-specs.yml b/.ci/updatecli/updatecli.d/update-specs.yml
index 0be8fa56a..2b3f34ef8 100644
--- a/.ci/updatecli/updatecli.d/update-specs.yml
+++ b/.ci/updatecli/updatecli.d/update-specs.yml
@@ -77,8 +77,8 @@ targets:
agent-json-schema:
name: APM agent json server schema {{ source "sha" }}
scmid: default
- sourceid: sha
+ disablesourceinput: true
kind: shell
spec:
- command: 'tar -xzf {{ requiredEnv "GITHUB_WORKSPACE" }}/json-schema.tgz && git --no-pager diff # required to ignore the sourceid being appended'
+ command: 'tar -xzf {{ requiredEnv "GITHUB_WORKSPACE" }}/json-schema.tgz && git --no-pager diff'
workdir: "{{ .apm_agent.server_schema_specs_path }}"
worked like a charm, so I missed the disablesourceinput
argument when I tried this in the past. Let me add the change accordingly.
See 8e86691
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.
Ah, right. disablesourceinput
does the magic.
@@ -0,0 +1,14 @@ | |||
github: |
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.
We can easily copy the existing updatecli pipelines in .ci/updatecli.d/*.yml
in each APM Agent repository and change the relevant values in this file
sha: | ||
kind: file | ||
spec: | ||
file: 'https://github.com/{{ .github.owner }}/{{ .github.apm_data_repository }}/commit/{{ .github.branch }}.patch' | ||
matchpattern: "^From\\s([0-9a-f]{40})\\s" | ||
transformers: | ||
- findsubmatch: | ||
pattern: "[0-9a-f]{40}" |
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.
This could be changed to use gh API /repos/{{ .github.owner }}/{{ .github.apm_data_repository }}/commits --jq '.[0].sha'
since it uses the GITHUB_TOKEN
variable
This should help with unexpected failures when anonymously accessing GitHub.
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.
LGTM, I wonder how we could change this ? would introducing few changes in the repo and execute updatecli directly be possible ? If that works then only the trigger when changes are made in the upstream repo would be needed.
What do you mean by changing this?
That's correct; you can use your forked repository to test this and override the diff --git a/.ci/updatecli/values.yml b/.ci/updatecli/values.yml
index 5d1e74685..62d86073a 100644
--- a/.ci/updatecli/values.yml
+++ b/.ci/updatecli/values.yml
@@ -1,9 +1,9 @@
github:
- owner: "elastic"
+ owner: "your-gh-avatar"
repository: "apm-agent-java"
apm_repository: "apm"
apm_data_repository: "apm-data"
- branch: "main"
+ branch: "your-branch"
specs:
apm_data_path: "input/elasticapm/docs/spec/v2"
apm_json_path: "tests/agents/json-specs" Then you can run this PR locally once you have installed updatecli $ gh pr checkout 3497
$ GITHUB_WORKSPACE=/tmp \
GIT_USER="foo" \
GIT_EMAIL="[email protected]" \
GITHUB_TOKEN=$(gh auth token) \
updatecli apply --config .ci/updatecli/updatecli.d --values .ci/updatecli/values.yml --debug |
sorry, I meant "how we could test this", not change it 🤦 , I'll try the commands you've suggested here by artificially reverting those spec files to an older version. |
no worries :)
👍 Quick one, you can branch off one old release and use that branch name in the |
@elasticmachine run elasticsearch-ci/docs |
Hi @v1v I haven't been able to find time to test this, do you think it's risky to merge it as-is and adjust with follow-up PRs if needed later ? |
It's not risky as far as I can see; if something goes wrong, we will receive a notification in Slack anyway, and we can solve it. I need your 👀 again after refactoring the shell step with a native updatecli support to turn off appending the sha commit; see 8e86691 |
I'm wondering if it would be possible to have the updatecli pipeline in another single place and the values in the respective repos. In case of changes, we would only have to update the pipeline in a single place. I'm aware that having it on the consumer side was the initial idea, but I was still wondering what you think about it. WDYT? |
I thought about it, but we don't need it since there are no new APM Agents that often. Hence, as of today, adding such automation will not provide many benefits, plus the caveats with the support for the cross-project GitHub PR creation. As you mentioned, we used to have a centralised approach in the past, and we moved to a decentralised approach to let teams manage their things. In any case, if, for some reason, we need to change the same workflow again, we could re-evaluate this question and put the required tooling around it. |
What does this PR do?
values.yml
to define the configuration to be used when running theupdatecli apply
, see https://www.updatecli.io/docs/commands/updatecli_apply/#updatecli-applyelastic/apm
andelastic/apm-data
under the different folders.tar
with the shell target.Checklist
Test
I iterated in the existing GitHub action by using the upstream branch:
Locally:
or without pushing any changes
additionally, you can change the org from
elastic
to your own GitHub avatar.