Skip to content

Commit 698c44b

Browse files
committed
feat: update metainfo and add Flathub push workflow with manifest management
1 parent e9617f3 commit 698c44b

File tree

3 files changed

+296
-5
lines changed

3 files changed

+296
-5
lines changed

.github/workflows/flathub_push.yml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: "Flathub push"
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
dry_run:
7+
description: "Enable DRY RUN: don't push to Flathub, just simulate the process"
8+
type: boolean
9+
required: false
10+
default: false
11+
12+
jobs:
13+
Pushing_branch_to_flathub:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Install xmlstarlet
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y xmlstarlet
25+
xmlstarlet --version || true
26+
27+
- name: Prepare Flathub content (copy + optional manifest patch)
28+
id: prepare
29+
run: |
30+
set -euo pipefail
31+
32+
# prepare flathub folder and replace README (manifest is generated from Properties/linux/flatpak)
33+
./Scripts/update-flathub-manifest.sh -r README.md
34+
35+
# try to read a release version from metainfo (if present)
36+
METAFILE="Properties/linux/flathub/io.github.HyPrismTeam.HyPrism.metainfo.xml"
37+
RELEASE_VERSION=""
38+
if [ -f "$METAFILE" ]; then
39+
RELEASE_VERSION=$(xmlstarlet sel -t -v "//*[local-name()='release']/@version" "$METAFILE" 2>/dev/null || true)
40+
fi
41+
42+
if [ -z "$RELEASE_VERSION" ]; then
43+
SHORT_SHA=$(git rev-parse --short=7 HEAD 2>/dev/null || echo "local")
44+
RELEASE_VERSION="auto-$(date +%Y%m%d%H%M%S)-$SHORT_SHA"
45+
fi
46+
47+
echo "RELEASE_VERSION=$RELEASE_VERSION" > flathub_push_info.env
48+
echo "Prepared Properties/linux/flathub — release_version=$RELEASE_VERSION"
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Debug: show flathub dir and manifest
53+
run: |
54+
echo "Listing Properties/linux/flathub"
55+
ls -lah Properties/linux/flathub || true
56+
echo "----- manifest (if generated) -----"
57+
cat Properties/linux/flathub/io.github.HyPrismTeam.HyPrism.yml || true
58+
59+
- name: Clone Flathub repo and push
60+
env:
61+
GH_TOKEN: ${{ secrets.FLATHUB_PUSH }}
62+
GIT_NAME: ${{ secrets.GITNAME || github.actor }}
63+
GIT_MAIL: ${{ secrets.GITMAIL || github.actor }}
64+
DRY_RUN: ${{ github.event.inputs.dry_run }}
65+
run: |
66+
set -euo pipefail
67+
68+
if [ -z "${GH_TOKEN:-}" ]; then
69+
echo "ERROR: secret FLATHUB_PUSH is required to push to the Flathub repository" >&2
70+
exit 1
71+
fi
72+
73+
git config --global user.name "${GIT_NAME}"
74+
git config --global user.email "${GIT_MAIL}"
75+
76+
rm -rf flathub-repo || true
77+
git clone "https://x-access-token:${GH_TOKEN}@github.com/flathub/io.github.HyPrismTeam.HyPrism.git" flathub-repo
78+
79+
# determine branch name
80+
source flathub_push_info.env || true
81+
BRANCH_NAME="$RELEASE_VERSION"
82+
83+
echo "Using branch: $BRANCH_NAME"
84+
85+
cd flathub-repo
86+
87+
# create branch if it doesn't exist
88+
if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then
89+
git checkout "$BRANCH_NAME"
90+
else
91+
git checkout -b "$BRANCH_NAME"
92+
fi
93+
94+
# remove tracked files (keep .git)
95+
git rm -rf . || true
96+
git clean -fdx || true
97+
98+
# copy prepared flathub content
99+
cp -a ../Properties/linux/flathub/. .
100+
101+
# ensure README.md is present
102+
if [ ! -f README.md ]; then
103+
echo "WARNING: README.md missing in flathub content" >&2
104+
fi
105+
106+
git add -A
107+
if git commit -m "chore(flathub): update manifest/content for $BRANCH_NAME" >/dev/null 2>&1; then
108+
echo "Committed changes"
109+
else
110+
echo "No changes to commit"
111+
fi
112+
113+
if [ "${DRY_RUN}" = "true" ]; then
114+
echo "Dry-run: not pushing to flathub"
115+
exit 0
116+
fi
117+
118+
git push origin HEAD:$BRANCH_NAME --force
119+
echo "Pushed to https://github.com/flathub/io.github.HyPrismTeam.HyPrism/tree/$BRANCH_NAME"
120+
121+
Summary:
122+
needs: Pushing_branch_to_flathub
123+
runs-on: ubuntu-latest
124+
if: always()
125+
steps:
126+
- name: Checkout repository
127+
uses: actions/checkout@v4
128+
with:
129+
fetch-depth: 1
130+
131+
- name: Write Flathub push summary
132+
run: |
133+
set -e
134+
if [ -f flathub_push_info.env ]; then
135+
source flathub_push_info.env || true
136+
fi
137+
138+
branch_name="$RELEASE_VERSION"
139+
flathub_repo="https://github.com/flathub/io.github.HyPrismTeam.HyPrism"
140+
branch_url="$flathub_repo/tree/$branch_name"
141+
142+
echo "### Flathub push summary" >> "$GITHUB_STEP_SUMMARY"
143+
echo "* Flathub branch pushed: **$branch_name**" >> "$GITHUB_STEP_SUMMARY"
144+
echo "* Branch link: [$branch_url]($branch_url)" >> "$GITHUB_STEP_SUMMARY"
145+
echo "* Flathub content source: \\`Properties/linux/flathub\\

