Skip to content

Commit

Permalink
Readd CI
Browse files Browse the repository at this point in the history
  • Loading branch information
OoLunar committed May 24, 2024
1 parent 58b037f commit 4076bf8
Show file tree
Hide file tree
Showing 7 changed files with 572 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/scripts/apple-xcframework.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh

# Set up environment variables
export PREFIX="$(pwd)/libsodium-apple"
export IOS_VERSION_MIN="${IOS_VERSION_MIN-"9.0.0"}"

# Determine number of processors
PROCESSORS=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
PROCESSORS=${PROCESSORS:-3}

# Function to generate Swift module map
swift_module_map() {
cat <<EOF
module Clibsodium {
header "sodium.h"
export *
}
EOF
}

# Function to build for iOS
build_ios() {
SDK="$(xcode-select -p)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"

# Set compiler and linker flags for 64-bit iOS
CFLAGS="-Ofast -arch arm64 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN}"
LDFLAGS="-arch arm64 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN}"

# Configure and build
./configure --host=arm-apple-darwin10 --prefix="${PREFIX}/tmp/ios64" --enable-minimal || exit 1
make -j"${PROCESSORS}" install || exit 1
}

# Create necessary directories
mkdir -p "${PREFIX}/tmp"

# Build for iOS
echo "Building for iOS..."
build_ios

# Add Swift module map
echo "Adding the Clibsodium module map for Swift..."
find "$PREFIX" -name "include" -type d -print | while read -r f; do
swift_module_map >"${f}/module.modulemap"
done

# Bundle iOS targets
echo "Bundling iOS targets..."
mkdir -p "${PREFIX}/ios/lib"
cp -a "${PREFIX}/tmp/ios64/include" "${PREFIX}/ios/"
lipo -create "${PREFIX}/tmp/ios64/lib/libsodium.dylib" -output "${PREFIX}/ios/lib/libsodium.dylib"
echo "Done!"
43 changes: 43 additions & 0 deletions .github/scripts/package-opus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# Create Opus dir
mkdir -p "$WORKSPACE/libs/opus"
cd "$WORKSPACE/libs/opus"

# Clone the repository
git clone https://gitlab.xiph.org/xiph/opus .
git fetch --tags

# Export the latest tag
OPUS_VERSION="$(git describe --tags $(git rev-list --tags --max-count=1))"
echo "OPUS_VERSION=$OPUS_VERSION" >> $GITHUB_ENV

# Checkout the latest tag
git checkout "$OPUS_VERSION"

# Build the library
cmake -S . -B build $COMMAND_ARGS -DOPUS_BUILD_SHARED_LIBRARY=ON -DCMAKE_BUILD_TYPE=Release -Wno-dev
cmake --build build --config Release

EXPORT_DIR="$WORKSPACE/libs/libopus/$RID/native/"

# Do NOT exit on error
set +e

# Check if the output file has changed, since sometimes Git struggles on Windows
cmp --silent build/$FIND_FILE "$EXPORT_DIR/$FILE"
if [ $? -eq 0 ]; then
echo 'No changes detected'
exit 0
fi

# Exit on error
set -e

# Move the output file to the correct location
mkdir -p "$EXPORT_DIR"
rm -f "$EXPORT_DIR/$FILE"
mv build/$FIND_FILE "$EXPORT_DIR/$FILE"

# Delay committing to prevent race conditions
sleep "$(( $JOB_INDEX * 2 ))"
41 changes: 41 additions & 0 deletions .github/scripts/package-sodium.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# Create Sodium dir
mkdir -p "$WORKSPACE/libs/sodium"
cd "$WORKSPACE/libs/sodium"

# Clone the repository
git clone https://github.com/jedisct1/libsodium.git .
git fetch --tags

# Export the latest tag
SODIUM_VERSION="$(git describe --tags $(git rev-list --tags --max-count=1))"
echo "SODIUM_VERSION=$SODIUM_VERSION" >> $GITHUB_ENV

# Checkout the latest tag
git checkout "$SODIUM_VERSION"

# Build the library
$COMMAND
EXPORT_DIR="$WORKSPACE/libs/libsodium/$RID/native/"

# Do NOT exit on error
set +e

# Check if the output file has changed, since sometimes Git struggles on Windows
cmp --silent "$OUTPUT_FILE" "$EXPORT_DIR/$FILE"
if [ $? -eq 0 ]; then
echo 'No changes detected'
exit 0
fi

# Exit on error
set -e

# Move the output file to the correct location
mkdir -p "$EXPORT_DIR"
rm -f "$EXPORT_DIR/$FILE"
mv "$OUTPUT_FILE" "$EXPORT_DIR/$FILE"

# Delay committing to prevent race conditions
sleep "$(( $JOB_INDEX * 2 ))"
91 changes: 91 additions & 0 deletions .github/workflows/build-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Build Commit

on:
push:
paths:
- ".github/workflows/build-commit.yml"
- "src/**"
- "examples/**"
- "libs/**"
- "*.sln"
workflow_dispatch:

env:
DOTNET_NOLOGO: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 1

jobs:
build-commit:
name: Build Commit
runs-on: ubuntu-latest
if: "!contains(format('{0} {1}', github.event.head_commit.message, github.event.pull_request.title), '[ci-skip]')"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8
- name: Build Project
run: dotnet build
package-commit:
name: Package Commit
runs-on: ubuntu-latest
needs: build-commit
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8
- name: Package Project
run: |
NIGHTLY=$(printf "%0*d" 5 ${{ github.run_number }})
dotnet pack -c Release -o build -p:Nightly="$NIGHTLY"
#dotnet nuget push "build/*" --skip-duplicate -k ${{ secrets.NUGET_ORG_API_KEY }} -s https://api.nuget.org/v3/index.json
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: DSharpPlus.VoiceLink-Nightly-${{ github.run_number }}.zip
path: ./build/*
document-commit:
name: Document Commit
runs-on: ubuntu-latest
needs: package-commit
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8
- name: Build Project
run: |
dotnet build
dotnet tool update -g docfx --prerelease
docfx docs/docfx.json
- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v1
with:
path: ./docs/_site/
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
43 changes: 43 additions & 0 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build PR

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
paths:
- ".github/workflows/build-pr.yml"
- "src/**"
- "examples/**"
- "*.sln"
env:
DOTNET_NOLOGO: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 1

jobs:
build-commit:
name: "Build PR #${{ github.event.pull_request.number }}"
runs-on: ubuntu-latest
if: "!contains(format('{0} {1}', github.event.head_commit.message, github.event.pull_request.title), '[ci-skip]')"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8
- name: Build Project
run: dotnet build
- name: Build and Package Project
run: dotnet pack --include-symbols --include-source -o build -p:PR="${{ github.event.pull_request.number }}"
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: DSharpPlus.VoiceLink-PR-${{ github.event.pull_request.number }}
path: ./build/*
Loading

0 comments on commit 4076bf8

Please sign in to comment.