Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/build.yml
#	README.md
#	create-db-and-upload-action/action.yml
  • Loading branch information
GrassBlock1 committed Dec 27, 2024
2 parents efb40a6 + f1c3212 commit 6c43470
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 35 deletions.
42 changes: 26 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: ./build-aur-action
with:
repo-name: ${{ matrix.repos }}
preinstallPkgs: ${{ matrix.preinstall-pkgs }}

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
path: ./*/*.pkg.tar.zst
name: ${{ matrix.repos }}
Expand All @@ -44,46 +44,49 @@ jobs:
strategy:
matrix:
PKGBUILDs: [newsflash-git, wezterm-git-noinfo]

fail-fast: false

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Build Non-AUR packages
id: makepkg
uses: ./build-nonaur-action
with:
pkgdir: ${{ matrix.PKGBUILDs }}
aurDeps: true

- uses: actions/upload-artifact@v3
with:
path: ./*/*.pkg.tar.zst
name: ${{ matrix.PKGBUILDs }}
if-no-files-found: error

- uses: ncipollo/release-action@v1
with:
allowUpdates: true
tag: "packages"
artifacts: ${{ steps.makepkg.outputs.pkgfile0 }}
token: ${{ secrets.GITHUB_TOKEN }}
#TODO

#TODO
uploadToOneDrive:
runs-on: ubuntu-latest
if: always()
needs: [buildAUR , buildNonAUR]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
id: download


- name: Display structure of downloaded files
run: ls -R ${{ steps.download.outputs.download-path }}

- uses: ./create-db-and-upload-action
with:
RCLONE_ONEDRIVE_CLIENT_ID: ${{ secrets.RCLONE_ONEDRIVE_CLIENT_ID }}
Expand All @@ -92,8 +95,15 @@ jobs:
RCLONE_ONEDRIVE_TOKEN: ${{ secrets.RCLONE_ONEDRIVE_TOKEN }}
RCLONE_ONEDRIVE_DRIVE_ID: ${{ secrets.RCLONE_ONEDRIVE_DRIVE_ID }}
RCLONE_ONEFRIVE_TENANT_ID: ${{ secrets.RCLONE_ONEDRIVE_TENANT_ID }}
RCLONE_ONEDRIVE_DRIVE_TYPE: business
dest_path: /data/archrepo
repo_name: gb-cha0s
RCLONE_ONEDRIVE_DRIVE_TYPE: personal
dest_path: /archrepo
repo_name: vifly
gpg-privatekey: ${{ secrets.gpg_private_key }}
local_path: ${{ steps.download.outputs.download-path }}

- uses: ncipollo/release-action@v1
with:
allowUpdates: true
tag: "packages"
artifacts: "./upload_packages/*.sig,./upload_packages/*.files,./upload_packages/*.db,./upload_packages/*.tar.gz"
token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 6 additions & 2 deletions create-db-and-upload-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ inputs:
required: true
RCLONE_ONEDRIVE_REGION:
required: true
RCLONE_ONEDRIVE_TENANT_ID:
required: false
description: "Your tenant id, required if the application is created with single tenant scope. Read rclone documention for more info."
RCLONE_ONEDRIVE_TOKEN:
required: true
RCLONE_ONEDRIVE_DRIVE_ID:
required: true
RCLONE_ONEDRIVE_DRIVE_TYPE:
required: true
RCLONE_ONEDRIVE_TENANT_ID:
RCLONE_CONFIG_CONTENT:
required: true
RCLONE_CONFIG_NAME:
required: false
description: "Your tenant id, required if the application is created with single tenant scope. Read rclone documention for more info."
dest_path:
required: true
repo_name:
Expand Down
35 changes: 23 additions & 12 deletions create-db-and-upload-action/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ set -e

init_path=$PWD
mkdir upload_packages
cp $local_path/*/*/*.tar.zst ./upload_packages/
find $local_path -type f -name "*.tar.zst" -exec cp {} ./upload_packages/ \;

echo "$RCLONE_CONFIG_NAME"

if [ ! -f ~/.config/rclone/rclone.conf ]; then
mkdir --parents ~/.config/rclone
echo "[onedrive]" >> ~/.config/rclone/rclone.conf
echo "type = onedrive" >> ~/.config/rclone/rclone.conf

echo "client_id=$RCLONE_ONEDRIVE_CLIENT_ID" >> ~/.config/rclone/rclone.conf
echo "client_secret=$RCLONE_ONEDRIVE_CLIENT_SECRET" >> ~/.config/rclone/rclone.conf
echo "region=$RCLONE_ONEDRIVE_REGION" >> ~/.config/rclone/rclone.conf
echo "drive_type=$RCLONE_ONEDRIVE_DRIVE_TYPE" >> ~/.config/rclone/rclone.conf
echo "token=$RCLONE_ONEDRIVE_TOKEN" >> ~/.config/rclone/rclone.conf
echo "drive_id=$RCLONE_ONEDRIVE_DRIVE_ID" >> ~/.config/rclone/rclone.conf
echo "$RCLONE_CONFIG_CONTENT" >> ~/.config/rclone/rclone.conf
fi

