-
Notifications
You must be signed in to change notification settings - Fork 19
153 lines (119 loc) · 4.65 KB
/
Copy pathrelease-mod.yml
File metadata and controls
153 lines (119 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: "8.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: 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 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: 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