Properties/linux/flatpak/io.github.HyPrismTeam.HyPrism.metainfo.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<component type="desktop-application">
33
<id>io.github.HyPrismTeam.HyPrism</id>
44
<name>HyPrism</name>
5-
<summary>Cross-platform Hytale launcher</summary>
5+
<summary>Cross-platform Hytale launcher and mod manager</summary>
66
<icon type="cached">io.github.HyPrismTeam.HyPrism</icon>
77
<metadata_license>MIT</metadata_license>
88
<project_license>MIT</project_license>
99

1010
<description>
1111
<p>
12-
HyPrism is an open-source launcher for Hytale with instance management,
12+
HyPrism is an open-source launcher and mod manager for Hytale with instance management,
1313
CurseForge mod integration, and streamlined updates.
1414
</p>
1515
<ul>
@@ -25,12 +25,12 @@
2525
<screenshots>
2626
<screenshot type="default">
2727
<caption>HyPrism launcher dashboard</caption>
28-
<image>https://raw.githubusercontent.com/yyyumeniku/HyPrism/main/assets/screenshot.png</image>
28+
<image>https://raw.githubusercontent.com/HyPrismTeam.HyPrism/HyPrism/main/assets/screenshot.png</image>
2929
</screenshot>
3030
</screenshots>
3131

32-
<url type="homepage">https://github.com/yyyumeniku/HyPrism</url>
33-
<url type="bugtracker">https://github.com/yyyumeniku/HyPrism/issues</url>
32+
<url type="homepage">https://github.com/HyPrismTeam.HyPrism/HyPrism</url>
33+
<url type="bugtracker">https://github.com/HyPrismTeam.HyPrism/HyPrism/issues</url>
3434
<developer_name>HyPrism Team</developer_name>
3535

3636
<provides>

