Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,61 @@ on:
paths:
- 'docs/**'
- 'mkdocs.yml'
- 'docs/requirements.txt'
- '.github/workflows/docs.yml'
pull_request:
paths:
- 'docs/**'
- 'mkdocs.yml'
- 'docs/requirements.txt'
- '.github/workflows/docs.yml'
workflow_dispatch:

permissions:
contents: write
contents: read

jobs:
build:
name: Build site
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6

- uses: actions/setup-python@v6
with:
python-version: '3.x'
cache: pip
cache-dependency-path: docs/requirements.txt

- name: Install MkDocs and theme
run: pip install -r docs/requirements.txt

- name: Strict build (fails on warnings)
run: mkdocs build --strict

deploy:
name: Deploy to GitHub Pages
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
# `mkdocs gh-deploy` pushes to the gh-pages branch.
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
with:
fetch-depth: 0

- uses: actions/setup-python@v5
- uses: actions/setup-python@v6
with:
python-version: '3.x'
cache: pip
cache-dependency-path: docs/requirements.txt

- name: Instalar MkDocs
run: pip install mkdocs-material
- name: Install MkDocs and theme
run: pip install -r docs/requirements.txt

- name: Deploy GitHub Pages
run: mkdocs gh-deploy --force
- name: Deploy
run: mkdocs gh-deploy --force --clean
128 changes: 84 additions & 44 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types: [published, prereleased]

permissions:
contents: write
contents: read

env:
CARGO_TERM_COLOR: always
Expand All @@ -14,73 +14,113 @@ env:
jobs:
build-release:
runs-on: ubuntu-latest
# Needs write access to attach .so/.dll/.inc to the GitHub release
# and to amend the release body with the auto-generated notes.
permissions:
contents: write

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Verify Cargo.toml version matches release tag
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
CARGO_VERSION="$(grep -m1 '^version' Cargo.toml | sed 's/.*= *"\(.*\)"/\1/')"
echo "Release tag: ${GITHUB_REF_NAME} (version=${TAG_VERSION})"
echo "Cargo.toml: ${CARGO_VERSION}"
if [ "${TAG_VERSION}" != "${CARGO_VERSION}" ]; then
echo "::error::Release tag (${GITHUB_REF_NAME}) does not match Cargo.toml version (${CARGO_VERSION})."
echo "::error::Bump Cargo.toml to ${TAG_VERSION} (or retag) and try again."
exit 1
fi

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: i686-unknown-linux-gnu,i686-pc-windows-gnu
targets: i686-unknown-linux-gnu,i686-pc-windows-msvc

- name: Install cross-compilation tools
run: |
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib mingw-w64
sudo apt-get install -y gcc-multilib g++-multilib clang llvm

- name: Install cargo-xwin
run: cargo install cargo-xwin --locked

- name: Cache cargo
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.cache/cargo-xwin
target
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}

- name: Build Linux (i686)
- name: Build Linux (i686, SA-MP + native OMP)
run: cargo build --release --target i686-unknown-linux-gnu

- name: Build Windows (i686)
run: cargo build --release --target i686-pc-windows-gnu
- name: Build Windows (i686 MSVC, SA-MP + native OMP)
run: cargo xwin build --xwin-arch x86 --release --target i686-pc-windows-msvc

- name: Stage release artifacts
run: |
mkdir -p dist
cp "target/i686-unknown-linux-gnu/release/lib${PLUGIN_NAME}.so" "dist/${PLUGIN_NAME}.so"
cp "target/i686-pc-windows-msvc/release/${PLUGIN_NAME}.dll" "dist/${PLUGIN_NAME}.dll"
cp "include/${PLUGIN_NAME}.inc" "dist/${PLUGIN_NAME}.inc"

- name: Package release assets
- name: Generate release notes
run: |
VERSION="${{ github.ref_name }}"
LINUX_SO="target/i686-unknown-linux-gnu/release/lib${PLUGIN_NAME}.so"
WINDOWS_DLL="target/i686-pc-windows-gnu/release/${PLUGIN_NAME}.dll"

# SA:MP Linux — plugins/ + include/
mkdir -p pkg/samp-linux/plugins pkg/samp-linux/include
cp "$LINUX_SO" "pkg/samp-linux/plugins/${PLUGIN_NAME}.so"
cp "include/${PLUGIN_NAME}.inc" "pkg/samp-linux/include/"

# SA:MP Windows — plugins/ + pawno/include/
mkdir -p pkg/samp-windows/plugins pkg/samp-windows/pawno/include
cp "$WINDOWS_DLL" "pkg/samp-windows/plugins/${PLUGIN_NAME}.dll"
cp "include/${PLUGIN_NAME}.inc" "pkg/samp-windows/pawno/include/"

# OMP Linux — plugins/ + qawno/include/
mkdir -p pkg/omp-linux/plugins pkg/omp-linux/qawno/include
cp "$LINUX_SO" "pkg/omp-linux/plugins/${PLUGIN_NAME}.so"
cp "include/${PLUGIN_NAME}.inc" "pkg/omp-linux/qawno/include/"

# OMP Windows — plugins/ + qawno/include/
mkdir -p pkg/omp-windows/plugins pkg/omp-windows/qawno/include
cp "$WINDOWS_DLL" "pkg/omp-windows/plugins/${PLUGIN_NAME}.dll"
cp "include/${PLUGIN_NAME}.inc" "pkg/omp-windows/qawno/include/"

