Skip to content

Commit 4834ac8

Browse files
committed
Only create one PR when updating dependencies
1 parent bb18aa6 commit 4834ac8

File tree

2 files changed

+160
-65
lines changed

2 files changed

+160
-65
lines changed

.github/workflows/stackhpc-update-kolla.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
codename: Epoxy
2222
uses: ./.github/workflows/update-dependencies.yml
2323
with:
24-
openstack_version: ${{ matrix.version }}
24+
branch: ${{ matrix.version }}
2525
openstack_codename: ${{ matrix.codename }}
2626
permissions:
2727
contents: write

.github/workflows/update-dependencies.yml

Lines changed: 159 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,92 +3,187 @@ name: Update dependencies
33
on:
44
workflow_call:
55
inputs:
6-
openstack_version:
7-
description: OpenStack version
6+
branch:
7+
description: Branch to update. Must exist in all repositories. e.g. stackhpc/2025.1
88
type: string
99
required: true
1010
openstack_codename:
11-
description: OpenStack codename
11+
description: OpenStack codename e.g. Epoxy
12+
type: string
13+
required: true
14+
workflow_dispatch:
15+
inputs:
16+
branch:
17+
description: Branch to update. Must exist in all repositories. e.g. stackhpc/2025.1
18+
type: string
19+
required: true
20+
openstack_codename:
21+
description: OpenStack codename e.g. Epoxy
1222
type: string
1323
required: true
1424

1525
jobs:
16-
propose_github_release_updates:
26+
propose-dependency-updates:
1727
if: github.repository == 'stackhpc/stackhpc-kayobe-config'
18-
runs-on: ubuntu-22.04
19-
strategy:
20-
matrix:
21-
include:
22-
- key: kolla
23-
path: src/kayobe-config/etc/kayobe/stackhpc.yml
24-
repository: stackhpc/kolla
25-
search_regex: 'stackhpc_kolla_source_version\:.*$'
26-
prefix: 'stackhpc_kolla_source_version\: '
27-
28-
- key: kolla-ansible
29-
path: src/kayobe-config/etc/kayobe/stackhpc.yml
30-
repository: stackhpc/kolla-ansible
31-
search_regex: 'stackhpc_kolla_ansible_source_version\:.*$'
32-
prefix: 'stackhpc_kolla_ansible_source_version\: '
33-
34-
- key: kayobe
35-
path: src/kayobe-config/requirements.txt
36-
repository: stackhpc/kayobe
37-
search_regex: 'kayobe@stackhpc\/.*$'
38-
prefix: 'kayobe@'
28+
runs-on: ubuntu-24.04
3929
permissions:
4030
contents: write
4131
pull-requests: write
42-
name: ${{ matrix.key }}
32+
name: Propose dependency updates
33+
outputs:
34+
kolla-tag: ${{ steps.latest_kolla_tag.outputs.latest_tag || steps.current_kolla_version.outputs.version }}
35+
kolla-ansible-tag: ${{ steps.latest_kolla_ansible_tag.outputs.latest_tag || steps.current_kolla_ansible_version.outputs.version }}
36+
kayobe-tag: ${{ steps.latest_kayobe_tag.outputs.latest_tag || steps.current_kayobe_version.outputs.version }}
4337
steps:
44-
- name: Checkout
38+
- name: Checkout Kayobe-config
4539
uses: actions/checkout@v4
4640
with:
47-
ref: ${{ inputs.openstack_version }}
48-
path: ${{ github.workspace }}/src/kayobe-config
41+
ref: ${{ inputs.branch }}
42+
path: src/kayobe-config
43+
44+
- name: Set sanitised branch name
45+
id: branch_name
46+
run: |
47+
sanitised_name=$(echo "update-dependencies-${{ inputs.branch }}" | tr '/' '-')
48+
echo "name=${sanitised_name}" >> $GITHUB_OUTPUT
49+
50+
- name: Set up branch and Git config
51+
run: |
52+
git checkout -b ${{ steps.branch_name.outputs.name }}
53+
git config user.name "stackhpc-ci"
54+
git config user.email "22933334+stackhpc-ci@users.noreply.github.com"
55+
working-directory: src/kayobe-config
56+
57+
- name: Initialise PR Body
58+
run: |
59+
echo "This PR was created automatically to update dependencies for the ${{ inputs.branch }} release." > pr_body.md
60+
echo "" >> pr_body.md
61+
echo "### Changes" >> pr_body.md
62+
63+
- name: Checkout Kolla repository
64+
uses: actions/checkout@v4
65+
with:
66+
repository: stackhpc/kolla
67+
ref: ${{ inputs.branch }}
68+
fetch-tags: true
69+
path: src/kolla
70+
71+
- name: Get latest Kolla tag
72+
id: latest_kolla_tag
73+
run: echo "latest_tag=$(git describe --tags --abbrev=0 --match stackhpc/\*)" >> $GITHUB_OUTPUT
74+
working-directory: ${{ github.workspace }}/src/kolla
75+
76+
- name: Get current Kolla version
77+
id: current_kolla_version
78+
run: |
79+
VERSION=$(awk -F': ' '/stackhpc_kolla_source_version:/ {print $2}' src/kayobe-config/etc/kayobe/stackhpc.yml | xargs)
80+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
4981
50-
- name: Checkout the dependency repo
82+
- name: Update and commit Kolla version if needed
83+
if: steps.latest_kolla_tag.outputs.latest_tag != steps.current_kolla_version.outputs.version
84+
run: |
85+
sed -i "s/stackhpc_kolla_source_version\:.*$/stackhpc_kolla_source_version\: $(echo $TAG | sed 's/\//\\\//g')/g" etc/kayobe/stackhpc.yml
86+
echo "- **Kolla** bumped from \`${{ steps.current_kolla_version.outputs.version }}\` to \`${{ steps.latest_kolla_tag.outputs.latest_tag }}\`" >> ../../pr_body.md
87+
echo " - Changelog: https://github.com/stackhpc/kolla/releases/tag/${{ steps.latest_kolla_tag.outputs.latest_tag }}" >> ../../pr_body.md
88+
git add etc/kayobe/stackhpc.yml
89+
git commit -m "(automated) Bump kolla to ${{ steps.latest_kolla_tag.outputs.latest_tag }}"
90+
env:
91+
TAG: ${{ steps.latest_kolla_tag.outputs.latest_tag }}
92+
working-directory: src/kayobe-config
93+
94+
- name: Checkout Kolla Ansible repository
5195
uses: actions/checkout@v4
5296
with:
53-
repository: ${{ matrix.repository }}
54-
ref: ${{ inputs.openstack_version }}
97+
repository: stackhpc/kolla-ansible
98+
ref: ${{ inputs.branch }}
5599
fetch-tags: true
56-
path: ${{ github.workspace }}/src/${{ matrix.key }}
100+
path: src/kolla-ansible
57101