Scripts/update-flathub-manifest.sh

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# update-flathub-manifest.sh
5+
# - copy all regular files (not directories) from Properties/linux/flatpak -> Properties/linux/flathub
6+
# - download (or read locally) flathub-bundle.tar.gz, compute sha256 and update
7+
# `Properties/linux/flathub/io.github.HyPrismTeam.HyPrism.yml` by replacing the placeholder
8+
9+
usage() {
10+
cat <<EOF
11+
Usage: $0 [-s SRC_DIR] [-d DST_DIR] [-a ARCHIVE_URL_OR_PATH] [-r README_SRC]
12+
13+
Options:
14+
-s SRC_DIR source folder with flatpak files (default: Properties/linux/flatpak)
15+
-d DST_DIR destination folder for flathub files (default: Properties/linux/flathub)
16+
-a ARCHIVE URL or local path to flathub-bundle.tar.gz (optional — if given the
17+
script will download/inspect it and insert the sha256 into the manifest)
18+
-r README_SRC optional path to a README file which will replace the README.md in the
19+
destination folder (useful to replace with the repo README)
20+
-h show this help
21+
22+
Examples:
23+
# copy files only
24+
$0
25+
26+
# copy files + download archive and patch manifest sha256
27+
$0 -a https://github.com/OWNER/REPO/releases/download/vX.Y/flathub-bundle.tar.gz
28+
29+
# copy files and replace README.md in the flathub folder
30+
$0 -r README.md
31+
EOF
32+
exit 1
33+
}
34+
35+
SRC_DIR="Properties/linux/flatpak"
36+
DST_DIR="Properties/linux/flathub"
37+
ARCHIVE=""
38+
README_SRC=""
39+
40+
while getopts ":s:d:a:r:h" opt; do
41+
case $opt in
42+
s) SRC_DIR="$OPTARG" ;;
43+
d) DST_DIR="$OPTARG" ;;
44+
a) ARCHIVE="$OPTARG" ;;
45+
r) README_SRC="$OPTARG" ;;
46+
h) usage ;;
47+
\?) echo "Invalid option: -$OPTARG" >&2; usage ;;
48+
esac
49+
done
50+
51+
mkdir -p "$DST_DIR"
52+
53+
# 1) copy regular files (no directories)
54+
echo "Copying regular files from '$SRC_DIR' -> '$DST_DIR'..."
55+
if [ ! -d "$SRC_DIR" ]; then
56+
echo "Source directory '$SRC_DIR' does not exist." >&2
57+
exit 2
58+
fi
59+
find "$SRC_DIR" -maxdepth 1 -type f -exec cp -a -- '{}' "$DST_DIR/" \;
60+
61+
# optional: replace README in destination with provided source
62+
if [ -n "${README_SRC:-}" ]; then
63+
if [ -f "$README_SRC" ]; then
64+
echo "Replacing README in '$DST_DIR' with '$README_SRC'"
65+
cp -a "$README_SRC" "$DST_DIR/README.md"
66+
else
67+
echo "README source not found: $README_SRC" >&2
68+
exit 5
69+
fi
70+
fi
71+
72+
MANIFEST="$DST_DIR/io.github.HyPrismTeam.HyPrism.yml"
73+
# if no manifest in DST, try to copy from SRC
74+
if [ ! -f "$MANIFEST" ]; then
75+
if [ -f "$SRC_DIR/io.github.HyPrismTeam.HyPrism.yml" ]; then
76+
echo "Creating manifest '$MANIFEST' by copying from $SRC_DIR"
77+
cp -a "$SRC_DIR/io.github.HyPrismTeam.HyPrism.yml" "$MANIFEST"
78+
else
79+
echo "Manifest not found in source or destination: $MANIFEST" >&2
80+
exit 3
81+
fi
82+
fi
83+
84+
# helper: insert/replace sha256 in manifest
85+
insert_sha_in_manifest() {
86+
local sha="$1"
87+
# 3 possible states in manifest:
88+
# 1) placeholder `REPLACE_WITH_FLATHUB_BUNDLE_SHA256` — replace it
89+
# 2) already `type: archive` — update sha field
90+
# 3) still has the two `type: dir` blocks — replace those with archive + sha
91+
92+
if grep -q "REPLACE_WITH_FLATHUB_BUNDLE_SHA256" "$MANIFEST"; then
93+
sed -i "s/REPLACE_WITH_FLATHUB_BUNDLE_SHA256/$sha/" "$MANIFEST"
94+
return
95+
fi
96+
97+
if grep -q "type: archive" "$MANIFEST"; then
98+
# replace existing sha value
99+
sed -i -E "s/(sha256:\s*)[a-f0-9]{64}/\1$sha/" "$MANIFEST"
100+
return
101+
fi
102+
103+
# replace the two `type: dir` blocks with the archive block
104+
perl -0777 -pe "s{(\n\s*sources:\n)\s*- type: dir\n\s*path: ../../../bin/Release/net10.0/linux-x64/publish/linux-unpacked\n\s*dest: linux-unpacked\n\s*- type: dir\n\s*path: ../../../wwwroot\n\s*dest: wwwroot\n}{\1 - type: archive\n url: release, latest, flathub-bundle.tar.gz\n sha256: $sha\n}s" -i "$MANIFEST"
105+
}
106+
107+
# 2) if archive provided -> download (or use local path), compute sha and patch manifest
108+
if [ -n "$ARCHIVE" ]; then
109+
TMPDIR="$(mktemp -d)"
110+
trap 'rm -rf "$TMPDIR"' EXIT
111+
112+
if [[ "$ARCHIVE" =~ ^https?:// ]]; then
113+
TARPATH="$TMPDIR/flathub-bundle.tar.gz"
114+
echo "Downloading archive from $ARCHIVE..."
115+
curl -fL -o "$TARPATH" "$ARCHIVE"
116+
else
117+
TARPATH="$ARCHIVE"
118+
if [ ! -f "$TARPATH" ]; then
119+
echo "Archive file not found: $TARPATH" >&2
120+
exit 4
121+
fi
122+
fi
123+
124+
echo "Computing sha256..."
125+
if command -v sha256sum >/dev/null 2>&1; then
126+
SHA256="$(sha256sum "$TARPATH" | awk '{print $1}')"
127+
else
128+
SHA256="$(shasum -a 256 "$TARPATH" | awk '{print $1}')"
129+
fi
130+
echo "sha256=$SHA256"
131+
132+
# quick verification that the tar contains both expected directories
133+
if tar -tzf "$TARPATH" | awk -F/ '{print $1}' | sort -u | grep -E "^(wwwroot|linux-unpacked)$" >/dev/null; then
134+
echo "Archive contains expected entries (wwwroot, linux-unpacked)"
135+
else
136+
echo "Warning: archive does NOT appear to contain both 'wwwroot' and 'linux-unpacked' (continuing)" >&2
137+
fi
138+
139+
insert_sha_in_manifest "$SHA256"
140+
echo "Patched manifest: $MANIFEST"
141+
else
142+
echo "No archive provided (-a); manifest left with placeholder or will contain archive block after manual update."
143+
fi
144+
145+
echo "Done. Files copied to '$DST_DIR' and manifest updated (if -a was used)."
146+
exit 0

0 commit comments

Comments
 (0)