Merge pull request #622 from joshuaboniface/unified-build

Add unified build script and bump_version script
This commit is contained in:
Joshua M. Boniface 2019-01-20 13:28:39 -05:00 committed by GitHub
commit 18189644e3
19 changed files with 536 additions and 89 deletions

204
build Executable file
View File

@ -0,0 +1,204 @@
#!/usr/bin/env bash
# build - build Jellyfin binaries or packages
set -o errexit
set -o pipefail
# The list of possible package actions (except 'clean')
declare -a actions=( 'build' 'package' 'sign' 'publish' )
# The list of possible platforms, based on directories under 'deployment/'
declare -a platforms=( $(
find deployment/ -maxdepth 1 -mindepth 1 -type d | sed 's/deployment\///' | sort
) )
# The list of standard dependencies required by all build scripts; individual
# action scripts may specify their own dependencies
declare -a dependencies=( 'tar' 'zip' )
usage() {
echo -e "build - build Jellyfin binaries or packages"
echo -e ""
echo -e "Usage:"
echo -e " $ build --list-platforms"
echo -e " $ build --list-actions <platform>"
echo -e " $ build [-b/--web-branch <web_branch>] <platform> <action>"
echo -e ""
echo -e "The web_branch defaults to the same branch name as the current main branch."
echo -e "To build all platforms, use 'all'."
echo -e "To perform all build actions, use 'all'."
echo -e "Build output files are collected at '../jellyfin-build/<platform>'."
}
# Show usage on stderr with exit 1 on argless
if [[ -z $1 ]]; then
usage >&2
exit 1
fi
# Show usage if -h or --help are specified in the args
if [[ $@ =~ '-h' || $@ =~ '--help' ]]; then
usage
exit 0
fi
# List all available platforms then exit
if [[ $1 == '--list-platforms' ]]; then
echo -e "Available platforms:"
for platform in ${platforms[@]}; do
echo -e " ${platform}"
done
exit 0
fi
# List all available actions for a given platform then exit
if [[ $1 == '--list-actions' ]]; then
platform="$2"
if [[ ! " ${platforms[@]} " =~ " ${platform} " ]]; then
echo "ERROR: Platform ${platform} does not exist."
exit 1
fi
echo -e "Available actions for platform ${platform}:"
for action in ${actions[@]}; do
if [[ -f deployment/${platform}/${action}.sh ]]; then
echo -e " ${action}"
fi
done
exit 0
fi
# Parse branch option
if [[ $1 == '-b' || $1 == '--web-branch' ]]; then
web_branch="$2"
shift 2
else
web_branch="$( git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' )"
fi
# Parse platform option
if [[ -n $1 ]]; then
cli_platform="$1"
shift
else
echo "ERROR: A platform must be specified. Use 'all' to specify all platforms."
exit 1
fi
if [[ ${cli_platform} == 'all' ]]; then
declare -a platform=( ${platforms[@]} )
else
if [[ ! " ${platforms[@]} " =~ " ${cli_platform} " ]]; then
echo "ERROR: Platform ${cli_platform} is invalid. Use the '--list-platforms' option to list available platforms."
exit 1
else
declare -a platform=( "${cli_platform}" )
fi
fi
# Parse action option
if [[ -n $1 ]]; then
cli_action="$1"
shift
else
echo "ERROR: An action must be specified. Use 'all' to specify all actions."
exit 1
fi
if [[ ${cli_action} == 'all' ]]; then
declare -a action=( ${actions[@]} )
else
if [[ ! " ${actions[@]} " =~ " ${cli_action} " ]]; then
echo "ERROR: Action ${cli_action} is invalid. Use the '--list-actions <platform>' option to list available actions."
exit 1
else
declare -a action=( "${cli_action}" )
fi
fi
# Verify required utilities are installed
missing_deps=()
for utility in ${dependencies[@]}; do
if ! which ${utility} &>/dev/null; then
missing_deps+=( ${utility} )
fi
done
# Error if we're missing anything
if [[ ${#missing_deps[@]} -gt 0 ]]; then
echo -e "ERROR: This script requires the following missing utilities:"
for utility in ${missing_deps[@]}; do
echo -e " ${utility}"
done
exit 1
fi
# Parse platform-specific dependencies
for target_platform in ${platform[@]}; do
# Read platform-specific dependencies
if [[ -f deployment/${target_platform}/dependencies.txt ]]; then
platform_dependencies="$( grep -v '^#' deployment/${target_platform}/dependencies.txt )"
# Verify required utilities are installed
missing_deps=()
for utility in ${platform_dependencies[@]}; do
if ! which ${utility} &>/dev/null; then
missing_deps+=( ${utility} )
fi
done
# Error if we're missing anything
if [[ ${#missing_deps[@]} -gt 0 ]]; then
echo -e "ERROR: The ${target_platform} platform requires the following utilities:"
for utility in ${missing_deps[@]}; do
echo -e " ${utility}"
done
exit 1
fi
fi
done
# Initialize submodules
git submodule update --init --recursive
# configure branch
pushd MediaBrowser.WebDashboard/jellyfin-web
if ! git diff-index --quiet HEAD --; then
popd
echo
echo "ERROR: Your 'jellyfin-web' submodule working directory is not clean!"
echo "This script will overwrite your unstaged and unpushed changes."
echo "Please do development on 'jellyfin-web' outside of the submodule."
exit 1
fi
git fetch --all
git checkout origin/${web_branch} || {
echo "ERROR: 'jellyfin-web' branch ${web_branch} is invalid."
exit 1
}
popd
# Execute each platform and action in order, if said action is enabled
pushd deployment/
for target_platform in ${platform[@]}; do
echo -e "> Processing platform ${target_platform}"
pushd ${target_platform}
for target_action in ${action[@]}; do
echo -e ">> Processing action ${target_action}"
if [[ -f ${target_action}.sh && -x ${target_action}.sh ]]; then
./${target_action}.sh
fi
done
if [[ -d pkg-dist/ ]]; then
echo -e ">> Collecting build artifacts"
target_dir="../../../jellyfin-build/${target_platform}"
mkdir -p ${target_dir}
mv pkg-dist/* ${target_dir}/
echo -e ">> Processing action clean"
if [[ -f clean.sh && -x clean.sh ]]; then
./clean.sh
fi
fi
popd
done
popd

199
bump_version Executable file
View File

@ -0,0 +1,199 @@
#!/usr/bin/env bash
# bump_version - increase the shared version and generate changelogs
set -o errexit
set -o pipefail
usage() {
echo -e "bump_version - increase the shared version and generate changelogs"
echo -e ""
echo -e "Usage:"
echo -e " $ bump_version [-b/--web-branch <web_branch>] <new_version>"
echo -e ""
echo -e "The web_branch defaults to the same branch name as the current main branch."
echo -e "This helps facilitate releases where both branches would be called release-X.Y.Z"
echo -e "and would already be created before running this script."
}
if [[ -z $1 ]]; then
usage
exit 1
fi
shared_version_file="./SharedVersion.cs"
# Parse branch option
if [[ $1 == '-b' || $1 == '--web-branch' ]]; then
web_branch="$2"
shift 2
else
web_branch="$( git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' )"
fi
# Initialize submodules
git submodule update --init --recursive
# configure branch
pushd MediaBrowser.WebDashboard/jellyfin-web
if ! git diff-index --quiet HEAD --; then
popd
echo
echo "ERROR: Your 'jellyfin-web' submodule working directory is not clean!"
echo "This script will overwrite your unstaged and unpushed changes."
echo "Please do development on 'jellyfin-web' outside of the submodule."
exit 1
fi
git fetch --all
git checkout origin/${web_branch} || {
echo "ERROR: 'jellyfin-web' branch ${web_branch} is invalid."
exit 1
}
popd
new_version="$1"
# Parse the version from the AssemblyVersion
old_version="$(
grep "AssemblyVersion" ${shared_version_file} \
| sed -E 's/\[assembly: ?AssemblyVersion\("([0-9\.]+)"\)\]/\1/' \
| sed -E 's/.0$//'
)"
# Set the shared version to the specified new_version
old_version_sed="$( sed 's/\./\\./g' <<<"${old_version}" )" # Escape the '.' chars
sed -i "s/${old_version_sed}/${new_version}/g" ${shared_version_file}
declare -a pr_merges_since_last_master
declare changelog_string_github
declare changelog_string_deb
declare changelog_string_yum
# Build up a changelog from merge commits
for repo in ./ MediaBrowser.WebDashboard/jellyfin-web/; do
last_master_merge_commit=""
pr_merges_since_last_master=()
git_show_details=""
pull_request_id=""
pull_request_description=""
changelog_strings_repo_github=""
changelog_strings_repo_deb=""
changelog_strings_repo_yum=""
case $repo in
*jellyfin-web*)
repo_name="jellyfin-web"
;;
*)
repo_name="jellyfin"
;;
esac
pushd ${repo}
# Find the last release commit, so we know what's happened since
last_master_branch="master-${old_version}" # TODO: Set to `release-` for next release, so we can properly parse both repos with the new branch standard
last_master_merge_commit="$(
git log --merges --pretty=oneline \
| grep -F "${last_master_branch}" \
| awk '{ print $1 }' \
|| true # Don't die here with errexit
)"
if [[ -z ${last_master_merge_commit} ]]; then
# This repo has no last proper commit, so just skip it
popd
continue
fi
# Get all the PR merge commits since the last master merge commit in `jellyfin`
pr_merges_since_last_master+=( $(
git log --merges --pretty=oneline ${last_master_merge_commit}..HEAD \
| grep -F "Merge pull request" \
| awk '{ print $1 }'
) )
for commit_hash in ${pr_merges_since_last_master[@]}; do
git_show_details="$( git show ${commit_hash} )"
pull_request_id="$(
awk '
/Merge pull request/{ print $4 }
{ next }
' <<<"${git_show_details}"
)"
pull_request_description="$(
awk '
/^[a-zA-Z]/{ next }
/^ Merge/{ next }
/^$/{ next }
{ print $0 }
' <<<"${git_show_details}"
)"
pull_request_description="$( sed ':a;N;$!ba;s/\n//g; s/ \+//g' <<<"${pull_request_description}" )"
changelog_strings_repo_github="${changelog_strings_repo_github}\n* ${pull_request_id}: ${pull_request_description}"
changelog_strings_repo_deb="${changelog_strings_repo_deb}\n * $( sed 's/#/PR/' <<<"${pull_request_id}" ) ${pull_request_description}"
changelog_strings_repo_yum="${changelog_strings_repo_yum}\n- $( sed 's/#/PR/' <<<"${pull_request_id}" ) ${pull_request_description}"
done
changelog_string_github="${changelog_string_github}\n#### ${repo_name}:\n$( echo -e "${changelog_strings_repo_github}" | sort -nk2 )\n"
changelog_string_deb="${changelog_string_deb}\n * ${repo_name}:$( echo -e "${changelog_strings_repo_deb}" | sort -nk2 )"
changelog_string_yum="${changelog_string_yum}\n- ${repo_name}:$( echo -e "${changelog_strings_repo_yum}" | sort -nk2 )"
popd
done
# Write out a temporary Debian changelog with our new stuff appended and some templated formatting
debian_changelog_file="deployment/debian-package-x64/pkg-src/changelog"
debian_changelog_temp="$( mktemp )"
# Create new temp file with our changelog
echo -e "### DEBIAN PACKAGE CHANGELOG: Verify this file looks correct or edit accordingly, then delete this line, write, and exit.
jellyfin (${new_version}-1) unstable; urgency=medium
${changelog_string_deb}
-- Jellyfin Packaging Team <packaging@jellyfin.org> $( date --rfc-2822 )
" >> ${debian_changelog_temp}
cat ${debian_changelog_file} >> ${debian_changelog_temp}
# Edit the file to verify
$EDITOR ${debian_changelog_temp}
# Move into place
mv ${debian_changelog_temp} ${debian_changelog_file}
# Clean up
rm -f ${debian_changelog_temp}
# Write out a temporary Yum changelog with our new stuff prepended and some templated formatting
fedora_spec_file="deployment/fedora-package-x64/pkg-src/jellyfin.spec"
fedora_changelog_temp="$( mktemp )"
fedora_spec_temp_dir="$( mktemp -d )"
fedora_spec_temp="${fedora_spec_temp_dir}/jellyfin.spec.tmp"
# Make a copy of our spec file for hacking
cp ${fedora_spec_file} ${fedora_spec_temp_dir}/
pushd ${fedora_spec_temp_dir}
# Split out the stuff before and after changelog
csplit jellyfin.spec "/^%changelog/" # produces xx00 xx01
# Update the version in xx00
sed -i "s/${old_version_sed}/${new_version}/g" xx00
# Remove the header from xx01
sed -i '/^%changelog/d' xx01
# Create new temp file with our changelog
echo -e "### YUM SPEC CHANGELOG: Verify this file looks correct or edit accordingly, then delete this line, write, and exit.
%changelog
* $( LANG=C date '+%a %b %d %Y' ) Jellyfin Packaging Team <packaging@jellyfin.org>${changelog_string_yum}" >> ${fedora_changelog_temp}
cat xx01 >> ${fedora_changelog_temp}
# Edit the file to verify
$EDITOR ${fedora_changelog_temp}
# Reassembble
cat xx00 ${fedora_changelog_temp} > ${fedora_spec_temp}
popd
# Move into place
mv ${fedora_spec_temp} ${fedora_spec_file}
# Clean up
rm -rf ${fedora_changelog_temp} ${fedora_spec_temp_dir}
# Stage the changed files for commit
git add ${shared_version_file} ${debian_changelog_file} ${fedora_spec_file}
git status
# Write out the GitHub-formatted changelog for the merge request/release pages
echo ""
echo "=== The GitHub-formatted changelog follows ==="
echo -e "${changelog_string_github}"

View File

@ -1,8 +1,111 @@
# Build scripts
# Jellyfin Packaging
All `build.sh` and `package.sh` scripts are for *nix platforms (or WSL on Windows 10).
This directory contains the packaging configuration of Jellyfin for multiple platforms. The specification is below; all package platforms must follow the specification to be compatable with the central `build` script.
After running both, check the `*/pkg-dist/` folders for the archives and packages.
## Package List
### Operating System Packages
* `debian-package-x64`: Package for Debian and Ubuntu amd64 systems.
* `fedora-package-x64`: Package for Fedora, CentOS, and Red Hat Enterprise Linux amd64 systems.
### Portable Builds (archives)
* `debian-x64`: Portable binary archive for Debian amd64 systems.
* `ubuntu-x64`: Portable binary archive for Ubuntu amd64 systems.
* `linux-x64`: Portable binary archive for generic Linux amd64 systems.
* `osx-x64`: Portable binary archive for MacOS amd64 systems.
* `win-x64`: Portable binary archive for Windows amd64 systems.
* `win-x86`: Portable binary archive for Windows i386 systems.
### Other Builds
These builds are not necessarily run from the `build` script, but are present for other platforms.
* `framework`: Compiled `.dll` for use with .NET Core runtime on any system.
* `docker`: Docker manifests for auto-publishing.
* `unraid`: unRaid Docker template; not built by `build` but imported into unRaid directly.
* `win-generic`: Portable binary for generic Windows systems.
## Package Specification
### Dependencies
* If a platform requires additional build dependencies, the required binary names, i.e. to validate `which <binary>`, should be specified in a `dependencies.txt` file inside the platform directory.
* Each dependency should be present on its own line.
### Action Scripts
* Actions are defined in BASH scripts with the name `<action>.sh` within the platform directory.
* The list of valid actions are:
1. `build`: Builds a set of binaries.
2. `package`: Assembles the compiled binaries into a package.
3. `sign`: Performs signing actions on a package.
4. `publish`: Performs a publishing action for a package.
5. `clean`: Cleans up any artifacts from the previous actions.
* All package actions are optional, however at least one should generate output files, and any that do should contain a `clean` action.
* Actions are executed in the order specified above, and later actions may depend on former actions.
* Actions except for `clean` should `set -o errexit` to terminate on failed actions.
* The `clean` action should always `exit 0` even if no work is done or it fails.
### Output Files
* Upon completion of the defined actions, at least one output file must be created in the `<platform>/pkg-dist` directory.
* Output files will be moved to the directory `jellyfin-build/<platform>` one directory above the repository root upon completion.
### Common Functions
* A number of common functions are defined in `deployment/common.build.sh` for use by platform scripts.
* Each action script should import the common functions to define a number of standard variables.
* The common variables are:
* `ROOT`: The Jellyfin repostiory root, usually `../..`.
* `CONFIG`: The .NET config, usually `Release`.
* `DOTNETRUNTIME`: The .NET `--runtime` value, platform-dependent.
* `OUTPUT_DIR`: The intermediate output dir, usually `./dist/jellyfin_${VERSION}`.
* `BUILD_CONTEXT`: The Docker build context, usually `../..`.
* `DOCKERFILE`: The Dockerfile, usually `Dockerfile` in the platform directory.
* `IMAGE_TAG`: A tag for the built Docker image.
* `PKG_DIR`: The final binary output directory for collection, invariably `pkg-dist`.
* `ARCHIVE_CMD`: The compression/archive command for release archives, usually `tar -xvzf` or `zip`.
#### `get_version`
Reads the version information from `SharedVersion.cs`.
**Arguments:** `ROOT`
#### `build_jellyfin`
Build a standard self-contained binary in the current OS context.
**Arguments:** `ROOT` `CONFIG` `DOTNETRUNTIME` `OUTPUT_DIR`
#### `build_jellyfin_docker`
Build a standard self-contained binary in a Docker image.
**Arguments:** `BUILD_CONTEXT` `DOCKERFILE` `IMAGE_TAG`
#### `clean_jellyfin`
Clean up a build for housekeeping.
**Arguments:** `ROOT` `CONFIG` `OUTPUT_DIR` `PKG_DIR`
#### `package_portable`
Produce a compressed archive.
**Arguments:** `ROOT` `OUTPUT_DIR` `PKG_DIR` `ARCHIVE_CMD`
`build_all.sh` will invoke every build and package script.
Use `collect_all.sh` to copy all artifact to one directory for easy uploading.

View File

@ -1,21 +0,0 @@
#!/usr/bin/env bash
set -e
# Execute every clean.sh scripts in every folder.
echo "Running for platforms '$@'."
for directory in */ ; do
platform=`basename "${directory}"`
if [[ $@ == *"$platform"* || $@ = *"all"* ]]; then
echo "Processing ${platform}"
pushd "$platform"
if [ -f clean.sh ]; then
echo ./clean.sh
fi
popd
else
echo "Skipping $platform."
fi
done
rm -rf ./collect-dist

View File

@ -1,20 +0,0 @@
#!/usr/bin/env bash
source common.build.sh
VERSION=`get_version ..`
COLLECT_DIR="./collect-dist"
mkdir -p ./collect-dist
DIRS=`find . -type d -name "pkg-dist"`
while read directory
do
echo "Collecting everything from '$directory'.."
PLATFORM=$(basename "$(dirname "$directory")")
# Copy all artifacts with extensions tar.gz, deb, exe, zip, rpm and add the platform name to resolve any duplicates.
find $directory \( -name "jellyfin*.tar.gz" -o -name "jellyfin*.deb" -o -name "jellyfin*.rpm" -o -name "jellyfin*.zip" -o -name "jellyfin*.exe" \) -exec sh -c 'cp "$1" "'${COLLECT_DIR}'/jellyfin_'${PLATFORM}'_${1#*jellyfin}"' _ {} \;
done <<< "${DIRS}"

View File

@ -16,6 +16,16 @@ DEFAULT_OUTPUT_DIR="dist/jellyfin-git"
DEFAULT_PKG_DIR="pkg-dist"
DEFAULT_DOCKERFILE="Dockerfile"
DEFAULT_IMAGE_TAG="jellyfin:"`git rev-parse --abbrev-ref HEAD`
DEFAULT_ARCHIVE_CMD="tar -xvzf"
# Parse the version from the AssemblyVersion
get_version()
(
local ROOT=${1-$DEFAULT_ROOT}
grep "AssemblyVersion" ${ROOT}/SharedVersion.cs \
| sed -E 's/\[assembly: ?AssemblyVersion\("([0-9\.]+)"\)\]/\1/' \
| sed -E 's/.0$//'
)
# Run a build
build_jellyfin()
@ -77,19 +87,13 @@ clean_jellyfin()
fi
)
# Parse the version from the AssemblyVersion
get_version()
(
local ROOT=${1-$DEFAULT_ROOT}
grep "AssemblyVersion" ${ROOT}/SharedVersion.cs | sed -E 's/\[assembly: ?AssemblyVersion\("([0-9\.]+)"\)\]/\1/' | sed -E 's/.0$//'
)
# Packages the output folder into an archive.
package_portable()
(
local ROOT=${1-$DEFAULT_ROOT}
local OUTPUT_DIR=${2-$DEFAULT_OUTPUT_DIR}
local PKG_DIR=${3-$DEFAULT_PKG_DIR}
local ARCHIVE_CMD=${4-$DEFAULT_ARCHIVE_CMD}
# Package portable build result
if [ -d ${OUTPUT_DIR} ]; then
echo -e "${CYAN}Packaging build in '${OUTPUT_DIR}' for `basename "${OUTPUT_DIR}"` to '${PKG_DIR}' with root '${ROOT}'.${NC}"

View File

@ -0,0 +1 @@
docker

View File

@ -6,6 +6,8 @@ jellyfin (10.0.2-1) unstable; urgency=medium
* #541: Change ItemId to Guid in ProviderManager
* #566: Avoid printing stacktrace when bind to port 1900 fails
-- Joshua Boniface <joshua@boniface.me> Sat, 19 Jan 2019 01:19:59 -0500
jellyfin (10.0.1-1) unstable; urgency=medium
* Hotfix release, corrects several small bugs from 10.0.0

View File

@ -0,0 +1 @@
dotnet

View File

@ -0,0 +1 @@
docker

View File

@ -0,0 +1 @@
docker

View File

@ -1,13 +1,13 @@
%global debug_package %{nil}
# jellyfin tag to package
%global gittag v10.0.1
%global gittag v10.0.2
# Taglib-sharp commit of the submodule since github archive doesn't include submodules
%global taglib_commit ee5ab21742b71fd1b87ee24895582327e9e04776
%global taglib_shortcommit %(c=%{taglib_commit}; echo ${c:0:7})
AutoReq: no
Name: jellyfin
Version: 10.0.1
Version: 10.0.2
Release: 1%{?dist}
Summary: The Free Software Media Browser
License: GPLv2

View File

@ -0,0 +1 @@
dotnet

View File

@ -1,34 +0,0 @@
#!/usr/bin/env bash
git submodule update --init --recursive
pushd ../Jellyfin.Versioning
./update-version
popd
#TODO enabled proper flag parsing for enabling and disabling building, signing, packaging and publishing
# Execute all build.sh, package.sh, sign.sh and publish.sh scripts in every folder. In that order. Script should check for artifacts themselves.
echo "Running for platforms '$@'."
for directory in */ ; do
platform=`basename "${directory}"`
if [[ $@ == *"$platform"* || $@ = *"all"* ]]; then
echo "Processing ${platform}"
pushd "$platform"
if [ -f build.sh ]; then
./build.sh
fi
if [ -f package.sh ]; then
./package.sh
fi
if [ -f sign.sh ]; then
./sign.sh
fi
if [ -f publish.sh ]; then
./publish.sh
fi
popd
else
echo "Skipping $platform."
fi
done

View File

@ -0,0 +1 @@
dotnet

View File

@ -0,0 +1 @@
dotnet

View File

@ -0,0 +1 @@
dotnet

View File

@ -0,0 +1 @@
dotnet

View File

@ -0,0 +1 @@
dotnet