# Compactar
cd pkg
zip -r "../${PLUGIN_NAME}-${VERSION}-linux-samp.zip" samp-linux/
zip -r "../${PLUGIN_NAME}-${VERSION}-windows-samp.zip" samp-windows/
zip -r "../${PLUGIN_NAME}-${VERSION}-linux-omp.zip" omp-linux/
zip -r "../${PLUGIN_NAME}-${VERSION}-windows-omp.zip" omp-windows/
SDK_VERSION="$(grep -oP 'tag\s*=\s*"\Kv[0-9][^"]*' Cargo.toml | head -n1)"
PLUGIN_VERSION="$(grep -m1 '^version' Cargo.toml | sed 's/.*= *"\(.*\)"/\1/')"

# Extract the section for the current version from CHANGELOG.md.
# Format: "## [X.Y.Z] — yyyy/mm/dd" up to the next "## " heading.
CHANGELOG_SECTION=""
if [ -f CHANGELOG.md ]; then
CHANGELOG_SECTION="$(awk -v ver="${PLUGIN_VERSION}" '
$0 ~ "^## \\[" ver "\\]" { capture = 1; next }
capture && /^## / { exit }
capture { print }
' CHANGELOG.md)"
fi

cat > release_body.md <<EOF
## ${PLUGIN_NAME} v${PLUGIN_VERSION}

Built on top of [rust-samp ${SDK_VERSION}](https://github.com/NullSablex/rust-samp/releases/tag/${SDK_VERSION}).

### Artifacts
- \`${PLUGIN_NAME}.so\` — Linux i686 (\`i686-unknown-linux-gnu\`).
- \`${PLUGIN_NAME}.dll\` — Windows i686 (\`i686-pc-windows-msvc\`).
- \`${PLUGIN_NAME}.inc\` — Pawn include, identical file for SA-MP and Open Multiplayer.

### Compatibility
The binaries are **universal**: they run on SA-MP and on Open Multiplayer, on Linux and Windows alike.

- **SA-MP**: register under \`plugins=\` in \`server.cfg\`.
- **Open Multiplayer (native mode, recommended)**: register as a component under \`components\` in \`config.json\`. Loaded via \`ComponentEntryPoint\`, with access to \`ICore\`, \`ITimersComponent\` and the remaining native APIs.
- **Open Multiplayer (legacy mode)**: still supported — register under \`legacy_plugins\` (or the equivalent key in your \`config.json\`) if you prefer the SA-MP compat path over the native component. Same binary, no extra build flags.
EOF

if [ -n "${CHANGELOG_SECTION}" ]; then
{
echo ""
echo "### Changelog"
echo ""
echo "${CHANGELOG_SECTION}"
} >> release_body.md
fi

cat release_body.md

- name: Upload release assets
uses: softprops/action-gh-release@v2
uses: softprops/action-gh-release@v3
with:
body_path: release_body.md
append_body: true
files: |
${{ env.PLUGIN_NAME }}-${{ github.ref_name }}-linux-samp.zip
${{ env.PLUGIN_NAME }}-${{ github.ref_name }}-windows-samp.zip
${{ env.PLUGIN_NAME }}-${{ github.ref_name }}-linux-omp.zip
${{ env.PLUGIN_NAME }}-${{ github.ref_name }}-windows-omp.zip
dist/${{ env.PLUGIN_NAME }}.so
dist/${{ env.PLUGIN_NAME }}.dll
dist/${{ env.PLUGIN_NAME }}.inc
125 changes: 92 additions & 33 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,100 @@ on:
env:
CARGO_TERM_COLOR: always

# Default: read-only. Each job opts in to extra scopes when needed.
permissions:
contents: read

jobs:
build:
name: Build, test, clippy
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6

- name: Install Rust (stable + clippy)
uses: dtolnay/rust-toolchain@stable
with:
targets: i686-unknown-linux-gnu
components: clippy

- name: Install cross-compilation tools
run: |
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib

- uses: Swatinem/rust-cache@v2

- name: Build
run: cargo build --target i686-unknown-linux-gnu --verbose

- name: Test
run: cargo test --target i686-unknown-linux-gnu --verbose

- name: Clippy
run: cargo clippy --target i686-unknown-linux-gnu --all-targets -- -D warnings

fmt:
name: Rustfmt
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: i686-unknown-linux-gnu

- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Build
run: cargo build --verbose

- name: Run tests
run: cargo test --verbose

- name: Run clippy
run: cargo clippy --all-targets -- -D warnings
- uses: actions/checkout@v6
- name: Install Rust (stable + rustfmt)
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: cargo fmt --all -- --check

audit:
name: Security audit
runs-on: ubuntu-latest
# rustsec/audit-check opens issues for new advisories and posts
# review comments on PRs that introduce vulnerable dependencies.
permissions:
contents: read
issues: write
pull-requests: write
checks: write
steps:
- uses: actions/checkout@v6
- uses: rustsec/audit-check@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}

coverage:
name: Coverage (llvm-cov)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6

- name: Install Rust (stable + llvm-tools)
uses: dtolnay/rust-toolchain@stable
with:
targets: i686-unknown-linux-gnu
components: llvm-tools-preview

- name: Install cross-compilation tools
run: |
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib

- uses: Swatinem/rust-cache@v2

- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Generate LCOV report
run: cargo llvm-cov --target i686-unknown-linux-gnu --lcov --output-path lcov.info

- name: Upload coverage artifact
uses: actions/upload-artifact@v7
with:
name: coverage-lcov
path: lcov.info
if-no-files-found: error
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
.claude
CLAUDE.md
/dist
/reference
/reference

# MkDocs
/site
/.venv
__pycache__/
Loading
Loading