Skip to content

Commit 54bc902

Browse files
committed
wip
1 parent 3f493da commit 54bc902

File tree

3 files changed

+71
-16
lines changed

3 files changed

+71
-16
lines changed

.github/workflows/merge-flow.yaml

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ on:
1111
description: Upstream repo path in owner/repo format
1212
required: true
1313
type: string
14+
upstream-version-regex:
15+
description: Regex that the upstream version should match
16+
required: false
17+
default: '^v\d+\.\d+\.\d+$'
18+
type: string
1419
downstream:
1520
description: Downstream repo path in owner/repo format
1621
required: true
@@ -24,6 +29,11 @@ on:
2429
description: Sandbox repo path in owner/repo format. Used as a base to create PR against downstream.
2530
required: true
2631
type: string
32+
sandbox-branch-prefix:
33+
description: Prefix fot the PR branch
34+
required: false
35+
default: 'automated-updates'
36+
type: string
2737
restore-upstream:
2838
description: List of files to be reset using upstream content on merge conflict.
2939
required: false
@@ -44,6 +54,16 @@ on:
4454
required: false
4555
default: ''
4656
type: string
57+
pr-labels:
58+
description: Labels to add to the PR
59+
required: false
60+
default: ''
61+
type: string
62+
pr-title-prefix:
63+
description: Prefix for the PR title
64+
required: false
65+
default: ''
66+
type: string
4767
secrets:
4868
cloner-app-id:
4969
description: Github ID of cloner app
@@ -67,14 +87,12 @@ jobs:
6787
name: Perform merge operation
6888
steps:
6989
- name: Get latest upstream tag
90+
uses: oprypin/find-latest-tag@v1
7091
id: upstream
71-
run: |
72-
UPSTREAM_VERSION=$(curl --fail --silent "https://api.github.com/repos/${{ inputs.upstream }}/releases/latest" | jq -r '.tag_name')
73-
if [ "$UPSTREAM_VERSION" == "" ]; then
74-
echo "upstream-version is invalid" >> "$GITHUB_OUTPUT"
75-
exit 1
76-
fi
77-
echo "release=${UPSTREAM_VERSION}" >> "$GITHUB_OUTPUT"
92+
with:
93+
repository: ${{ inputs.upstream }}
94+
releases-only: true
95+
regex: ${{ inputs.upstream-version-regex }}
7896
- name: Find github org name from repo name
7997
id: org
8098
run: |
@@ -104,13 +122,13 @@ jobs:
104122
id: version
105123
with:
106124
version: ${{ steps.org.outputs.downstream-version }}
107-
compare-to: ${{ steps.upstream.outputs.release }}
125+
compare-to: ${{ steps.upstream.outputs.tag }}
108126
lenient: false # fail if either of the versions cannot be parsed
109127
- name: Check openshift fork status
110128
id: fork-sync
111129
run: |
112130
SEMVER_RESULT="${{ steps.version.outputs.comparison-result }}"
113-
echo "${{ inputs.downstream }}@${{ steps.org.outputs.downstream-version }} ${SEMVER_RESULT} ${{ inputs.upstream }}@${{ steps.upstream.outputs.release }}"
131+
echo "${{ inputs.downstream }}@${{ steps.org.outputs.downstream-version }} ${SEMVER_RESULT} ${{ inputs.upstream }}@${{ steps.upstream.outputs.tag }}"
114132
if [ "${SEMVER_RESULT}" == "<" ]; then
115133
echo "status=outdated" >> $GITHUB_OUTPUT
116134
echo "::notice::downstream outdated"
@@ -134,10 +152,10 @@ jobs:
134152
git config user.email 'github-actions[bot]@users.noreply.github.com'
135153
git config --global core.editor "/bin/true"
136154
git fetch https://github.com/${{ inputs.upstream }} --tags
137-
- name: Merge with upstream ${{ steps.upstream.outputs.release }} tag
155+
- name: Merge with upstream ${{ steps.upstream.outputs.tag }} tag
138156
id: merge
139157
run: |
140-
git merge refs/tags/${{ steps.upstream.outputs.release }} --no-edit || echo 'MERGE_CONFLICT=true' >> $GITHUB_OUTPUT
158+
git merge refs/tags/${{ steps.upstream.outputs.tag }} --no-edit || echo 'MERGE_CONFLICT=true' >> $GITHUB_OUTPUT
141159
- name: Resolve conflict using upstream contents
142160
if: ${{ steps.merge.outputs.MERGE_CONFLICT == 'true' && inputs.restore-upstream != ''}}
143161
run: |
@@ -159,9 +177,9 @@ jobs:
159177
run: git merge --continue
160178
- name: Add VERSION file if not present
161179
run: |
162-
is_version_file_present_upstream=$(git ls-tree ${{ steps.upstream.outputs.release }} | grep VERSION || true)
180+
is_version_file_present_upstream=$(git ls-tree ${{ steps.upstream.outputs.tag }} | grep VERSION || true)
163181
# All tags use the vX.Y.Z format currently.
164-
version_from_tag=$(echo ${{ steps.upstream.outputs.release }} | sed -e "s/^v//")
182+
version_from_tag=$(echo ${{ steps.upstream.outputs.tag }} | sed -e "s/^v//")
165183
# Perform check only if both remotes have the VERSION file.
166184
if [ -n "$is_version_file_present_upstream" ] && [ -f VERSION ]; then
167185
version_from_file=$(cat VERSION)
@@ -224,15 +242,15 @@ jobs:
224242
uses: rhobs/create-pull-request@v3
225243
id: create-pr
226244
with:
227-
title: "[bot] Bump ${{ inputs.downstream }} to ${{ steps.upstream.outputs.release }}"
245+
title: "${{ inputs.pr-title-prefix }}[bot] Bump ${{ inputs.downstream }} to ${{ steps.upstream.outputs.tag }}"
228246
body: |
229247
## Description
230248
This is an automated version bump from CI.
231249
The logs for this run can be found [in the syncbot repo actions](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).
232250
If you wish to perform this manually, execute the following commands from ${{ inputs.downstream }} repo:
233251
```
234252
git fetch https://github.com/${{ inputs.upstream }} --tags
235-
if ! git merge refs/tags/${{ steps.upstream.outputs.release }} --no-edit; then
253+
if ! git merge refs/tags/${{ steps.upstream.outputs.tag }} --no-edit; then
236254
git checkout --theirs ${{ inputs.restore-upstream }}
237255
git checkout --ours ${{ inputs.restore-downstream }}
238256
git add ${{ inputs.restore-upstream }} ${{ inputs.restore-downstream }}
@@ -247,10 +265,11 @@ jobs:
247265
git diff --cached --exit-code || git commit -s -m "[bot] update rh-manifest.txt"
248266
fi
249267
```
268+
labels: ${{ inputs.pr-labels }}
250269
author: 'github-actions[bot]<github-actions[bot]@users.noreply.github.com>'
251270
committer: 'github-actions[bot]<github-actions[bot]@users.noreply.github.com>'
252271
signoff: true
253-
branch: automated-updates-${{ inputs.downstream-branch }}
272+
branch: ${{ inputs.sandbox-branch-prefix }}-${{ inputs.downstream-branch }}
254273
delete-branch: true
255274
token: ${{ steps.pr.outputs.token }}
256275
push-to-fork: ${{ inputs.sandbox }}

