-
Notifications
You must be signed in to change notification settings - Fork 231
143 lines (119 loc) · 5.11 KB
/
Copy pathobs-release.yml
File metadata and controls
143 lines (119 loc) · 5.11 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
name: Release to OBS
on:
workflow_call:
workflow_dispatch:
permissions:
contents: read
jobs:
release-obs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Get version
id: version
run: |
# Extract version by removing 'v' prefix if it exists, fallback to Cargo.toml
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
# Read the binary's [package] version, not [workspace.package] (the
# latter is the 0.x library version and comes first in Cargo.toml).
VERSION=$(awk -F'"' '/^\[package\]/{p=1} p && /^version = /{print $2; exit}' Cargo.toml)
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Setup Linux dependencies
uses: ./.github/actions/setup-linux-deps
with:
extra-packages: osc obs-build build-essential
- name: Install Rust
uses: dtolnay/rust-toolchain@stable # unpinned: maintained branch by Rust team member
with:
toolchain: stable
- name: Configure OBS credentials
run: |
cat <<EOF > ~/.oscrc
[general]
apiurl = https://api.opensuse.org
[https://api.opensuse.org]
user = ${{ secrets.OBS_USER }}
pass = ${{ secrets.OBS_PASS }}
EOF
chmod 600 ~/.oscrc
- name: Download source tarball
run: |
VERSION="${{ steps.version.outputs.version }}"
PACKAGE_NAME="rustnet"
# Output filename must match Source0's basename (v%{version}.tar.gz)
# so the offline OBS build can resolve it; the internal dir prefix
# stays rustnet-%{version}/ to match %autosetup -n.
RELEASE_TAG="v${VERSION}"
if git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then
echo "✓ Found release tag: $RELEASE_TAG"
git archive --format=tar --prefix="${PACKAGE_NAME}-${VERSION}/" "$RELEASE_TAG" | gzip > "v${VERSION}.tar.gz"
else
echo "⚠ Release tag $RELEASE_TAG not found, using HEAD"
git archive --format=tar --prefix="${PACKAGE_NAME}-${VERSION}/" HEAD | gzip > "v${VERSION}.tar.gz"
fi
- name: Vendor dependencies
run: |
VERSION="${{ steps.version.outputs.version }}"
PACKAGE_NAME="rustnet"
RELEASE_TAG="v${VERSION}"
mkdir -p build-vendor
if git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then
git archive --format=tar "$RELEASE_TAG" | tar -x -C build-vendor
else
git archive --format=tar HEAD | tar -x -C build-vendor
fi
cd build-vendor
# Capture the source-replacement config that cargo prints. The OBS
# build has no network, so it needs this at .cargo/config.toml to
# resolve crates from the vendored directory instead of crates.io.
mkdir -p .cargo
cargo vendor vendor > .cargo/config.toml
# Clean up static libs to reduce size
find vendor -name "*.a" -delete
find vendor -name "*.lib" -delete
# Bundle .cargo/config.toml alongside vendor/ so `%autosetup -a 1`
# drops both into the source tree for the offline build.
tar --use-compress-program="zstd -T0 -10" -cf ../vendor.tar.zst .cargo vendor
cd ..
rm -rf build-vendor
- name: Prepare and push to OBS
run: |
VERSION="${{ steps.version.outputs.version }}"
OBS_PROJECT="${{ secrets.OBS_PROJECT }}"
OBS_PACKAGE="rustnet"
if [ -z "$OBS_PROJECT" ]; then
echo "::error::OBS_PROJECT secret is not set!"
exit 1
fi
# Checkout OBS project
osc checkout "$OBS_PROJECT" "$OBS_PACKAGE"
cd "$OBS_PROJECT/$OBS_PACKAGE"
# Clean old files
rm -f *.tar.gz *.tar.zst *.spec
# Copy new files
cp ../../v${VERSION}.tar.gz .
cp ../../vendor.tar.zst .
cp ../../rpm/rustnet.spec .
# Update version in spec file
sed -i "s/^Version:.*/Version: $VERSION/" rustnet.spec
# Prepend a changelog entry. OBS has no rpmautospec, so the spec's
# %changelog is empty on SUSE and the changelog lives here instead.
STAMP="$(LC_ALL=C date -u '+%a %b %e %T %Z %Y')"
{
printf -- '-------------------------------------------------------------------\n'
printf '%s - %s@opensuse.org\n\n' "$STAMP" "${{ secrets.OBS_USER }}"
printf -- '- Update to version %s\n\n' "$VERSION"
[ -f rustnet.changes ] && cat rustnet.changes
} > rustnet.changes.new
mv rustnet.changes.new rustnet.changes
# Add new files, remove deleted ones
osc addremove
# Commit to OBS
osc commit -m "Update to version $VERSION"