Skip to content

Commit 2ed6af9

Browse files
authored
feat: support PGO file (#77)
* feat: support PGO file * initial attempt to pgo diff * avoid diff * add e2e tests
1 parent 30c1119 commit 2ed6af9

File tree

8 files changed

+156
-0
lines changed

8 files changed

+156
-0
lines changed
514 KB
Binary file not shown.

updatecli-compose.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ policies:
3939
values:
4040
- updatecli/policies/updatecli/version/testdata/values.yaml
4141

42+
- name: Handle apm-managed-service/pgo (e2e tests)
43+
policy: ghcr.io/elastic/oblt-updatecli-policies/apm-managed-service/pgo:latest
44+
values:
45+
- updatecli/policies/apm-managed-service/pgo/testdata/values.yaml
46+
4247
- name: Handle updatecli update
4348
policy: ghcr.io/elastic/oblt-updatecli-policies/updatecli/version:latest
4449
values:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## 0.1.0
4+
5+
* Init policy
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
authors:
2+
- Victor Martinez <[email protected]>
3+
4+
url: "https://github.com/elastic/oblt-updatecli-policies/"
5+
changelog: "https://github.com/elastic/oblt-updatecli-policies/tree/main/updatecli/policies/apm-managed-service/pgo/CHANGELOG.md"
6+
documentation: "https://github.com/elastic/oblt-updatecli-policies/tree/main/updatecli/policies/apm-managed-service/pgo/README.md"
7+
source: "https://github.com/elastic/oblt-updatecli-policies/tree/main/updatecli/policies/apm-managed-service/pgo/"
8+
version: 0.1.0
9+
vendor: Elastic Project
10+
11+
licenses:
12+
- "Apache-2.0 license"
13+
14+
description: |
15+
PGO build in MIS update policy
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# README
2+
3+
This policy updates the PGO file defined in `elastic/apm-managed-service`
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
scm:
2+
enabled: true
3+
owner: elastic
4+
repository: oblt-updatecli-policies
5+
username: obltmachine
6+
branch: main
7+
commitusingapi: true
8+
9+
# use one existing file until the pgo file is in the repository.
10+
pgo_file: pgo.log
11+
pgo_target_path: ./tests/apm-managed-service/pgo
12+
pgo_source_repo: observability-robots-playground
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
# Helpers
3+
# {{ $GitHubRepositoryList := env "GITHUB_REPOSITORY" | split "/"}}
4+
# {{ $GitHubPAT := env "GITHUB_TOKEN"}}
5+
# {{ $GitHubUsername := env "GITHUB_ACTOR"}}
6+
7+
name: '{{ .name }}'
8+
pipelineid: '{{ .pipelineid }}'
9+
10+
sources:
11+
sha:
12+
kind: shell
13+
spec:
14+
command: gh api /repos/{{ default $GitHubRepositoryList._0 .scm.owner }}/{{ .pgo_source_repo}}/commits/main --jq '.sha'
15+
environments:
16+
- name: GITHUB_TOKEN
17+
- name: PATH
18+
pull_request:
19+
kind: shell
20+
dependson:
21+
- sha
22+
spec:
23+
command: gh api /repos/{{ default $GitHubRepositoryList._0 .scm.owner }}/{{ .pgo_source_repo}}/commits/{{ source "sha" }}/pulls --jq '.[].html_url'
24+
environments:
25+
- name: GITHUB_TOKEN
26+
- name: PATH
27+
pgo-file:
28+
kind: shell
29+
scmid: apm-managed-service
30+
dependson:
31+
- sha
32+
spec:
33+
command: tar cvzf {{ requiredEnv "GITHUB_WORKSPACE" }}/pgo.tgz {{ .pgo_file }}
34+
environments:
35+
- name: PATH
36+
workdir: "{{ .pgo_source_path }}"
37+
38+
targets:
39+
pgo:
40+
name: PGO file {{ source "sha" }}
41+
disablesourceinput: true
42+
kind: shell
43+
dependson:
44+
- source#pgo-file
45+
spec:
46+
# git diff helps to print what it changed, If it is empty, then updatecli report a success with no changes applied.
47+
# See https://www.updatecli.io/docs/plugins/resource/shell/#_shell_target
48+
command: 'tar -xzf {{ requiredEnv "GITHUB_WORKSPACE" }}/pgo.tgz && git --no-pager diff'
49+
workdir: "{{ .pgo_target_path }}"
50+
#{{ if or (.scm.enabled) (env "GITHUB_REPOSITORY") }}
51+
scmid: default
52+
# {{ end }}
53+
54+
{{ if or (.scm.enabled) (env "GITHUB_REPOSITORY") }}
55+
scms:
56+
default:
57+
kind: "github"
58+
spec:
59+
# Priority set to the environment variable
60+
user: '{{ default $GitHubUsername .scm.username}}'
61+
owner: '{{ default $GitHubRepositoryList._0 .scm.owner }}'
62+
repository: '{{ default $GitHubRepositoryList._1 .scm.repository}}'
63+
token: '{{ default $GitHubPAT .scm.token }}'
64+
username: '{{ default $GitHubUsername .scm.username }}'
65+
branch: '{{ .scm.branch }}'
66+
#{{ if .scm.commitusingapi }}
67+
commitusingapi: {{ .scm.commitusingapi }}
68+
# {{ end }}
69+
70+
apm-managed-service:
71+
kind: github
72+
spec:
73+
user: '{{ default $GitHubUsername .scm.username }}'
74+
owner: '{{ default $GitHubRepositoryList._0 .scm.owner }}'
75+
repository: '{{ .pgo_source_repo }}'
76+
token: '{{ default $GitHubPAT .scm.token }}'
77+
username: '{{ default $GitHubUsername .scm.username }}'
78+
branch: 'main'
79+
80+
actions:
81+
default:
82+
title: '[Automation] Update default.pgo'
83+
kind: "github/pullrequest"
84+
scmid: default
85+
sourceid: sha
86+
spec:
87+
automerge: {{ .automerge }}
88+
labels:
89+
- dependencies
90+
description: |-
91+
### What
92+
Update default.pgo automatic sync
93+
94+
### Why
95+
*Changeset*
96+
* {{ source "pull_request" }}
97+
* https://github.com/{{ default $GitHubRepositoryList._0 .scm.owner }}/{{ .pgo_source_repo }}/commit/{{ source "sha" }}
98+
99+
{{ end }}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: 'automation: update PGO'
2+
pipelineid: apm-managed-service/pgo
3+
automerge: false
4+
5+
pgo_file: default.pgo
6+
pgo_source_repo: apm-managed-service
7+
pgo_source_path: ./
8+
pgo_target_path: ./
9+
10+
scm:
11+
enabled: false
12+
# owner: v1v
13+
# repository: updatecli-demo
14+
# token: "xxx"
15+
# username: "v1v-bot"
16+
# branch: main
17+
# commitusingapi: false

0 commit comments

Comments
 (0)