name: Build Release Artifacts on: release: types: [published] permissions: contents: write actions: read jobs: # Build SDK artifacts build-sdk-artifacts: runs-on: ubuntu-latest timeout-minutes: 60 env: TAG_NAME: ${{ github.event.release.tag_name }} strategy: matrix: sdk: [c] steps: - name: Checkout code uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 with: submodules: true fetch-depth: 0 - name: Create SDK artifact directory run: | mkdir -p sdk-artifact/thru-program-sdk-${{ matrix.sdk }}-${TAG_NAME} - name: Copy SDK-specific files run: | # Copy the entire SDK directory cp -rL sdks/${{ matrix.sdk }}/. sdk-artifact/thru-program-sdk-${{ matrix.sdk }}-${TAG_NAME}/ # Ensure deps.sh and setup.sh are executable chmod +x sdk-artifact/thru-program-sdk-${{ matrix.sdk }}-${TAG_NAME}/deps.sh chmod +x sdk-artifact/thru-program-sdk-${{ matrix.sdk }}-${TAG_NAME}/setup.sh - name: Create tarball run: | cd sdk-artifact tar -czf thru-program-sdk-${{ matrix.sdk }}-${TAG_NAME}.tar.gz thru-program-sdk-${{ matrix.sdk }}-${TAG_NAME}/ cd .. mv sdk-artifact/thru-program-sdk-${{ matrix.sdk }}-${TAG_NAME}.tar.gz . - name: Create zip archive run: | cd sdk-artifact zip -r thru-program-sdk-${{ matrix.sdk }}-${TAG_NAME}.zip thru-program-sdk-${{ matrix.sdk }}-${TAG_NAME}/ cd .. mv sdk-artifact/thru-program-sdk-${{ matrix.sdk }}-${TAG_NAME}.zip . - name: Upload SDK artifacts to release env: GH_TOKEN: ${{ github.token }} run: | gh release upload "${TAG_NAME}" \ thru-program-sdk-${{ matrix.sdk }}-${TAG_NAME}.tar.gz \ thru-program-sdk-${{ matrix.sdk }}-${TAG_NAME}.zip \ --repo "${GITHUB_REPOSITORY}" \ --clobber - name: Upload SDK artifacts to workflow uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 with: name: sdk-${{ matrix.sdk }} path: | thru-program-sdk-${{ matrix.sdk }}-${{ github.event.release.tag_name }}.tar.gz thru-program-sdk-${{ matrix.sdk }}-${{ github.event.release.tag_name }}.zip retention-days: 90 # Build toolchain for Linux and macOS build-toolchain: permissions: contents: write actions: read runs-on: ${{ matrix.os }} timeout-minutes: 120 env: TAG_NAME: ${{ github.event.release.tag_name }} TN_SDK_BINARY_CACHE_DIR: ${{ github.workspace }}/.cache/thru-sdk-binary-cache strategy: fail-fast: false matrix: os: [ubuntu-large, macos-latest-xlarge] include: - os: ubuntu-large asset_platform: Linux-x86_64 - os: macos-latest-xlarge asset_platform: Darwin-arm64 steps: - name: Checkout code uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 with: submodules: true fetch-depth: 0 - name: Compute SDK compiler cache key id: sdk-compiler-cache-key run: | export TN_SDK_DEPS_NO_MAIN=1 source ./sdks/deps.sh echo "hash=$(host_compiler_cache_hash)" >> "$GITHUB_OUTPUT" - name: Cache local SDK binary cache uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5 with: path: .cache/thru-sdk-binary-cache/ key: thru-sdk-binary-${{ runner.os }}-${{ runner.arch }}-${{ steps.sdk-compiler-cache-key.outputs.hash }}-${{ hashFiles('sdks/deps.sh') }} restore-keys: | thru-sdk-binary-${{ runner.os }}-${{ runner.arch }}-${{ steps.sdk-compiler-cache-key.outputs.hash }}- - name: Cache .thru toolchain id: cache-toolchain uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5 with: path: .thru/sdk/toolchain/ key: thru-toolchain-c-${{ runner.os }}-${{ runner.arch }}-${{ steps.sdk-compiler-cache-key.outputs.hash }}-${{ hashFiles('sdks/deps.sh') }} restore-keys: | thru-toolchain-c-${{ runner.os }}-${{ runner.arch }}-${{ steps.sdk-compiler-cache-key.outputs.hash }}- - name: Ensure toolchain dependencies run: | if [[ ! -x "${GITHUB_WORKSPACE}/.thru/sdk/toolchain/bin/riscv64-unknown-elf-gcc" ]] || [[ ! -x "${GITHUB_WORKSPACE}/.thru/sdk/toolchain/bin/riscv64-unknown-elf-g++" ]]; then # apt only on the path that actually installs. deps.sh runs # `apt-get install` under TN_AUTO_INSTALL_PACKAGES=1, and that needs # a fresh index or it 404s on a moved package version -- but it only # runs when the toolchain cache missed. Hoisting the update out of # this branch made every cache-hit job fetch ~11 MB of indexes to # install nothing, and put a stalled mirror (5 x 180s + backoff) # directly on the merge-queue gate. UNTO-1667. if [[ "${RUNNER_OS}" == "Linux" ]]; then .github/scripts/apt-install-with-retry.sh --update-only fi for attempt in 1 2 3; do if TN_AUTO_INSTALL_PACKAGES=1 ./sdks/deps.sh --thru-dir "${GITHUB_WORKSPACE}" fetch check install-c; then break fi if [[ "${attempt}" == 3 ]]; then echo "Failed to install toolchain dependencies after ${attempt} attempts" >&2 exit 1 fi echo "Toolchain dependency install attempt ${attempt} failed; retrying in 10 seconds" >&2 sleep 10 done fi rm -rf "${GITHUB_WORKSPACE}/.thru/sdk/toolchain/git" - name: Verify toolchain installation run: | export PATH="${GITHUB_WORKSPACE}/.thru/sdk/toolchain/bin:${PATH}" echo "${GITHUB_WORKSPACE}/.thru/sdk/toolchain/bin" >> $GITHUB_PATH command -v riscv64-unknown-elf-gcc command -v riscv64-unknown-elf-g++ riscv64-unknown-elf-gcc --version riscv64-unknown-elf-g++ --version - name: Create minimal toolchain package run: | cd ${GITHUB_WORKSPACE}/.thru/sdk/ # Create a minimal toolchain directory with the final archive name mkdir -p thru-toolchain-${{ matrix.asset_platform }}-${TAG_NAME} # Copy only the essential directories for dir in bin include lib libexec picolibc riscv64-unknown-elf share; do if [ -d "toolchain/$dir" ]; then echo "Copying toolchain/$dir..." cp -r "toolchain/$dir" thru-toolchain-${{ matrix.asset_platform }}-${TAG_NAME}/ else echo "Warning: toolchain/$dir not found, skipping" fi done # Display what we're packaging echo "Toolchain package contents:" ls -la thru-toolchain-${{ matrix.asset_platform }}-${TAG_NAME}/ echo "Total size:" du -sh thru-toolchain-${{ matrix.asset_platform }}-${TAG_NAME}/ - name: Package toolchain as tar.gz run: | cd ${GITHUB_WORKSPACE}/.thru/sdk/ tar -czf thru-toolchain-${{ matrix.asset_platform }}-${TAG_NAME}.tar.gz thru-toolchain-${{ matrix.asset_platform }}-${TAG_NAME}/ ls -la thru-toolchain-${{ matrix.asset_platform }}-${TAG_NAME}.tar.gz - name: Upload toolchain artifact to release env: GH_TOKEN: ${{ github.token }} run: | gh release upload "${TAG_NAME}" \ ".thru/sdk/thru-toolchain-${{ matrix.asset_platform }}-${TAG_NAME}.tar.gz" \ --repo "${GITHUB_REPOSITORY}" \ --clobber - name: Upload toolchain artifact to workflow uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 with: name: toolchain-${{ matrix.asset_platform }} path: .thru/sdk/thru-toolchain-${{ matrix.asset_platform }}-${{ github.event.release.tag_name }}.tar.gz retention-days: 90 # Verify the release after every build has reached a terminal state. Each # successful matrix leg uploads independently, so one platform failure does # not suppress artifacts built by the others. verify-release-artifacts: needs: [build-sdk-artifacts, build-toolchain] if: ${{ always() && !cancelled() }} runs-on: ubuntu-latest timeout-minutes: 10 env: TAG_NAME: ${{ github.event.release.tag_name }} steps: - name: Verify expected release artifacts env: GH_TOKEN: ${{ github.token }} run: | assets=$(gh release view "${TAG_NAME}" \ --repo "${GITHUB_REPOSITORY}" \ --json assets \ --jq '.assets[].name') missing=0 for expected in \ "thru-program-sdk-c-${TAG_NAME}.tar.gz" \ "thru-program-sdk-c-${TAG_NAME}.zip" \ "thru-toolchain-Linux-x86_64-${TAG_NAME}.tar.gz" \ "thru-toolchain-Darwin-arm64-${TAG_NAME}.tar.gz"; do if grep -Fxq "${expected}" <<<"${assets}"; then echo "Found ${expected}" else echo "Missing required release artifact: ${expected}" >&2 missing=1 fi done exit "${missing}"