-
Notifications
You must be signed in to change notification settings - Fork 35
159 lines (136 loc) · 5.04 KB
/
Copy pathc-bindings.yml
File metadata and controls
159 lines (136 loc) · 5.04 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
154
155
156
157
158
159
name: Marmot C Bindings
on:
push:
tags:
- marmotc-v*
permissions:
contents: read
concurrency:
group: marmot-c-bindings-${{ github.ref }}
cancel-in-progress: false
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: "0"
CARGO_PROFILE_RELEASE_DEBUG: "0"
jobs:
linux-bindings:
name: Build Linux C bindings
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Check out repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
persist-credentials: false
- name: Validate release tag
shell: bash
run: |
set -euo pipefail
if [[ ! "$GITHUB_REF_NAME" =~ ^marmotc-v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
echo "error: C binding releases must use a version tag like marmotc-v0.1.0" >&2
exit 1
fi
tag_version="${GITHUB_REF_NAME#marmotc-v}"
workspace_version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)"
if [[ "$tag_version" != "$workspace_version" ]]; then
echo "error: tag version $tag_version does not match workspace version $workspace_version" >&2
exit 1
fi
- name: Install Rust toolchain
shell: bash
run: |
set -euo pipefail
rustup show active-toolchain || rustup toolchain install
# No Cargo cache on this tag-triggered path: these artifacts are
# published to a public GitHub Release, so they are built from a clean
# target directory rather than from a restorable (poisonable) cache.
- name: Build C bindings
shell: bash
run: ./crates/marmot-c/c-bindings.sh
- name: Smoke-test against gcc and clang
shell: bash
run: |
set -euo pipefail
sudo apt-get update
sudo apt-get install -y valgrind
./crates/marmot-c/c-smoke.sh gcc clang
- name: Package bundle
shell: bash
run: |
set -euo pipefail
tag="$GITHUB_REF_NAME"
version="${tag#marmotc-v}"
workspace_version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)"
lock_sha="$(sha256sum Cargo.lock | awk '{print $1}')"
stage_parent="build/marmot-c-stage"
stage="$stage_parent/marmot-c-$version"
asset="marmot-c-linux-x86_64-$version.zip"
rm -rf "$stage_parent" "$asset" "$asset.sha256"
mkdir -p "$stage" dist
cp -R crates/marmot-c/output/. "$stage/"
cp crates/marmot-c/README.md "$stage/"
cat > "$stage/manifest.json" <<EOF
{
"artifact": "marmot-c",
"version": "$version",
"workspace_version": "$workspace_version",
"cargo_lock_sha256": "$lock_sha",
"commit": "$GITHUB_SHA",
"target": "x86_64-unknown-linux-gnu"
}
EOF
(cd "$stage_parent" && zip -r "../../$asset" "marmot-c-$version")
sha256sum "$asset" | awk -v name="$asset" '{print $1 " " name}' > "$asset.sha256"
cp "$asset" "$asset.sha256" dist/
- name: Upload bundle
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: marmot-c-linux
path: dist/
if-no-files-found: error
release:
name: Create GitHub release
runs-on: ubuntu-latest
needs:
- linux-bindings
timeout-minutes: 15
permissions:
actions: read
contents: write
steps:
- name: Download binding artifacts
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
mkdir -p dist
gh run download "$GITHUB_RUN_ID" --repo "$GITHUB_REPOSITORY" --name marmot-c-linux --dir dist
- name: Create or update release
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
tag="$GITHUB_REF_NAME"
version="${tag#marmotc-v}"
notes="$RUNNER_TEMP/release-notes.md"
cat > "$notes" <<EOF
Marmot C bindings generated from MDK commit \`$GITHUB_SHA\`.
Assets:
- \`marmot-c-linux-x86_64-$version.zip\`: \`libmarmot_c.so\` + \`libmarmot_c.a\`, \`marmot.h\`, pkg-config file, README.
Verify downloads with the accompanying \`.sha256\` files.
EOF
assets=(
"dist/marmot-c-linux-x86_64-$version.zip"
"dist/marmot-c-linux-x86_64-$version.zip.sha256"
)
if gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
gh release upload "$tag" "${assets[@]}" --repo "$GITHUB_REPOSITORY" --clobber
gh release edit "$tag" --repo "$GITHUB_REPOSITORY" --title "v$version - Marmot C" --notes-file "$notes"
else
gh release create "$tag" "${assets[@]}" \
--repo "$GITHUB_REPOSITORY" \
--title "v$version - Marmot C" \
--notes-file "$notes"
fi