mirror of
https://github.com/RetroDECK/RetroDECK.git
synced 2025-04-10 19:15:12 +00:00
FLATHUB_PUSH: comments and cleanup [skip ci]
This commit is contained in:
parent
c8ecd1d50f
commit
a5bb5a03a0
|
@ -1,51 +1,60 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# EDITABLES:
|
# Check if GITHUB_WORKSPACE is set, if not, set gits_folder to /tmp/gits
|
||||||
#rd_branch=${GITHUB_REF_NAME} # should be main
|
|
||||||
|
|
||||||
if [ -z "${GITHUB_WORKSPACE}" ]; then
|
if [ -z "${GITHUB_WORKSPACE}" ]; then
|
||||||
gits_folder="${GITHUB_WORKSPACE}/tmp/gits" # without last /
|
gits_folder="${GITHUB_WORKSPACE}/tmp/gits" # without last /
|
||||||
else
|
else
|
||||||
gits_folder="/tmp/gits" # without last /
|
gits_folder="/tmp/gits" # without last /
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
rd_branch="main"
|
rd_branch="main"
|
||||||
flathub_target_repo='flathub/net.retrodeck.retrodeck'
|
flathub_target_repo='flathub/net.retrodeck.retrodeck'
|
||||||
retrodeck_repo='RetroDECK/RetroDECK'
|
retrodeck_repo='RetroDECK/RetroDECK'
|
||||||
|
|
||||||
|
# Get the latest artifact SHA and download URL from the RetroDECK Artifacts repository
|
||||||
artifacts_sha_link=$(curl -s https://api.github.com/repos/RetroDECK/Artifacts/releases/latest | jq -r '.assets[] | select(.name == "RetroDECK-Artifact.sha").browser_download_url')
|
artifacts_sha_link=$(curl -s https://api.github.com/repos/RetroDECK/Artifacts/releases/latest | jq -r '.assets[] | select(.name == "RetroDECK-Artifact.sha").browser_download_url')
|
||||||
artifacts_link=$(curl -s https://api.github.com/repos/RetroDECK/Artifacts/releases/latest | jq -r '.assets[] | select(.name == "RetroDECK-Artifact.tar.gz").browser_download_url')
|
artifacts_link=$(curl -s https://api.github.com/repos/RetroDECK/Artifacts/releases/latest | jq -r '.assets[] | select(.name == "RetroDECK-Artifact.tar.gz").browser_download_url')
|
||||||
|
|
||||||
|
# Remove existing gits_folder if it exists and create a new one
|
||||||
if [ -d "$gits_folder" ] ; then
|
if [ -d "$gits_folder" ] ; then
|
||||||
rm -rf "$gits_folder"
|
rm -rf "$gits_folder"
|
||||||
fi
|
fi
|
||||||
mkdir -vp "$gits_folder"
|
mkdir -vp "$gits_folder"
|
||||||
cd "$gits_folder" && echo "Moving in $gits_folder" || exit 1
|
cd "$gits_folder" && echo "Moving in $gits_folder" || exit 1
|
||||||
|
|
||||||
|
# Remove existing flathub and RetroDECK directories if they exist
|
||||||
if [ -d flathub ]; then
|
if [ -d flathub ]; then
|
||||||
rm -rf "$gits_folder/flathub"
|
rm -rf "$gits_folder/flathub"
|
||||||
fi
|
fi
|
||||||
if [ -d flathub ]; then
|
if [ -d flathub ]; then
|
||||||
rm -rf "$gits_folder/RetroDECK"
|
rm -rf "$gits_folder/RetroDECK"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Clone the flathub and RetroDECK repositories
|
||||||
git clone --depth=1 --recursive "https://github.com/$flathub_target_repo.git" "$gits_folder/flathub"
|
git clone --depth=1 --recursive "https://github.com/$flathub_target_repo.git" "$gits_folder/flathub"
|
||||||
git clone --depth=1 --recursive "https://github.com/$retrodeck_repo.git" "$gits_folder/RetroDECK"
|
git clone --depth=1 --recursive "https://github.com/$retrodeck_repo.git" "$gits_folder/RetroDECK"
|
||||||
|
|
||||||
|
# Get the latest release name, preferring prereleases if available
|
||||||
relname=$(curl -s https://api.github.com/repos/$retrodeck_repo/releases | jq -r '[.[] | select(.prerelease == true)][0].tag_name // empty')
|
relname=$(curl -s https://api.github.com/repos/$retrodeck_repo/releases | jq -r '[.[] | select(.prerelease == true)][0].tag_name // empty')
|
||||||
if [ -z "$relname" ]; then
|
if [ -z "$relname" ]; then
|
||||||
relname=$(curl -s https://api.github.com/repos/$retrodeck_repo/releases/latest | jq -r .tag_name)
|
relname=$(curl -s https://api.github.com/repos/$retrodeck_repo/releases/latest | jq -r .tag_name)
|
||||||
fi
|
fi
|
||||||
echo "Using release: $relname"
|
echo "Using release: $relname"
|
||||||
|
|
||||||
|
# Checkout the main branch in the RetroDECK repository
|
||||||
cd "$gits_folder/RetroDECK" && echo "Moving in $gits_folder/RetroDECK" && git checkout "$rd_branch"
|
cd "$gits_folder/RetroDECK" && echo "Moving in $gits_folder/RetroDECK" && git checkout "$rd_branch"
|
||||||
|
|
||||||
|
# Create a new branch in the flathub repository with the release name
|
||||||
cd "$gits_folder"/flathub && echo "Moving in $gits_folder/flathub" || exit 1
|
cd "$gits_folder"/flathub && echo "Moving in $gits_folder/flathub" || exit 1
|
||||||
git checkout -b "$relname"
|
git checkout -b "$relname"
|
||||||
echo "Current directory: $(pwd)"
|
echo "Current directory: $(pwd)"
|
||||||
ls -lah
|
ls -lah
|
||||||
git rm -rf *
|
|
||||||
git clean -fxd # restroing git index
|
|
||||||
|
|
||||||
# Copying only a few files as the others are cloned by git in retrodeck.sh
|
# Remove all files in the flathub repository and clean the git index
|
||||||
|
git rm -rf *
|
||||||
|
git clean -fxd # restoring git index
|
||||||
|
|
||||||
|
# Copy specific files from the RetroDECK repository to the flathub repository
|
||||||
files_to_copy=('LICENSE' 'README.md' 'other_licenses.txt' 'net.retrodeck.retrodeck.yml' 'net.retrodeck.retrodeck.metainfo.xml')
|
files_to_copy=('LICENSE' 'README.md' 'other_licenses.txt' 'net.retrodeck.retrodeck.yml' 'net.retrodeck.retrodeck.metainfo.xml')
|
||||||
for file in "${files_to_copy[@]}"; do
|
for file in "${files_to_copy[@]}"; do
|
||||||
if ! cp -fv "$gits_folder/RetroDECK/$file" "$gits_folder/flathub"; then
|
if ! cp -fv "$gits_folder/RetroDECK/$file" "$gits_folder/flathub"; then
|
||||||
|
@ -56,7 +65,7 @@ done
|
||||||
cd "$gits_folder/flathub" && echo "Moving in $gits_folder/flathub" || exit 1
|
cd "$gits_folder/flathub" && echo "Moving in $gits_folder/flathub" || exit 1
|
||||||
ls -lah
|
ls -lah
|
||||||
|
|
||||||
# Creating the manifest for flathub
|
# Create the manifest for flathub
|
||||||
manifest='net.retrodeck.retrodeck.yml'
|
manifest='net.retrodeck.retrodeck.yml'
|
||||||
sed -n '/cleanup:/q;p' $gits_folder/RetroDECK/net.retrodeck.retrodeck.yml > $manifest
|
sed -n '/cleanup:/q;p' $gits_folder/RetroDECK/net.retrodeck.retrodeck.yml > $manifest
|
||||||
sed -i '/^[[:space:]]*#/d' $manifest
|
sed -i '/^[[:space:]]*#/d' $manifest
|
||||||
|
@ -74,18 +83,20 @@ modules:
|
||||||
sha256: $(curl -sL "$artifacts_sha_link")
|
sha256: $(curl -sL "$artifacts_sha_link")
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# Create a flathub.json file specifying the architecture
|
||||||
cat << EOF >> flathub.json
|
cat << EOF >> flathub.json
|
||||||
{
|
{
|
||||||
"only-arches": ["x86_64"]
|
"only-arches": ["x86_64"]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# If we are in a GitHub workflow...
|
# If running in a GitHub workflow, configure git and authenticate with GitHub
|
||||||
if [ -n "${GITHUB_WORKFLOW}" ]; then
|
if [ -n "${GITHUB_WORKFLOW}" ]; then
|
||||||
git config --global user.name "$GIT_NAME"
|
git config --global user.name "$GIT_NAME"
|
||||||
git config --global user.email "$GIT_MAIL"
|
git config --global user.email "$GIT_MAIL"
|
||||||
git config --global credential.helper store
|
git config --global credential.helper store
|
||||||
gh auth login
|
gh auth login
|
||||||
|
# If not in a GitHub workflow, prompt the user for git configuration if not already set
|
||||||
elif [[ -z $(git config --get user.name) || -z $(git config --get user.email) ]]; then
|
elif [[ -z $(git config --get user.name) || -z $(git config --get user.email) ]]; then
|
||||||
read -p "No git user.name set, please enter your name: " git_username
|
read -p "No git user.name set, please enter your name: " git_username
|
||||||
git config --local user.name "$git_username"
|
git config --local user.name "$git_username"
|
||||||
|
@ -93,9 +104,11 @@ elif [[ -z $(git config --get user.name) || -z $(git config --get user.email) ]]
|
||||||
git config --local user.email "$git_email"
|
git config --local user.email "$git_email"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Commit the changes and push to the new branch
|
||||||
git add .
|
git add .
|
||||||
git commit -m "Update RetroDECK to v$relname from RetroDECK/$rd_branch"
|
git commit -m "Update RetroDECK to v$relname from RetroDECK/$rd_branch"
|
||||||
|
|
||||||
|
# Push the changes to the remote repository, using authentication if in a GitHub workflow
|
||||||
if [ -n "${GITHUB_WORKFLOW}" ]; then
|
if [ -n "${GITHUB_WORKFLOW}" ]; then
|
||||||
git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/${flathub_target_repo}
|
git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/${flathub_target_repo}
|
||||||
git push --force origin "$relname"
|
git push --force origin "$relname"
|
||||||
|
|
Loading…
Reference in a new issue