Skip to content

Commit 6f69d8e

Browse files
authored
Add script+workflow to update IREE requirement pins. (#827)
Progress on #760, built off of the work in iree-org/iree-turbine#388. This adds a new workflow that runs once a day to update all pinned IREE versions. I also looked into using Dependabot but found that it struggles with `--find-links`, `--index-url`, and with there being multiple `requirements.txt` files in a repository. While I would love to not need to reinvent this wheel, I do like keeping full control over the process. This PR includes: * A new `build_tools/update_iree_requirement_pins.py` script handles updating the pins in `requirements-iree-pinned.txt` and `shortfin/CMakeLists.txt`. The script also sets some variables in `GITHUB_ENV`. * A new `.github/workflows/update_iree_requirement_pins.yml` workflow runs that script then calls https://github.com/peter-evans/create-pull-request to create or update a pull request if there are local changes after running that script. The commit message and pull request body are constructed using the variables set by the script. Test action run: https://github.com/ScottTodd/shark-ai/actions/runs/12777789320 Test pull request: ScottTodd#1
1 parent 13781bb commit 6f69d8e

File tree

2 files changed

+248
-0
lines changed

2 files changed

+248
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2025 Advanced Micro Devices, Inc.
2+
#
3+
# Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
name: Update IREE requirement pins
8+
9+
on:
10+
workflow_dispatch:
11+
schedule:
12+
# Weekdays at 11:00 AM UTC = 03:00 AM PST / 04:00 AM PDT
13+
- cron: "0 11 * * 1-5"
14+
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
19+
jobs:
20+
update-iree:
21+
if: ${{ github.repository_owner == 'nod-ai' || github.event_name != 'schedule' }}
22+
runs-on: ubuntu-24.04
23+
24+
steps:
25+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
27+
- name: "Setting up Python"
28+
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
29+
with:
30+
python-version: 3.11
31+
32+
# This sets a few environment variables used below.
33+
- name: Update IREE requirement pins
34+
run: build_tools/update_iree_requirement_pins.py
35+
36+
- name: Create or update pull request
37+
if: |
38+
${{ env.CURRENT_IREE_BASE_COMPILER_VERSION }} != ${{ env.LATEST_IREE_BASE_COMPILER_VERSION }} || \
39+
${{ env.CURRENT_IREE_BASE_RUNTIME_VERSION }} != ${{ env.LATEST_IREE_BASE_RUNTIME_VERSION }} || \
40+
${{ env.CURRENT_IREE_TURBINE_VERSION }} != ${{ env.LATEST_IREE_TURBINE_VERSION }}
41+
${{ env.CURRENT_SHORTFIN_IREE_GIT_TAG }} != ${{ env.LATEST_SHORTFIN_IREE_GIT_TAG }}
42+
uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f # v7.0.6
43+
with:
44+
base: main
45+
branch: integrates/iree
46+
delete-branch: true
47+
signoff: true
48+
title: "Bump IREE requirement pins to their latest versions."
49+
body: |
50+
Diff: https://github.com/iree-org/iree/compare/iree-${{ env.CURRENT_IREE_BASE_COMPILER_VERSION }}...iree-${{ env.LATEST_IREE_BASE_COMPILER_VERSION }}
51+
52+
Auto-generated by GitHub Actions using [`.github/workflows/update_iree_requirement_pins.yml`](https://github.com/${{ github.repository }}/blob/main/.github/workflows/update_iree_requirement_pins.yml).
53+
commit-message: "Bump IREE to ${{ env.LATEST_IREE_BASE_COMPILER_VERSION }}."
+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2025 Advanced Micro Devices, Inc.
4+
#
5+
# Licensed under the Apache License v2.0 with LLVM Exceptions.
6+
# See https://llvm.org/LICENSE.txt for license information.
7+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
9+
"""Updates the pinned IREE versions in this repository.
10+
11+
Usage:
12+
update_iree_requirement_pins.py
13+
14+
Environment variable outputs (via GITHUB_ENV) for GitHub Actions:
15+
CURRENT_IREE_BASE_COMPILER_VERSION
16+
CURRENT_IREE_BASE_RUNTIME_VERSION
17+
CURRENT_IREE_TURBINE_VERSION
18+
LATEST_IREE_BASE_COMPILER_VERSION
19+
LATEST_IREE_BASE_RUNTIME_VERSION
20+
LATEST_IREE_TURBINE_VERSION
21+
"""
22+
23+
from pathlib import Path
24+
import os
25+
import re
26+
import subprocess
27+
import sys
28+
import textwrap
29+
30+
REPO_ROOT = Path(__file__).parent.parent
31+
REQUIREMENTS_IREE_PINNED_PATH = REPO_ROOT / "requirements-iree-pinned.txt"
32+
SHORTFIN_CMAKELISTS_PATH = REPO_ROOT / "shortfin" / "CMakeLists.txt"
33+
34+
35+
def get_current_version(package_name):
36+
with open(REQUIREMENTS_IREE_PINNED_PATH, "r") as f:
37+
text = f.read()
38+
return re.findall(f"{package_name}==(.*)", text)[0]
39+
40+
41+
def get_latest_version(package_name, extra_pip_args=[]):
42+
print("\n-------------------------------------------------------------------------")
43+
print(f"Finding latest available package version for package '{package_name}'\n")
44+
45+
# This queries the pip index to get the latest version.
46+
#
47+
# This doesn't require downloading or installing, so it should be more
48+
# portable across operating systems than other approaches.
49+
#
50+
# Note: the `index` subcommand is experimental. We could instead:
51+
# * Install (into a venv) then check what was installed with `--report`,
52+
# `pip freeze`, or regex parsing (as in `get_current_version()` above)
53+
# * Download then check what was downloaded
54+
# * Scrape the package index and/or release page (https://iree.dev/pip-release-links.html)
55+
subprocess_args = [
56+
sys.executable,
57+
"-m",
58+
"pip",
59+
"index",
60+
"versions",
61+
package_name,
62+
"--disable-pip-version-check",
63+
]
64+
subprocess_args.extend(extra_pip_args)
65+
66+
print(f"Running command:\n {subprocess.list2cmdline(subprocess_args)}\n")
67+
result = subprocess.run(subprocess_args, stdout=subprocess.PIPE)
68+
output = result.stdout.decode("utf-8")
69+
print(f"Command output:\n{textwrap.indent(output, ' ')}")
70+
71+
# Search for text like `iree-base-compiler (3.2.0rc20250109)` within the
72+
# multiple lines of output from the command.
73+
# WARNING: The output from `pip index` is UNSTABLE and UNSTRUCTURED, but
74+
# this seems to work using Python 3.11.2 and pip 22.3.1.
75+
version_search_regex = re.compile(f"{package_name}\s\((.*)\)")
76+
matches = version_search_regex.match(output)
77+
if not matches:
78+
raise RuntimeError("Failed to find a package version using regex")
79+
version = matches.groups()[0]
80+
print(
81+
f"Found package version for '{package_name}' in output using regex: '{version}'"
82+
)
83+
return version
84+
85+
86+
def get_current_git_tag():
87+
with open(SHORTFIN_CMAKELISTS_PATH, "r") as f:
88+
text = f.read()
89+
return re.findall('SHORTFIN_IREE_GIT_TAG "(.*)"', text)[0]
90+
91+
92+
def main():
93+
print("Updating IREE version pins!")
94+
95+
current_compiler_version = get_current_version("iree-base-compiler")
96+
current_runtime_version = get_current_version("iree-base-runtime")
97+
current_turbine_version = get_current_version("iree-turbine")
98+
current_git_tag = get_current_git_tag()
99+
100+
nightly_pip_args = [
101+
"--pre",
102+
"--find-links",
103+
"https://iree.dev/pip-release-links.html",
104+
]
105+
latest_compiler_version = get_latest_version("iree-base-compiler", nightly_pip_args)
106+
latest_runtime_version = get_latest_version("iree-base-runtime", nightly_pip_args)
107+
latest_turbine_version = get_latest_version("iree-turbine", nightly_pip_args)
108+
# TODO(scotttodd): Get this from git? It should generally be in sync with
109+
# the python packages and follow a naming convention. If that isn't
110+
# true, such as right after a stable release, then this may break.
111+
latest_git_tag = f"iree-{latest_runtime_version}"
112+
113+
print("\n-------------------------------------------------------------------------")
114+
print("Current versions:")
115+
print(f" iree-base-compiler=={current_compiler_version}")
116+
print(f" iree-base-runtime=={current_runtime_version}")
117+
print(f" iree-turbine=={current_turbine_version}")
118+
print(f' SHORTFIN_IREE_GIT_TAG "{current_git_tag}"')
119+
print("Latest versions:")
120+
print(f" iree-base-compiler=={latest_compiler_version}")
121+
print(f" iree-base-runtime=={latest_runtime_version}")
122+
print(f" iree-turbine=={latest_turbine_version}")
123+
print(f' SHORTFIN_IREE_GIT_TAG "{latest_git_tag}"')
124+
125+
# Write to GitHub Actions environment variables for future steps to use if they want.
126+
github_env = os.getenv("GITHUB_ENV")
127+
if github_env:
128+
with open(github_env, "a") as fh:
129+
print(
130+
f"CURRENT_IREE_BASE_COMPILER_VERSION={current_compiler_version}",
131+
file=fh,
132+
)
133+
print(
134+
f"CURRENT_IREE_BASE_RUNTIME_VERSION={current_runtime_version}", file=fh
135+
)
136+
print(f"CURRENT_IREE_TURBINE_VERSION={current_turbine_version}", file=fh)
137+
print(f"CURRENT_SHORTFIN_IREE_GIT_TAG={current_git_tag}", file=fh)
138+
print(
139+
f"LATEST_IREE_BASE_COMPILER_VERSION={latest_compiler_version}", file=fh
140+
)
141+
print(f"LATEST_IREE_BASE_RUNTIME_VERSION={latest_runtime_version}", file=fh)
142+
print(f"LATEST_IREE_TURBINE_VERSION={latest_turbine_version}", file=fh)
143+
print(f"LATEST_SHORTFIN_IREE_GIT_TAG={latest_git_tag}", file=fh)
144+
145+
if (
146+
current_compiler_version == latest_compiler_version
147+
and current_runtime_version == latest_runtime_version
148+
and current_turbine_version == latest_turbine_version
149+
and current_git_tag == latest_git_tag
150+
):
151+
print("Already using the latest versions, exiting")
152+
return
153+
154+
print("\n-------------------------------------------------------------------------")
155+
print(f"Editing version pins in '{REQUIREMENTS_IREE_PINNED_PATH}'")
156+
with open(REQUIREMENTS_IREE_PINNED_PATH, "r") as f:
157+
text = f.read()
158+
print(f"Original text:\n{textwrap.indent(text, ' ')}\n")
159+
160+
text = re.sub(
161+
"iree-base-compiler==.*",
162+
f"iree-base-compiler=={latest_compiler_version}",
163+
text,
164+
)
165+
text = re.sub(
166+
"iree-base-runtime==.*",
167+
f"iree-base-runtime=={latest_runtime_version}",
168+
text,
169+
)
170+
text = re.sub(
171+
"iree-turbine==.*",
172+
f"iree-turbine=={latest_turbine_version}",
173+
text,
174+
)
175+
print(f"New text:\n{textwrap.indent(text, ' ')}\n")
176+
with open(REQUIREMENTS_IREE_PINNED_PATH, "w") as f:
177+
f.write(text)
178+
179+
print(f"Editing git tag in '{SHORTFIN_CMAKELISTS_PATH}'")
180+
with open(SHORTFIN_CMAKELISTS_PATH, "r") as f:
181+
text = f.read()
182+
text = re.sub(
183+
'SHORTFIN_IREE_GIT_TAG ".*"',
184+
f'SHORTFIN_IREE_GIT_TAG "{latest_git_tag}"',
185+
text,
186+
)
187+
with open(SHORTFIN_CMAKELISTS_PATH, "w") as f:
188+
f.write(text)
189+
190+
print("-------------------------------------------------------------------------")
191+
print("Edits complete")
192+
193+
194+
if __name__ == "__main__":
195+
main()

0 commit comments

Comments
 (0)