From 0e66017b6f4c0c6c336d3c84a058f093c024269b Mon Sep 17 00:00:00 2001 From: gal20 <71563441+gal20@users.noreply.github.com> Date: Fri, 9 Oct 2020 00:01:44 +0300 Subject: [PATCH] Add Flatpak CI --- .../linux-flatpak/azure-ci-flatpak.env | 8 + .ci/scripts/linux-flatpak/azure-ci.env | 14 + .ci/scripts/linux-flatpak/docker.sh | 58 ++++ .ci/scripts/linux-flatpak/exec.sh | 14 + .ci/scripts/linux-flatpak/finish.sh | 9 + .ci/scripts/linux-flatpak/generate-data.sh | 292 ++++++++++++++++++ .ci/templates/build-flatpak-single.yml | 35 +++ .ci/yuzu-flatpak-step2.yml | 39 +++ 8 files changed, 469 insertions(+) create mode 100644 .ci/scripts/linux-flatpak/azure-ci-flatpak.env create mode 100644 .ci/scripts/linux-flatpak/azure-ci.env create mode 100644 .ci/scripts/linux-flatpak/docker.sh create mode 100644 .ci/scripts/linux-flatpak/exec.sh create mode 100644 .ci/scripts/linux-flatpak/finish.sh create mode 100644 .ci/scripts/linux-flatpak/generate-data.sh create mode 100644 .ci/templates/build-flatpak-single.yml create mode 100644 .ci/yuzu-flatpak-step2.yml diff --git a/.ci/scripts/linux-flatpak/azure-ci-flatpak.env b/.ci/scripts/linux-flatpak/azure-ci-flatpak.env new file mode 100644 index 0000000000..93467a2815 --- /dev/null +++ b/.ci/scripts/linux-flatpak/azure-ci-flatpak.env @@ -0,0 +1,8 @@ +# Flatpak specific environment variables +FLATPAK_ENC_IV +FLATPAK_ENC_K +FLATPAK_GPG_PUBLIC_KEY +FLATPAK_SSH_HOSTNAME +FLATPAK_SSH_PORT +FLATPAK_SSH_PUBLIC_KEY +FLATPAK_SSH_USER diff --git a/.ci/scripts/linux-flatpak/azure-ci.env b/.ci/scripts/linux-flatpak/azure-ci.env new file mode 100644 index 0000000000..6c8612d93c --- /dev/null +++ b/.ci/scripts/linux-flatpak/azure-ci.env @@ -0,0 +1,14 @@ +# List of environment variables to be shared with Docker containers +AZURE_BRANCH +AZURE_BUILD_ID +AZURE_BUILD_NUMBER +AZURE_COMMIT +AZURE_COMMIT_RANGE +AZURE_EVENT_TYPE +AZURE_JOB_ID +AZURE_REPO_SLUG +AZURE_TAG + +# yuzu specific flags +ENABLE_COMPATIBILITY_REPORTING +USE_DISCORD_PRESENCE diff --git a/.ci/scripts/linux-flatpak/docker.sh b/.ci/scripts/linux-flatpak/docker.sh new file mode 100644 index 0000000000..45d766b383 --- /dev/null +++ b/.ci/scripts/linux-flatpak/docker.sh @@ -0,0 +1,58 @@ +#!/bin/bash -ex + +# Converts "yuzu-emu/yuzu-release" to "yuzu-release" +REPO_NAME=$(echo $AZURE_REPO_SLUG | cut -d'/' -f 2) +YUZU_SRC_DIR="/yuzu" +BUILD_DIR="$YUZU_SRC_DIR/build" +REPO_DIR="$YUZU_SRC_DIR/repo" +STATE_DIR="$YUZU_SRC_DIR/.flatpak-builder" +KEYS_ARCHIVE="/tmp/keys.tar" +SSH_DIR="/upload" +SSH_KEY="/tmp/ssh.key" +GPG_KEY="/tmp/gpg.key" + +# Generate flatpak Manifest and AppData files (/tmp/appdata.xml and /tmp/org.yuzu.$REPO_NAME.json) +/bin/bash -ex $YUZU_SRC_DIR/.ci/scripts/linux-flatpak/generate-data.sh $1 + +# Extract keys +#openssl aes-256-cbc -K $FLATPAK_ENC_K -iv $FLATPAK_ENC_IV -in "$YUZU_SRC_DIR/keys.tar.enc" -out "$KEYS_ARCHIVE" -d +#tar -C /tmp -xvf $KEYS_ARCHIVE + +# Configure SSH keys +#eval "$(ssh-agent -s)" +#chmod 700 "$HOME/.ssh" +#chmod -R 600 $HOME/.ssh/* +#chown -R yuzu "$HOME/.ssh" +#chmod 600 "$SSH_KEY" +#ssh-add "$SSH_KEY" +#echo "[$FLATPAK_SSH_HOSTNAME]:$FLATPAK_SSH_PORT,[$(dig +short $FLATPAK_SSH_HOSTNAME)]:$FLATPAK_SSH_PORT $FLATPAK_SSH_PUBLIC_KEY" > ~/.ssh/known_hosts + +# Configure GPG keys +#gpg2 --import "$GPG_KEY" + +# Set permissions +chown -R yuzu "$YUZU_SRC_DIR" +chmod -R 700 "$YUZU_SRC_DIR" + +# Mount our flatpak repository +# -o reconnect and -o ServerAliveInterval ensure that +# the share stays active during long flatpak builds +mkdir -p "$REPO_DIR" +#sshfs "$FLATPAK_SSH_USER@$FLATPAK_SSH_HOSTNAME:$SSH_DIR" "$REPO_DIR" -C -p "$FLATPAK_SSH_PORT" -o IdentityFile="$SSH_KEY" -o ServerAliveInterval=60 -o "reconnect" -o auto_cache -o no_readahead + +# setup ccache location +chown -R yuzu "$HOME/ccache" +chmod -R 700 "$HOME/ccache" +mkdir -p "$STATE_DIR" +chown -R yuzu "$STATE_DIR" +chmod -R 700 "$STATE_DIR" +ln -sv --force $HOME/ccache "$STATE_DIR/ccache" + +# Set ccache permissions +chmod -R 700 "$STATE_DIR/ccache" + +# Build the yuzu flatpak +#flatpak-builder -v --jobs=4 --ccache --force-clean --state-dir="$STATE_DIR" --gpg-sign="$FLATPAK_GPG_PUBLIC_KEY" --repo="$REPO_DIR" "$BUILD_DIR" "/tmp/org.yuzu.$REPO_NAME.json" +#flatpak build-update-repo "$REPO_DIR" -v --generate-static-deltas --gpg-sign="$FLATPAK_GPG_PUBLIC_KEY" +flatpak-builder -v --jobs=4 --ccache --force-clean --state-dir="$STATE_DIR" --repo="$REPO_DIR" "$BUILD_DIR" "/tmp/org.yuzu.$REPO_NAME.json" +flatpak build-update-repo "$REPO_DIR" -v --generate-static-deltas diff --git a/.ci/scripts/linux-flatpak/exec.sh b/.ci/scripts/linux-flatpak/exec.sh new file mode 100644 index 0000000000..fbfdf4185d --- /dev/null +++ b/.ci/scripts/linux-flatpak/exec.sh @@ -0,0 +1,14 @@ +#!/bin/bash -ex +mkdir -p "ccache" + + +chmod a+x ./.ci/scripts/linux-flatpak/docker.sh + +# the UID for the container yuzu user is 1027 +#sudo chown -R 1027 "$HOME/.ssh" +sudo chown -R 1027 "ccache" +sudo chown -R 1027 $(pwd) +docker run --env-file .ci/scripts/linux-flatpak/azure-ci.env --env-file .ci/scripts/linux-flatpak/azure-ci-flatpak.env -v $(pwd):/yuzu -v "$(pwd)/ccache":/home/yuzu/ccache -v "$HOME/.ssh":/home/yuzu/.ssh --privileged meirod/build-environments:linux-flatpak /bin/bash -ex /yuzu/.ci/scripts/linux-flatpak/docker.sh $1 +#sudo chown -R $UID "$HOME/.ssh" +sudo chown -R $UID "ccache" +sudo chown -R $UID $(pwd) diff --git a/.ci/scripts/linux-flatpak/finish.sh b/.ci/scripts/linux-flatpak/finish.sh new file mode 100644 index 0000000000..336b65f73f --- /dev/null +++ b/.ci/scripts/linux-flatpak/finish.sh @@ -0,0 +1,9 @@ +#!/bin/bash -ex + +YUZU_SRC_DIR="/yuzu" +REPO_DIR="$YUZU_SRC_DIR/repo" + +# When the script finishes, unmount the repository and delete sensitive files, +# regardless of whether the build passes or fails +umount "$REPO_DIR" || true +rm -rf "$REPO_DIR" /tmp/* || true diff --git a/.ci/scripts/linux-flatpak/generate-data.sh b/.ci/scripts/linux-flatpak/generate-data.sh new file mode 100644 index 0000000000..1e35fc87bd --- /dev/null +++ b/.ci/scripts/linux-flatpak/generate-data.sh @@ -0,0 +1,292 @@ +#!/bin/bash -ex +# This script generates the appdata.xml and org.yuzu.$REPO_NAME.json files +# needed to define application metadata and build yuzu + +# Converts "yuzu-emu/yuzu-release" to "yuzu-release" +REPO_NAME=$(echo $AZURE_REPO_SLUG | cut -d'/' -f 2) +# Converts "yuzu-release" to "yuzu Release" +REPO_NAME_FRIENDLY=$(echo $REPO_NAME | sed -e 's/-/ /g' -e 's/\b\(.\)/\u\1/g') + +# Generate the correct appdata.xml for the version of yuzu we're building +cat > /tmp/appdata.xml < + + org.yuzu.$REPO_NAME.desktop + $REPO_NAME_FRIENDLY + Nintendo Switch emulator + CC0-1.0 + GPL-2.0 + +

