Pin X-code version on mac/bazel tests to prevent flakiness.

See https://github.com/bazelbuild/rules_swift/issues/950 and https://www.smileykeith.com/2021/03/08/locking-xcode-in-bazel/ for more details.

PiperOrigin-RevId: 507609630
diff --git a/.github/BUILD.bazel b/.github/BUILD.bazel
new file mode 100644
index 0000000..98a95d1
--- /dev/null
+++ b/.github/BUILD.bazel
@@ -0,0 +1,27 @@
+# This information is extracted from the MacOS runner specs located at:
+# https://github.com/actions/runner-images/blob/win19/20230129.2/images/macos/macos-12-Readme.md
+xcode_version(
+    name = "version14_2_14C18",
+    version = "14.2.14C18",
+    aliases = ["14C18"],
+    default_ios_sdk_version = "16.2",
+    default_tvos_sdk_version = "16.1",
+    default_macos_sdk_version = "13.1",
+    default_watchos_sdk_version = "9.1",
+)
+
+xcode_version(
+    name = "version14_1_0_14B47b",
+    version = "14.1.0.14B47b",
+    aliases = ["14B47b"],
+    default_ios_sdk_version = "16.1",
+    default_tvos_sdk_version = "16.1",
+    default_macos_sdk_version = "13.0",
+    default_watchos_sdk_version = "9.1",
+)
+
+xcode_config(
+    name = "host_xcodes",
+    versions = [":version14_2_14C18", ":version14_1_0_14B47b"],
+    default = ":version14_1_0_14B47b",
+)
diff --git a/.github/actions/internal/bazel-setup/action.yml b/.github/actions/internal/bazel-setup/action.yml
index c4059b3..eb0951f 100644
--- a/.github/actions/internal/bazel-setup/action.yml
+++ b/.github/actions/internal/bazel-setup/action.yml
@@ -39,6 +39,11 @@
       shell: bash
       run: echo "BAZEL_FLAGS=$BAZEL_FLAGS --enable_runfiles" >> $GITHUB_ENV
 
+    - name: Initialize MacOS-specific Bazel flags
+      if: runner.os == 'macOS'
+      shell: bash
+      run: echo "BAZEL_FLAGS=$BAZEL_FLAGS --xcode_version_config=//.github:host_xcodes" >> $GITHUB_ENV
+
     - name: Configure Bazel caching
       # Skip bazel cache for local act runs due to issue with credential files
       # and nested docker images