58-
- name: Get latest tag
59-
id: latest_tag
102+
- name: Get latest Kolla Ansible tag
103+
id: latest_kolla_ansible_tag
104+
run: echo "latest_tag=$(git describe --tags --abbrev=0 --match stackhpc/\*)" >> $GITHUB_OUTPUT
105+
working-directory: ${{ github.workspace }}/src/kolla-ansible
106+
107+
- name: Get current Kolla Ansible version
108+
id: current_kolla_ansible_version
60109
run: |
61-
TAG=$(git describe --tags --abbrev=0 --match stackhpc/\*)
62-
echo latest_tag=${TAG} >> $GITHUB_OUTPUT
63-
working-directory: ${{ github.workspace }}/src/${{ matrix.key }}
110+
VERSION=$(awk -F': ' '/stackhpc_kolla_ansible_source_version:/ {print $2}' src/kayobe-config/etc/kayobe/stackhpc.yml | xargs)
111+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
64112
65-
- name: Update dependency key
113+
- name: Update and commit Kolla Ansible version if needed
114+
if: steps.latest_kolla_ansible_tag.outputs.latest_tag != steps.current_kolla_ansible_version.outputs.version
66115
run: |
67-
TAG_OVERRIDE=$(echo $TAG | sed 's/\//\\\//g')
68-
sed -i "s/$SEARCH/$PREFIX$TAG_OVERRIDE/g" $REQUIREMENTS
116+
sed -i "s/stackhpc_kolla_ansible_source_version\:.*$/stackhpc_kolla_ansible_source_version\: $(echo $TAG | sed 's/\//\\\//g')/g" etc/kayobe/stackhpc.yml
117+
echo "- **Kolla-Ansible** bumped from \`${{ steps.current_kolla_ansible_version.outputs.version }}\` to \`${{ steps.latest_kolla_ansible_tag.outputs.latest_tag }}\`" >> ../../pr_body.md
118+
echo " - Changelog: https://github.com/stackhpc/kolla-ansible/releases/tag/${{ steps.latest_kolla_ansible_tag.outputs.latest_tag }}" >> ../../pr_body.md
119+
git add etc/kayobe/stackhpc.yml
120+
git commit -m "(automated) Bump kolla-ansible to ${{ steps.latest_kolla_ansible_tag.outputs.latest_tag }}"
69121
env:
70-
PREFIX: ${{ matrix.prefix }}
71-
TAG: ${{ steps.latest_tag.outputs.latest_tag }}
72-
REQUIREMENTS: ${{ github.workspace }}/${{ matrix.path }}
73-
SEARCH: ${{ matrix.search_regex }}
122+
TAG: ${{ steps.latest_kolla_ansible_tag.outputs.latest_tag }}
123+
working-directory: src/kayobe-config
74124

