mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-05-06 06:57:56 +00:00
f549a6b031
The helps to remove special casing from actions and will make future LLVM updates smoother.
122 lines
4.2 KiB
YAML
122 lines
4.2 KiB
YAML
# 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 LLVM release."
|
|
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 releases = [];
|
|
|
|
let target = process.env.target
|
|
let versionPrefix = process.env.version_prefix
|
|
|
|
do {
|
|
const res = await github.rest.repos.listReleases({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
per_page: 50,
|
|
page,
|
|
});
|
|
|
|
releases = res.data
|
|
releases.sort((a, b) => {
|
|
return (a.published_at < b.published_at) ? 1 : ((a.published_at > b.published_at) ? -1 : 0);
|
|
});
|
|
|
|
let llvmRelease;
|
|
if (versionPrefix) {
|
|
// Search for latest release matching the version prefix
|
|
llvmRelease = releases.find(release => {
|
|
return release.tag_name.startsWith(versionPrefix);
|
|
});
|
|
if (llvmRelease) {
|
|
core.info(`Found LLVM release matching prefix '${versionPrefix}': ${llvmRelease.tag_name}`);
|
|
}
|
|
} else {
|
|
// Find latest LLVM release
|
|
llvmRelease = releases.find(release => {
|
|
return release.tag_name.startsWith('llvm-');
|
|
});
|
|
if (llvmRelease) {
|
|
core.info(`Found 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();
|
|
}
|
|
return asset.browser_download_url;
|
|
}
|
|
|
|
page++;
|
|
} while(releases.length > 0);
|
|
|
|
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: |
|
|
curl -sSLo llvm.tar.gz ${{ steps.find.outputs.result }}
|
|
|
|
- name: unpack
|
|
shell: bash
|
|
run: |
|
|
tar -xf llvm.tar.gz
|
|
rm llvm.tar.gz
|