Skip to content

Add generic DPA profiling tools #17

Add generic DPA profiling tools

Add generic DPA profiling tools #17

Workflow file for this run

name: Release Mod
"on":
push:
branches:
- "**"
paths:
- Directory.Build.props
permissions:
contents: write
jobs:
verify-tag-package-and-release:
if: github.ref_type == 'branch' && github.ref_name == github.event.repository.default_branch
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"
- name: Determine mod metadata
run: |
set -euo pipefail
python3 - <<'PY' >> "$GITHUB_ENV"
import sys
import xml.etree.ElementTree as ET
from pathlib import Path
props = ET.parse("Directory.Build.props")
root = props.getroot()
def read_value(name: str) -> str:
node = root.find(f".//{name}")
return (node.text or "").strip() if node is not None and node.text else ""
mod_name = read_value("ModName")
mod_file_name = read_value("ModFileName")
if not mod_file_name:
raise SystemExit("Directory.Build.props is missing ModFileName.")
candidates = sorted(
path for path in Path(".").rglob(f"{mod_file_name}.csproj")
if "bin" not in path.parts and "obj" not in path.parts
)
if len(candidates) != 1:
names = ", ".join(str(path) for path in candidates) or "none"
raise SystemExit(
f"Expected exactly one project named {mod_file_name}.csproj, found {len(candidates)}: {names}"
)
print(f"MOD_NAME={mod_name or mod_file_name}")
print(f"MOD_FILE_NAME={mod_file_name}")
print(f"MOD_PROJECT={candidates[0].as_posix()}")
PY
- name: Determine release version
run: |
set -euo pipefail
MOD_VERSION="$(dotnet msbuild "$MOD_PROJECT" -nologo -getProperty:Version)"
RELEASE_TAG="v$MOD_VERSION"
echo "MOD_VERSION=$MOD_VERSION" >> "$GITHUB_ENV"
echo "RELEASE_TAG=$RELEASE_TAG" >> "$GITHUB_ENV"
- name: Create or verify release tag
run: |
set -euo pipefail
git fetch --tags --force
if git show-ref --verify --quiet "refs/tags/$RELEASE_TAG"; then
TAG_COMMIT="$(git rev-list -n 1 "$RELEASE_TAG")"
if [ "$TAG_COMMIT" != "$GITHUB_SHA" ]; then
echo "Tag $RELEASE_TAG already exists at $TAG_COMMIT but current commit is $GITHUB_SHA." >&2
echo "Update ModVersion in Directory.Build.props before creating another release." >&2
exit 1
fi
echo "Tag $RELEASE_TAG already points at this commit."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "$RELEASE_TAG" -m "Release $RELEASE_TAG"
git push origin "refs/tags/$RELEASE_TAG"
- name: Build mod
env:
RIMWORLD_MOD_DIR: ""
run: dotnet build "$MOD_PROJECT" -c Release
- name: Package mod zip
run: |
set -euo pipefail
PACKAGE_ROOT="$RUNNER_TEMP/mod-package"
PACKAGE_DIR="$PACKAGE_ROOT/$MOD_FILE_NAME"
STAGE_DIR="dist/$MOD_FILE_NAME"
ARCHIVE_NAME="${MOD_FILE_NAME}.zip"
rm -rf "$PACKAGE_ROOT" dist
mkdir -p dist "$STAGE_DIR"
dotnet build "$MOD_PROJECT" -c Release --no-restore -p:RIMWORLD_MOD_DIR="$PACKAGE_ROOT"
cp -R "$PACKAGE_DIR"/. "$STAGE_DIR"/
(
cd dist
zip -qr "$ARCHIVE_NAME" "$(basename "$STAGE_DIR")"
)
- name: Create GitHub release if needed
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
if ! gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
gh release create \
"$RELEASE_TAG" \
--title "$MOD_NAME $RELEASE_TAG" \
--generate-notes
fi
- name: Upload mod zip to GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
LEGACY_ARCHIVE_NAME="${MOD_FILE_NAME}-${RELEASE_TAG}.zip"
if gh release view "$RELEASE_TAG" --json assets --jq '.assets[].name' | grep -Fxq "$LEGACY_ARCHIVE_NAME"; then
gh release delete-asset "$RELEASE_TAG" "$LEGACY_ARCHIVE_NAME" --yes
fi
gh release upload \
"$RELEASE_TAG" \
"dist/${MOD_FILE_NAME}.zip" \
--clobber