# Copyright Advanced Micro Devices, Inc. # SPDX-License-Identifier: MIT # Reusable Workflow: Build Stage Artifacts # # This workflow builds TheRock stage artifacts for all stages. # Handles both generic stages (compiler-runtime, etc.) and # per-arch stages (math-libs) using conditional logic. # # Artifacts flow between stages via S3 using the artifact_manager.py tool. # # TODO: When kpack splitting is permanently enabled, change fetch commands to use # --generic-only instead of --amdgpu-families for efficiency. Subsequent build # stages only need generic (host) artifacts; device-specific kpacks are not # needed until final packaging. name: Build Stage Artifacts on: workflow_call: inputs: stage_name: type: string required: true description: "Stage name (e.g., compiler-runtime, math-libs)" stage_display_name: type: string required: true description: "Human-readable display name for the job" timeout_minutes: type: number required: true description: "Job timeout in minutes" amdgpu_family: type: string required: false default: "" description: "GPU family for per-arch stages (empty for generic stages)" dist_amdgpu_families: type: string required: true description: "Semicolon-separated list of all GPU families for dist targets" build_variant_cmake_preset: type: string rocm_package_version: type: string required: true description: "ROCm package version string" release_type: description: 'Release type; controls artifact bucket and IAM role' type: string default: ci repository: description: "Repository to checkout. Defaults to github.repository." type: string default: "" ref: description: "Branch, tag, or SHA to checkout. Defaults to the triggering ref." type: string default: "" build_runs_on: description: "Build runner label (selected by configure script with weighted distribution)" type: string default: "azure-windows-scale-rocm" external_repo_config: description: "JSON config for external repo checkout (generated by detect_external_repo_config.py)" type: string default: "" permissions: contents: read jobs: build_stage: name: ${{ inputs.stage_display_name }} runs-on: ${{ inputs.build_runs_on }} timeout-minutes: ${{ inputs.timeout_minutes }} permissions: contents: read id-token: write defaults: run: shell: bash env: STAGE_NAME: ${{ inputs.stage_name }} AMDGPU_FAMILIES: ${{ inputs.amdgpu_family }} BUILD_DIR: B:\build CCACHE_CONFIGPATH: ${{ github.workspace }}/.ccache/ccache.conf CACHE_DIR: ${{ github.workspace }}/.cache TEATIME_FORCE_INTERACTIVE: 0 RELEASE_TYPE: ${{ inputs.release_type }} EXTERNAL_FETCH_SOURCES_ARGS: ${{ inputs.external_repo_config != '' && fromJSON(inputs.external_repo_config).fetch_sources_args || '' }} steps: # Enable git longpaths before checkout (needed for external repos with long paths) - name: Enable git longpaths if: ${{ inputs.external_repo_config != '' }} run: git config --system core.longpaths true - name: Checkout Repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ inputs.repository || github.repository }} ref: ${{ inputs.ref }} - name: Checkout external repository if: ${{ inputs.external_repo_config != '' }} uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ fromJSON(inputs.external_repo_config).repository }} ref: ${{ fromJSON(inputs.external_repo_config).ref }} path: ${{ fromJSON(inputs.external_repo_config).checkout_path }} - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: "3.12" - name: Install python deps run: pip install -r requirements.txt - name: Install requirements run: | choco source disable -n=chocolatey choco source add -n=internal -s http://nexus-service.nexus-ns.svc.cluster.local:8081/repository/choco-group/ --priority=1 choco install --no-progress -y ccache # ninja pinned due to a bug in the 1.13.0 release: # https://github.com/ninja-build/ninja/issues/2616 choco install --no-progress -y ninja --version 1.12.1 choco install --no-progress -y strawberryperl echo "$PATH;C:\Strawberry\c\bin" >> $GITHUB_PATH - uses: iterative/setup-dvc@6c05772f52d19792ed73aedb6c2bf65ec92adebb # v3.0.0 with: version: '3.62.0' # After other installs, so MSVC gets priority in the PATH. - name: Configure MSVC uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 - name: Adjust git config run: | git config --global core.symlinks true git config --global core.longpaths true git config fetch.parallel 10 - name: Runner health status run: | python build_tools/health_status.py - name: Setup ccache run: | python ./build_tools/setup_ccache.py \ --release-type "${{ inputs.release_type }}" \ --dir "$(dirname $CCACHE_CONFIGPATH)" \ --local-path "$CACHE_DIR/ccache" \ --log-dir "${BUILD_DIR}/logs/ccache" # Note: no AWS credentials should be needed here since our CI buckets # all currently have public read access. - name: Fetch inbound artifacts run: | python build_tools/artifact_manager.py fetch \ --run-id="${{ github.run_id }}" \ --stage="${STAGE_NAME}" \ --amdgpu-families="${{ inputs.amdgpu_family }}" \ --output-dir="${BUILD_DIR}" \ --bootstrap - name: Fetch sources timeout-minutes: 30 run: python build_tools/fetch_sources.py --stage ${STAGE_NAME} --jobs 12 --depth 1 ${EXTERNAL_FETCH_SOURCES_ARGS} - name: Get stage configuration id: stage_config run: | python build_tools/configure_stage.py \ --stage=${STAGE_NAME} \ --amdgpu-families="${{ inputs.amdgpu_family }}" \ --dist-amdgpu-families="${{ inputs.dist_amdgpu_families }}" \ --gha-output - name: Install stage python deps if: ${{ steps.stage_config.outputs.pip_install_cmd }} run: pip install ${{ steps.stage_config.outputs.pip_install_cmd }} - name: Configure run: | cmake -B "${BUILD_DIR}" -S . -GNinja \ --preset=${{ inputs.build_variant_cmake_preset }} \ -DTHEROCK_PACKAGE_VERSION=${{ inputs.rocm_package_version }} \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ ${{ inputs.external_repo_config != '' && format('-DTHEROCK_{0}_SOURCE_DIR={1}', fromJSON(inputs.external_repo_config).source_package, fromJSON(inputs.external_repo_config).checkout_path) || '' }} \ ${{ inputs.external_repo_config != '' && fromJSON(inputs.external_repo_config).extra_cmake_options || '' }} \ ${{ steps.stage_config.outputs.cmake_args }} - name: Build stage run: | cmake --build "${BUILD_DIR}" --target stage-${STAGE_NAME} therock-artifacts -- -k 0 - name: Run build tests (Comgr, blocking) if: ${{ !cancelled() && inputs.stage_name == 'compiler-runtime' }} env: TEATIME_FORCE_INTERACTIVE: 1 run: | cmake --build "${BUILD_DIR}" --target therock-build-tests -- -k 0 - name: Report if: ${{ !cancelled() }} run: | echo "CCache Stats:" ccache -s -v echo "Artifacts:" ls -lh "${BUILD_DIR}"/artifacts/*.tar.xz 2>/dev/null || echo "No artifacts found" # TODO(scotttodd): enable once these tests pass # therock-examples-cpp-sdk-user can't find hipsparselt-config.cmake # - name: Test Packaging # run: | # ctest --test-dir ${BUILD_DIR} --output-on-failure - name: Configure AWS credentials for artifact uploads if: ${{ always() }} uses: ./.github/actions/configure_aws_artifacts_credentials with: release_type: ${{ inputs.release_type }} # TODO(#3336): Attempt upload `always()`? # * If some part of the build failed, partial artifacts may be useful for debugging. # * This script fails if `build_dir / "artifacts"` does not exist. That's useful # if the build succeeded but did not produce artifacts. That's _not_ useful # if the workflow failed or was cancelled before the build even started though. - name: Push stage artifacts run: | python build_tools/artifact_manager.py push \ --run-id ${{ github.run_id }} \ --stage="${STAGE_NAME}" \ --build-dir="${BUILD_DIR}" - name: Upload stage logs if: ${{ always() }} run: | python build_tools/github_actions/post_stage_upload.py \ --run-id=${{ github.run_id }} \ --stage="${STAGE_NAME}" \ --build-dir="${BUILD_DIR}" \ --amdgpu-family="${AMDGPU_FAMILIES}"