yuzu is an experimental open-source emulator for the Nintendo Switch from the creators of Citra.

+

It is written in C++ with portability in mind, with builds actively maintained for Windows and Linux. The emulator is currently only useful for homebrew development and research purposes.

+

yuzu only emulates a subset of Switch hardware and therefore is generally only useful for running/debugging homebrew applications. At this time, yuzu cannot play a majority of commercial games without major problems. yuzu can boot some commercial Switch games to varying degrees of success, but your experience may vary between games and for different combinations of host hardware.

+

yuzu is licensed under the GPLv2 (or any later version). Refer to the license.txt file included.

+
+ https://yuzu-emu.org/ + https://yuzu-emu.org/donate/ + https://github.com/yuzu-emu/yuzu/issues + https://yuzu-emu.org/wiki/faq/ + https://yuzu-emu.org/wiki/home/ + https://yuzu-emu.org/images/screenshots/001-Super%20Mario%20Odyssey.png + https://yuzu-emu.org/images/screenshots/004-Super%20Mario%20Odyssey.png + https://yuzu-emu.org/images/screenshots/019-Pokken%20Tournament.png + https://yuzu-emu.org/images/screenshots/052-Pokemon%20Let%27s%20Go.png + + Games + Emulator + +
+EOF + +cat > /tmp/yuzu-wrapper <= 10 +for i in 1 2 3 .. 20 +do + # Spawn a new shell + # This guarantees that a new process is created (unlike with potential bash internals like echo etc.) + bash -c "true" + sleep 0 +done + +# Symlink com.discordapp.Discord ipc pipes if they do not exist yet +for i in {0..9}; do + test -S \$XDG_RUNTIME_DIR/app/com.discordapp.Discord/discord-ipc-\$i && ln -sf {\$XDG_RUNTIME_DIR/app/com.discordapp.Discord,\$XDG_RUNTIME_DIR}/discord-ipc-\$i; +done + +yuzu \$@ +EOF + +# Generate the yuzu flatpak manifest +cat > /tmp/org.yuzu.$REPO_NAME.json <