Private
Public Access
1
0
Files
Kordophone/.gitea/workflows/core-rpm-release.yaml

202 lines
6.2 KiB
YAML

name: Core RPM Release
on:
push:
tags:
- 'release/core/*'
permissions:
code: read
releases: write
packages: write
env:
RPM_DISTRO_NAME: fedora
RPM_DISTRO_VERSION: '43'
jobs:
build-core-rpm-release:
runs-on: ubuntu-latest
container:
image: fedora:43
steps:
# Build inside Fedora so the RPM package repository grouping matches the
# Fedora release we publish to.
- name: Install system dependencies
run: |
set -eu
dnf install -y \
ca-certificates \
curl \
gcc \
gcc-c++ \
git \
make \
nodejs \
openssl-devel \
pkg-config \
python3 \
rpm-build \
sqlite-devel \
dbus-devel \
systemd-devel
dnf clean all
- name: Install Rust toolchain
run: |
set -eu
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
echo "/root/.cargo/bin" >> "$GITHUB_PATH"
- name: Install cargo-generate-rpm
run: cargo install cargo-generate-rpm
- name: Check out repository code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Build Core RPM
working-directory: core
run: make rpm
- name: Prepare release assets
env:
RELEASE_TAG: ${{ github.ref_name }}
RPM_PACKAGE_GROUP: ${{ vars.RPM_PACKAGE_GROUP }}
RPM_DISTRO_NAME: ${{ env.RPM_DISTRO_NAME }}
RPM_DISTRO_VERSION: ${{ env.RPM_DISTRO_VERSION }}
run: |
set -eu
version="${RELEASE_TAG#release/core/}"
if [ -z "$version" ] || [ "$version" = "$RELEASE_TAG" ]; then
echo "Expected tag in the form release/core/{version}, got: $RELEASE_TAG" >&2
exit 1
fi
package_version="$(awk -F ' = ' '
$0 == "[package]" { in_pkg = 1; next }
/^\[/ { in_pkg = 0 }
in_pkg && $1 == "version" {
gsub(/"/, "", $2)
print $2
exit
}
' core/kordophoned/Cargo.toml)"
if [ -z "$package_version" ]; then
echo "Could not determine kordophoned package version from core/kordophoned/Cargo.toml." >&2
exit 1
fi
if [ "$package_version" != "$version" ]; then
echo "Release tag version ($version) does not match kordophoned package version ($package_version)." >&2
exit 1
fi
assets_dir="${{ gitea.workspace }}/release-assets/core"
rpm_dir="${{ gitea.workspace }}/core/target/generate-rpm"
rm -rf "$assets_dir"
mkdir -p "$assets_dir"
if [ -d "$rpm_dir" ]; then
find "$rpm_dir" -maxdepth 1 -type f -name "kordophoned-${version}-*.rpm" \
-exec cp '{}' "$assets_dir/" ';'
fi
if ! find "$assets_dir" -maxdepth 1 -type f -name '*.rpm' | grep -q .; then
echo "No core RPM artifacts were produced." >&2
exit 1
fi
package_group="${RPM_PACKAGE_GROUP:-${RPM_DISTRO_NAME}/${RPM_DISTRO_VERSION}}"
{
printf 'RELEASE_VERSION=%s\n' "$version"
printf 'RELEASE_ASSETS_DIR=%s\n' "$assets_dir"
printf 'RPM_PACKAGE_GROUP=%s\n' "$package_group"
} >> "$GITHUB_ENV"
- name: Upload RPMs to Gitea package registry
env:
GITEA_SERVER_URL: ${{ gitea.server_url }}
GITEA_REPOSITORY_OWNER: ${{ gitea.repository_owner }}
RPM_PACKAGE_GROUP: ${{ env.RPM_PACKAGE_GROUP }}
RPM_PACKAGE_TOKEN: ${{ secrets.RPM_PACKAGE_TOKEN }}
RPM_PACKAGE_USERNAME: ${{ vars.RPM_PACKAGE_USERNAME }}
RELEASE_ASSETS_DIR: ${{ env.RELEASE_ASSETS_DIR }}
run: |
set -eu
owner="${GITEA_REPOSITORY_OWNER}"
package_user="${RPM_PACKAGE_USERNAME:-${GITEA_REPOSITORY_OWNER}}"
token="${RPM_PACKAGE_TOKEN:-}"
group="${RPM_PACKAGE_GROUP:-}"
if [ -z "$owner" ]; then
echo "Could not determine package owner from workflow context." >&2
exit 1
fi
if [ -z "$package_user" ]; then
echo "Missing package upload username. Set repository or organization variable RPM_PACKAGE_USERNAME." >&2
exit 1
fi
if [ -z "$token" ]; then
echo "Missing package upload token. Set repository or organization secret RPM_PACKAGE_TOKEN." >&2
exit 1
fi
upload_url="${GITEA_SERVER_URL%/}/api/packages/${owner}/rpm"
if [ -n "$group" ]; then
upload_url="${upload_url}/${group}"
fi
upload_url="${upload_url}/upload"
found_rpm=0
for rpm in "$RELEASE_ASSETS_DIR"/*.rpm; do
if [ ! -e "$rpm" ] || [ "${rpm##*.}" != "rpm" ]; then
continue
fi
found_rpm=1
http_code="$(curl --silent --show-error \
--write-out '%{http_code}' \
--output /tmp/package-upload-response \
--user "${package_user}:${token}" \
--upload-file "$rpm" \
"$upload_url")"
case "$http_code" in
201)
echo "Uploaded $(basename "$rpm") to the RPM package registry."
;;
409)
echo "Package already exists for $(basename "$rpm"); skipping duplicate upload."
;;
*)
echo "Failed to upload $(basename "$rpm") to $upload_url (HTTP $http_code)." >&2
cat /tmp/package-upload-response >&2 || true
exit 1
;;
esac
done
if [ "$found_rpm" -ne 1 ]; then
echo "No core RPM artifacts were found to upload." >&2
exit 1
fi
- name: Create Gitea release
uses: https://gitea.com/actions/gitea-release-action@v1
with:
name: Kordophoned Core ${{ env.RELEASE_VERSION }}
tag_name: ${{ github.ref_name }}
target_commitish: ${{ github.sha }}
files: |
${{ env.RELEASE_ASSETS_DIR }}/*.rpm