75-
- name: Propose changes via PR if required
76-
uses: peter-evans/create-pull-request@v7
125+
- name: Checkout Kayobe repository
126+
uses: actions/checkout@v4
77127
with:
78-
path: ${{ github.workspace }}/src/kayobe-config
79-
commit-message: >-
80-
Bump ${{ matrix.key }} to ${{ steps.latest_tag.outputs.latest_tag }}
81-
author: stackhpc-ci <22933334+stackhpc-ci@users.noreply.github.com>
82-
branch: update-dependency/${{ matrix.key }}/${{ inputs.openstack_version }}
83-
delete-branch: true
84-
title: >-
85-
Bump ${{ matrix.key }} to ${{ steps.latest_tag.outputs.latest_tag }}
86-
body: >
87-
This PR was created automatically to update ${{ inputs.openstack_version }}
88-
${{ matrix.key }} to ${{ steps.latest_tag.outputs.latest_tag }}.
89-
90-
GitHub Release Changelog:
91-
https://github.com/stackhpc/${{ matrix.key }}/releases/tag/${{ steps.latest_tag.outputs.latest_tag }}
92-
labels: |
93-
automated
94-
${{ inputs.openstack_codename }}
128+
repository: stackhpc/kayobe
129+
ref: ${{ inputs.branch }}
130+
fetch-tags: true
131+
path: src/kayobe
132+
133+
- name: Get latest Kayobe tag
134+
id: latest_kayobe_tag
135+
run: echo "latest_tag=$(git describe --tags --abbrev=0 --match stackhpc/\*)" >> $GITHUB_OUTPUT
136+
working-directory: ${{ github.workspace }}/src/kayobe
137+
138+
- name: Get current Kayobe version
139+
id: current_kayobe_version
140+
run: |
141+
VERSION=$(grep 'kayobe@stackhpc/' src/kayobe-config/requirements.txt | sed 's/.*@//' | xargs)
142+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
143+
144+
- name: Update and commit Kayobe version if needed
145+
if: steps.latest_kayobe_tag.outputs.latest_tag != steps.current_kayobe_version.outputs.version
146+
run: |
147+
sed -i "s|kayobe@stackhpc/.*$|kayobe@$(echo $TAG | sed 's|/|\\/|g')|g" requirements.txt
148+
echo "- **Kayobe** bumped from \`${{ steps.current_kayobe_version.outputs.version }}\` to \`${{ steps.latest_kayobe_tag.outputs.latest_tag }}\`" >> ../../pr_body.md
149+
echo " - Changelog: https://github.com/stackhpc/kayobe/releases/tag/${{ steps.latest_kayobe_tag.outputs.latest_tag }}" >> ../../pr_body.md
150+
git add requirements.txt
151+
git commit -m "(automated) Bump kayobe to ${{ steps.latest_kayobe_tag.outputs.latest_tag }}"
152+
env:
153+
TAG: ${{ steps.latest_kayobe_tag.outputs.latest_tag }}
154+
working-directory: src/kayobe-config
155+
156+
- name: Check for new commits
157+
id: check_commits
158+
run: |
159+
count=$(git rev-list --count ${{ inputs.branch }}..HEAD)
160+
if [ "$count" -gt 0 ]; then
161+
echo "has_commits=true" >> $GITHUB_OUTPUT
162+
else
163+
echo "has_commits=false" >> $GITHUB_OUTPUT
164+
fi
165+
working-directory: src/kayobe-config
166+
167+
- name: Push commits
168+
if: steps.check_commits.outputs.has_commits == 'true'
169+
run: git push --force origin ${{ steps.branch_name.outputs.name }}
170+
working-directory: src/kayobe-config
171+
172+
- name: Create or Update Pull Request
173+
if: steps.check_commits.outputs.has_commits == 'true'
174+
env:
175+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176+
working-directory: src/kayobe-config
177+
run: |
178+
EXISTING_PR=$(gh pr list --head "${{ steps.branch_name.outputs.name }}" --json number -q '.[0].number')
179+
if [ -n "$EXISTING_PR" ]; then
180+
gh pr close $EXISTING_PR
181+
fi
182+
gh pr create \
183+
--base "${{ inputs.branch }}" \
184+
--head "${{ steps.branch_name.outputs.name }}" \
185+
--title "(automated) Bump dependencies for OpenStack ${{ inputs.branch }}" \
186+
--body-file ../../pr_body.md \
187+
--label "automated" \
188+
--label "${{ inputs.openstack_codename }}"
189+

0 commit comments

Comments
 (0)