diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 919fd88df..611d67031 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 }} @@ -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 }} @@ -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 }} diff --git a/create-db-and-upload-action/action.yml b/create-db-and-upload-action/action.yml index 60c6e7914..b47859d4a 100644 --- a/create-db-and-upload-action/action.yml +++ b/create-db-and-upload-action/action.yml @@ -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: diff --git a/create-db-and-upload-action/entrypoint.sh b/create-db-and-upload-action/entrypoint.sh index 3ac904f68..68630848e 100755 --- a/create-db-and-upload-action/entrypoint.sh +++ b/create-db-and-upload-action/entrypoint.sh @@ -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 @@ -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 @@ -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::" \ No newline at end of file diff --git a/create-db-and-upload-action/sync.py b/create-db-and-upload-action/sync.py index ba1cc62da..c551504b9 100755 --- a/create-db-and-upload-action/sync.py +++ b/create-db-and-upload-action/sync.py @@ -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:] @@ -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, ) @@ -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, @@ -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." @@ -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") diff --git a/create-db-and-upload-action/upload.py b/create-db-and-upload-action/upload.py new file mode 100644 index 000000000..33b7decb5 --- /dev/null +++ b/create-db-and-upload-action/upload.py @@ -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)