if [ $RCLONE_ONEDRIVE_DRIVE_TYPE == "business" && $RCLONE_ONEDRIVE_TENANT_ID ]; then
Expand All @@ -29,11 +23,23 @@ fi

cd upload_packages || exit 1

echo "::group::Adding packages to the repo"

repo-add "./${repo_name:?}.db.tar.gz" ./*.tar.zst
python3 $init_path/create-db-and-upload-action/sync.py

echo "::endgroup::"

echo "::group::Removing old packages"

python3 $init_path/create-db-and-upload-action/sync.py

echo "::endgroup::"

rm "./${repo_name:?}.db.tar.gz"
rm "./${repo_name:?}.files.tar.gz"

echo "::group::Signing packages"

if [ ! -z "$gpg_key" ]; then
packages=( "*.tar.zst" )
for name in $packages
Expand All @@ -42,4 +48,9 @@ if [ ! -z "$gpg_key" ]; then
done
repo-add --verify --sign "./${repo_name:?}.db.tar.gz" ./*.tar.zst
fi
rclone copy ./ "onedrive:${dest_path:?}" --copy-links

echo "::endgroup::"

echo "::group::Uploading to remote"
python3 $init_path/create-db-and-upload-action/upload.py
echo "::endgroup::"
19 changes: 14 additions & 5 deletions create-db-and-upload-action/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@

REPO_NAME = os.environ["repo_name"]
ROOT_PATH = os.environ["dest_path"]
CONFIG_NAME = os.environ.get("RCLONE_CONFIG_NAME", "")

if CONFIG_NAME == "":
result = subprocess.run(["rclone", "listremotes"], capture_output=True)
CONFIG_NAME = result.stdout.decode().split("\n")[0]
if not CONFIG_NAME.endswith(":"):
CONFIG_NAME = CONFIG_NAME + ":"

if ROOT_PATH.startswith("/"):
ROOT_PATH = ROOT_PATH[1:]

Expand Down Expand Up @@ -56,7 +64,7 @@ def get_pkg_infos(file_path: str) -> list["PkgInfo"]:

def rclone_delete(name: str):
r = subprocess.run(
["rclone", "delete", f"onedrive:/{ROOT_PATH}/{name}"],
["rclone", "delete", f"{CONFIG_NAME}/{ROOT_PATH}/{name}"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
Expand All @@ -69,7 +77,7 @@ def rclone_download(name: str, dest_path: str = "./"):
[
"rclone",
"copy",
f"onedrive:/{ROOT_PATH}/{name}",
f"{CONFIG_NAME}/{ROOT_PATH}/{name}",
dest_path,
],
stdout=subprocess.PIPE,
Expand Down Expand Up @@ -110,10 +118,11 @@ def download_local_miss_files(

if __name__ == "__main__":
r = subprocess.run(
["rclone", "size", f"onedrive:/{ROOT_PATH}/{REPO_NAME}.db.tar.gz"],
["rclone", "size", f"{CONFIG_NAME}/{ROOT_PATH}/{REPO_NAME}.db.tar.gz"],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
if r.returncode != 0:
if r.returncode != 0 or "Total size: 0" in r.stdout.decode():
print("Remote database file is not exist!")
print(
"If you are running this script for the first time, you can ignore this error."
Expand All @@ -128,7 +137,7 @@ def download_local_miss_files(

old_packages = get_old_packages(local_packages, remote_packages)
for i in old_packages:
print(f"delete onedrive {i.filename}")
print(f"delete {CONFIG_NAME} {i.filename}")
rclone_delete(i.filename)
with suppress(RuntimeError):
rclone_delete(i.filename + ".sig")
Expand Down
25 changes: 25 additions & 0 deletions create-db-and-upload-action/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import subprocess
import os

REPO_NAME = os.environ["repo_name"]
ROOT_PATH = os.environ["dest_path"]
CONFIG_NAME = os.environ.get("RCLONE_CONFIG_NAME", "")

if CONFIG_NAME == "":
result = subprocess.run(["rclone", "listremotes"], capture_output=True)
CONFIG_NAME = result.stdout.decode().split("\n")[0]
if not CONFIG_NAME.endswith(":"):
CONFIG_NAME = CONFIG_NAME + ":"

if ROOT_PATH.startswith("/"):
ROOT_PATH = ROOT_PATH[1:]

if __name__ == "__main__":
r = subprocess.run(
["rclone", "copy", "./", f"{CONFIG_NAME}/{ROOT_PATH}", "--copy-links"],
stderr=subprocess.PIPE,
)
if r.returncode != 0:
print("Failed when copying to remote")
print(r.stderr.decode())
exit(0)

0 comments on commit 6c43470

Please sign in to comment.