.github/workflows/merge-prometheus.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ jobs:
1717
uses: ./.github/workflows/merge-flow.yaml
1818
with:
1919
upstream: prometheus/prometheus
20+
upstream-version-regex: ${{ inputs.upstream-version-regex }}
2021
downstream: openshift/prometheus
2122
sandbox: rhobs/prometheus
23+
sandbox-branch-prefix: ${{ inputs.sandbox-branch-prefix }}
24+
pr-labels: ${{ inputs.pr-labels }}
25+
pr-title-prefix: ${{ inputs.pr-title-prefix }}
2226
restore-upstream: >-
2327
CHANGELOG.md
2428
VERSION
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Prometheus rc versions tester
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 0 * * *' #@daily
7+
pull_request:
8+
paths:
9+
- '.github/workflows/merge-flow.yaml'
10+
- '.github/workflows/merge-prometheus.yaml'
11+
- '.github/workflows/test-prometheus-rc.yaml'
12+
push:
13+
paths:
14+
- '.github/workflows/merge-flow.yaml'
15+
- '.github/workflows/merge-prometheus.yaml'
16+
- '.github/workflows/test-prometheus-rc.yaml'
17+
jobs:
18+
prometheus-test-rc:
19+
uses: ./.github/workflows/merge-prometheus.yaml
20+
with:
21+
upstream-version-regex: '^v\d+\.\d+\.\d+-rc\.\d+$'
22+
sandbox-branch-prefix: automated-tests-rc
23+
# The PRs are only meant to run tests
24+
pr-labels: 'do-not-merge/hold,ok-to-test'
25+
pr-title-prefix: 'FOR TESTS ONLY: '
26+
27+
secrets:
28+
pr-app-id: ${{ secrets.APP_ID }}
29+
pr-app-private-key: ${{ secrets.APP_PRIVATE_KEY }}
30+
cloner-app-id: ${{ secrets.CLONER_APP_ID }}
31+
cloner-app-private-key: ${{ secrets.CLONER_APP_PRIVATE_KEY }}
32+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}

0 commit comments

Comments
 (0)