# example: # - uses: ./.github/actions/get-llvm # with: # target: x86_64-unknown-linux-gnu name: "Download LLVM" inputs: target: required: true version: description: "LLVM release version (e.g., 'llvm-18.1.8'). If not specified, uses the latest published LLVM release. To test a specific draft release, use the full name (e.g. 'llvm-21.1.8-revive.0f80912')." required: false default: "" runs: using: "composite" steps: - name: detect llvm version from submodule id: detect-version shell: bash run: | if [ -z "${{ inputs.version }}" ]; then # Get the full version from the LLVM submodule. git submodule update --init --recursive cd llvm # Try to get the most recent tag (e.g., "llvmorg-18.1.8") LLVM_TAG=$(git describe --tags --abbrev=0 2>/dev/null) if [ -n "$LLVM_TAG" ]; then echo "Detected LLVM version from submodule: $LLVM_TAG" # Convert "llvmorg-x.y.z" to "llvm-x.y.z" LLVM_VERSION=$(echo "$LLVM_TAG" | sed 's/^llvmorg-/llvm-/') echo "Detected LLVM version from submodule: $LLVM_VERSION" echo "version_prefix=$LLVM_VERSION" >> $GITHUB_OUTPUT else echo "Could not detect LLVM version from submodule, will use latest release" echo "version_prefix=" >> $GITHUB_OUTPUT fi cd .. else echo "Using explicitly provided version: ${{ inputs.version }}" echo "version_prefix=${{ inputs.version }}" >> $GITHUB_OUTPUT fi - name: find asset id: find uses: actions/github-script@v7 env: target: ${{ inputs.target }} version_prefix: ${{ steps.detect-version.outputs.version_prefix }} with: result-encoding: string script: | let page = 1; let allReleases = []; let target = process.env.target let versionPrefix = process.env.version_prefix // Fetch all releases from all pages core.info('Fetching releases from revive repository...'); let hasMorePages = true; while (hasMorePages) { const res = await github.rest.repos.listReleases({ owner: context.repo.owner, repo: context.repo.repo, per_page: 50, page, }); if (res.data.length > 0) { core.info(`Page ${page}: Fetched ${res.data.length} releases`); allReleases.push(...res.data); page++; } else { hasMorePages = false; } } core.info(`Total releases fetched: ${allReleases.length}`); // Sort all releases by publication date (newest first) allReleases.sort((a, b) => new Date(b.published_at) - new Date(a.published_at)); // Debug: Print all LLVM releases const llvmReleases = allReleases.filter(r => r.tag_name.startsWith('llvm-') && !r.prerelease); core.info(`Found ${llvmReleases.length} LLVM releases in total:`); llvmReleases.forEach(r => { core.info(` - ${r.tag_name} (published: ${r.published_at})`); }); // Find the appropriate LLVM release let llvmRelease; if (versionPrefix) { // Search for latest release matching the version prefix llvmRelease = llvmReleases.find(release => { return release.tag_name.startsWith(versionPrefix); }); if (llvmRelease) { core.info(`Selected LLVM release matching prefix '${versionPrefix}': ${llvmRelease.tag_name}`); } } else { // Find latest LLVM release (first in sorted list) llvmRelease = llvmReleases[0]; if (llvmRelease) { core.info(`Selected latest LLVM version: ${llvmRelease.tag_name}`); } } if (llvmRelease) { let asset = llvmRelease.assets.find(asset => { return asset.name.includes(target); }); if (!asset) { core.setFailed(`Artifact for '${target}' not found in release ${llvmRelease.tag_name} (${llvmRelease.html_url})`); process.exit(); } // Use the API URL (rather than `browser_download_url`) so that // the authorization header is respected for draft releases. return asset.url; } if (versionPrefix) { core.setFailed(`No LLVM releases matching prefix '${versionPrefix}' found! Please check the version.`); } else { core.setFailed(`No LLVM releases found! Please release LLVM before running this workflow.`); } process.exit(); - name: download shell: bash run: | # Pass the authorization token to allow downloading draft release assets. curl -sSLo llvm.tar.gz -H "Authorization: Bearer ${{ github.token }}" -H "Accept: application/octet-stream" ${{ steps.find.outputs.result }} - name: unpack shell: bash run: | tar -xf llvm.tar.gz rm llvm.tar.gz