-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (124 loc) · 5.31 KB
/
Copy pathrelease.yml
File metadata and controls
147 lines (124 loc) · 5.31 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
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
PLUGIN_NAME: mysql_samp
jobs:
build-release:
runs-on: ubuntu-latest
# Needs write access to create the release and upload .so/.dll/.inc.
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # full history so the generate-notes API can list every commit
- 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-msvc
- name: Install cross-compilation tools
run: |
sudo apt-get update
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@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.cache/cargo-xwin
target
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
- name: Build Linux (i686, SA-MP + native OMP)
run: cargo build --release --target i686-unknown-linux-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: Build release body
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${GITHUB_REF_NAME}"
VERSION="${TAG#v}"
# 1. Curated section from CHANGELOG.md — headlines, migration notes,
# breaking changes. Everything that humans wrote and the API cannot
# infer from PR titles alone.
BODY=$(awk "/^## \[?v?${VERSION}\]?/{found=1; next} found && /^## /{exit} found{print}" CHANGELOG.md)
if [ -z "$BODY" ]; then
BODY="See [CHANGELOG.md](CHANGELOG.md) for details."
fi
# 2. Auto-generated notes — used only to borrow the "New Contributors"
# block and the "Full Changelog" comparison link that GitHub computes
# natively. The "## What's Changed" categorisation produced here is
# dropped on purpose; the CHANGELOG already does that job with more
# context.
AUTO=$(gh api -X POST "repos/${GITHUB_REPOSITORY}/releases/generate-notes" \
-f tag_name="$TAG" \
-q .body 2>/dev/null || echo "")
# Everything from "## New Contributors" onwards already includes the
# "Full Changelog" link as its last line. Fall back to just the link
# if no first-time contributors were detected.
APPENDIX=$(echo "$AUTO" | sed -n '/^## New Contributors$/,$p')
if [ -z "$APPENDIX" ]; then
APPENDIX=$(echo "$AUTO" | grep '^\*\*Full Changelog\*\*' | tail -1)
fi
# 3. Artifact orientation footer — what each downloadable file is,
# plus a pointer to the installation docs. Kept at the bottom so it
# doesn't push the actual release notes below the fold.
FOOTER=$(cat <<EOF
### 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.
The same \`.so\` / \`.dll\` runs on SA-MP and on Open Multiplayer (native component or legacy). Installation paths: see [\`docs/installation.md\`](https://github.com/${GITHUB_REPOSITORY}/blob/master/docs/installation.md).
EOF
)
{
echo "$BODY"
if [ -n "$APPENDIX" ]; then
echo ""
echo "---"
echo ""
echo "$APPENDIX"
fi
echo ""
echo "---"
echo ""
echo "$FOOTER"
} > release_body.md
cat release_body.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
name: ${{ github.ref_name }}
body_path: release_body.md
files: |
dist/${{ env.PLUGIN_NAME }}.so
dist/${{ env.PLUGIN_NAME }}.dll
dist/${{ env.PLUGIN_NAME }}.inc
draft: false
prerelease: false