136 lines
5.2 KiB
YAML
136 lines
5.2 KiB
YAML
name: Nuget 📦 Distribution
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows:
|
|
- "Build UC2"
|
|
types:
|
|
- completed
|
|
branches:
|
|
- dev
|
|
- master
|
|
|
|
permissions:
|
|
packages: write
|
|
|
|
jobs:
|
|
publish:
|
|
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
runs-on: ubuntu-latest
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: bindings/dotnet/UnicornEngine
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
ref: ${{ github.event.workflow_run.head_branch }}
|
|
|
|
- name: 'Download and extract artifacts'
|
|
uses: actions/github-script@v6
|
|
with:
|
|
script: |
|
|
let fs = require('fs');
|
|
const options = {};
|
|
options.cwd = './bindings/dotnet/UnicornEngine';
|
|
|
|
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
run_id: context.payload.workflow_run.id,
|
|
});
|
|
|
|
let sourceDir = "";
|
|
let sourceFile = "";
|
|
let destDir = "";
|
|
let destFile = "";
|
|
for (const artifact of allArtifacts.data.artifacts) {
|
|
switch(artifact.name) {
|
|
case 'ubuntu-cmake-aarch64.7z':
|
|
sourceDir = "lib/";
|
|
sourceFile = "libunicorn.so.*";
|
|
destDir = "runtimes/linux-arm64/native";
|
|
destFile = "libunicorn.so";
|
|
break;
|
|
case 'ubuntu-cmake-ppc64le.7z':
|
|
sourceDir = "lib/";
|
|
sourceFile = "libunicorn.so.*";
|
|
destDir = "runtimes/linux-ppc64le/native";
|
|
destFile = "libunicorn.so";
|
|
break;
|
|
case 'ubuntu-cmake-shared-x64.7z':
|
|
sourceDir = "lib/";
|
|
sourceFile = "libunicorn.so.*";
|
|
destDir = "runtimes/linux-x64/native";
|
|
destFile = "libunicorn.so";
|
|
break;
|
|
case 'ubuntu-cmake-shared-x86.7z':
|
|
sourceDir = "lib/";
|
|
sourceFile = "libunicorn.so.*";
|
|
destDir = "runtimes/linux-x86/native";
|
|
destFile = "libunicorn.so";
|
|
break;
|
|
case 'macos-cmake-shared-x64.7z':
|
|
sourceDir = "lib/";
|
|
sourceFile = "libunicorn.*.dylib";
|
|
destDir = "runtimes/osx-x64/native";
|
|
destFile = "libunicorn.dylib";
|
|
break;
|
|
case 'windows_msvc64_shared.7z':
|
|
sourceDir = "";
|
|
sourceFile = "unicorn.dll";
|
|
destDir = "runtimes/win-x64/native";
|
|
destFile = "unicorn.dll";
|
|
break;
|
|
case 'windows_msvc32_shared.7z':
|
|
sourceDir = "";
|
|
sourceFile = "unicorn.dll";
|
|
destDir = "runtimes/win-x86/native";
|
|
destFile = "unicorn.dll";
|
|
break;
|
|
default:
|
|
continue;
|
|
}
|
|
console.log(`Creating destination directory: ${destDir}`);
|
|
await exec.exec("mkdir", ["-p", destDir], options);
|
|
|
|
console.log(`Downloading artifact: ${artifact.name}.zip`);
|
|
let download = await github.rest.actions.downloadArtifact({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
artifact_id: artifact.id,
|
|
archive_format: 'zip',
|
|
});
|
|
fs.writeFileSync(`/tmp/${artifact.name}.zip`, Buffer.from(download.data));
|
|
|
|
console.log(`Unzipping: /tmp/${artifact.name}.zip`);
|
|
await exec.exec("unzip", [`/tmp/${artifact.name}.zip`]);
|
|
console.log(`Extracting library from 7z file to: ${destDir}${sourceFile}`);
|
|
await exec.exec("7z", ["e", "-o", destDir, `/tmp/${artifact.name}`, `${sourceDir}${sourceFile}`], options);
|
|
if (sourceFile != destFile) {
|
|
console.log(`Renaming library to: ${destFile}`);
|
|
await exec.exec("mv", [`${destDir}/${sourceFile}`, `${destDir}/${destFile}`], options);
|
|
}
|
|
}
|
|
|
|
- name: Get short sha
|
|
id: git_short_sha
|
|
run: echo "result=$(git rev-parse --short "${{ github.event.workflow_run.head_sha }}")" >> $GITHUB_OUTPUT
|
|
|
|
- uses: actions/setup-dotnet@v3
|
|
with:
|
|
dotnet-version: 6.0.x
|
|
|
|
- name: Authenticate to Github Packages
|
|
run: dotnet nuget add source --username "${{ github.repository_owner }}" --password "${{ secrets.GITHUB_TOKEN }}" --store-password-in-clear-text --name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
|
|
|
|
- name: Package .NET bindings
|
|
run: |
|
|
[[ "${{ github.event.workflow_run.head_branch }}" == "master" ]] \
|
|
&& dotnet pack -c Release \
|
|
|| dotnet pack -c Release --version-suffix="${{ steps.git_short_sha.outputs.result }}"
|
|
|
|
- name: 📦 Publish to Github Packages
|
|
run: dotnet nuget push "bin/Release/UnicornEngine.Unicorn.*.nupkg" --source "github" --api-key "${{ secrets.GHPR_TOKEN }}"
|