Enable creating patch releases (#19467)

* Allow to parameterize the build type
* Add documentation on how to create a patch release

Patch releases are _stable_ releases which can be build via the _Oneshot
candidate release_ workflow.

If the build version to produce is not `rc`, no `rcYYYYMMDD` suffix is
appended to the version number. Therefore, the version string printed
via `iree-compiler --version` for a `stable` release differs from a
release candidate which is later promoted to a stable release.

Co-authored-by: Scott Todd <scott.todd0@gmail.com>
diff --git a/.github/workflows/oneshot_candidate_release.yml b/.github/workflows/oneshot_candidate_release.yml
index 94032cf..ee0f305 100644
--- a/.github/workflows/oneshot_candidate_release.yml
+++ b/.github/workflows/oneshot_candidate_release.yml
@@ -2,6 +2,11 @@
 
 on:
   workflow_dispatch:
+    inputs:
+      build_type:
+        description: The type of build version to produce ("stable", "rc", or "dev")
+        type: string
+        default: "rc"
 
 jobs:
   tag_release:
@@ -13,12 +18,29 @@
         with:
           token: ${{ secrets.WRITE_ACCESS_TOKEN }}
 
+      # Compute version suffix based on inputs (default to 'rc')
+      - name: Compute stable version suffix
+        if: ${{ inputs.build_type == 'stable' }}
+        run: |
+          version_suffix=""
+          echo "version_suffix=${version_suffix}" >> $GITHUB_ENV
+      - name: Compute rc version suffix
+        if: ${{ inputs.build_type == 'rc' || inputs.build_type == '' }}
+        run: |
+          version_suffix="$(printf 'rc%(%Y%m%d)T')"
+          echo "version_suffix=${version_suffix}" >> $GITHUB_ENV
+      - name: Compute dev version suffix
+        if: ${{ inputs.build_type == 'dev' }}
+        run: |
+          version_suffix=".dev0+${{ github.sha }}"
+          echo "version_suffix=${version_suffix}" >> $GITHUB_ENV
+
       - name: Compute version
         run: |
           git fetch --depth=1 origin +refs/tags/*:refs/tags/*
 
           # common version + tag
-          package_version="$(python3 build_tools/python_deploy/compute_common_version.py -rc)"
+          package_version="$(python3 build_tools/python_deploy/compute_common_version.py --version-suffix=${version_suffix})"
           tag_name="iree-${package_version}"
           echo "package_version=${package_version}" >> $GITHUB_ENV
           echo "tag_name=${tag_name}" >> $GITHUB_ENV
@@ -28,11 +50,11 @@
           echo "legacy_package_version=${legacy_package_version}" >> $GITHUB_ENV
 
           # iree-base-compiler version
-          compiler_package_version="$(python3 build_tools/python_deploy/compute_local_version.py compiler -rc)"
+          compiler_package_version="$(python3 build_tools/python_deploy/compute_local_version.py compiler --version-suffix=${version_suffix})"
           echo "compiler_package_version=${compiler_package_version}" >> $GITHUB_ENV
 
           # iree-base-runtime version
-          runtime_package_version="$(python3 build_tools/python_deploy/compute_local_version.py runtime -rc)"
+          runtime_package_version="$(python3 build_tools/python_deploy/compute_local_version.py runtime --version-suffix=${version_suffix})"
           echo "runtime_package_version=${runtime_package_version}" >> $GITHUB_ENV
 
       - name: Updating candidate tag
diff --git a/docs/website/docs/developers/general/one-shot-patch.png b/docs/website/docs/developers/general/one-shot-patch.png
new file mode 100644
index 0000000..3379386
--- /dev/null
+++ b/docs/website/docs/developers/general/one-shot-patch.png
Binary files differ
diff --git a/docs/website/docs/developers/general/release-management.md b/docs/website/docs/developers/general/release-management.md
index 89a3710..e568ad9 100644
--- a/docs/website/docs/developers/general/release-management.md
+++ b/docs/website/docs/developers/general/release-management.md
@@ -81,3 +81,37 @@
 
 3. Complete any remaining checkbox items on the release tracking issue then
    close it and open a new one for the next release.
+
+## Creating a patch release
+
+1. Create a new branch.
+
+    Checkout the corresponding stable release and create a branch for the patch release:
+
+    ```shell
+    git checkout iree-3.0.0
+    git checkout -b iree-3.0.1
+    ```
+
+2. Apply and commit the patches.
+
+3. Set the patch level:
+
+    * Adjust `compiler/version.json` if patches are applied to the compiler.
+
+    * Adjust `runtime/version.json` if patches are applied to the runtime.
+
+4. Push all changes to the new branch.
+
+5. Trigger the
+    [_Oneshot candidate release_ workflow](https://github.com/iree-org/iree/actions/workflows/oneshot_candidate_release.yml)
+    to create a release.
+
+    * Select to run the workflow from the patch branch.
+
+    * Set the type of build version to produce to "stable".
+
+        ![one_shot_patch](./one-shot-patch.png)
+
+6. Follow the documentation above to promote to stable.
+   The step to create a new tag can be skipped.