Skip to content

Commit

Permalink
release as single run file (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrightXiaoHan authored Feb 13, 2024
1 parent a1df048 commit fb67173
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 124 deletions.
134 changes: 34 additions & 100 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,24 @@ jobs:

- name: Install
shell: bash
run: scripts/install.sh local-install
run: scripts/install.sh -m local-install

- name: Pack
shell: bash
run: scripts/pack.sh home-cli-x86_64.tar

- uses: actions/upload-artifact@v3
with:
name: home-cli-pack-x86_64
path: home-cli-x86_64.tar

run-x86_64:
runs-on: ubuntu-20.04
needs: build-x86_64
run: scripts/pack.sh -o home-cli-x86_64.run

- name: Uninstall
shell: bash
run: scripts/uninstall.sh

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Unpack
shell: bash
run: bash ./home-cli-x86_64.run -- -m install --install-dir ${{ github.workspace }}/home-cli-x86_64

- uses: actions/download-artifact@v3
- uses: actions/upload-artifact@v3
with:
name: home-cli-pack-x86_64

- name: Unpack
shell: bash
run: scripts/install.sh unpack home-cli-x86_64.tar
path: home-cli-x86_64.run

build-arm64:
if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'linux') || github.event_name == 'push'
Expand Down Expand Up @@ -93,60 +83,26 @@ jobs:
run: |
uname -a
cd /workspace
scripts/install.sh local-install
scripts/pack.sh home-cli-arm64.tar
scripts/install.sh -m local-install
scripts/pack.sh -o home-cli-arm64.run
scripts/uninstall.sh
bash home-cli-arm64.run -- -m install --install-dir /workspace/home-cli-arm64
- uses: actions/upload-artifact@v3
with:
name: home-cli-pack-arm64
path: home-cli-arm64.tar

run-arm64:
runs-on: ubuntu-20.04
needs: build-arm64

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0

- uses: actions/download-artifact@v3
with:
name: home-cli-pack-arm64

- uses: uraimo/run-on-arch-action@v2
name: Run commands
with:
arch: aarch64
distro: ubuntu20.04

env: |
HOMECLI_PRINT_PROGRESS: false
# Mount the artifacts directory as /artifacts in the container
dockerRunArgs: |
--volume "${PWD}:/workspace"
install: |
apt update -y
apt install -y python3 python3-pip curl libfuse-dev git
# Set an output parameter `uname` for use in subsequent steps
run: |
cd /workspace
scripts/install.sh unpack home-cli-arm64.tar
path: home-cli-arm64.run

release:
runs-on: ubuntu-20.04
needs:
- run-x86_64
- run-arm64
- build-x86_64
- build-arm64
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

steps:
- name: Create Release
if: "!contains(github.ref, 'nightly')"
if: "! contains(github.ref, 'nightly')"
id: create_release
uses: actions/create-release@v1
with:
Expand All @@ -158,7 +114,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Delete Legacy Pre-Release
if: "contains(github.ref, 'nightly')"
if: contains(github.ref, 'nightly')
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -199,15 +155,15 @@ jobs:
name: home-cli-pack-x86_64

- name: Upload Assets x86_64
if: "!contains(github.ref, 'nightly')"
if: "! contains(github.ref, 'nightly')"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./home-cli-x86_64.tar
asset_name: home-cli-x86_64.tar
asset_content_type: application/tar
asset_path: ./home-cli-x86_64.run
asset_name: home-cli-x86_64.run
asset_content_type: application/octet-stream

- name: Upload Pre-Release Assets x86_64
if: contains(github.ref, 'nightly')
Expand All @@ -216,24 +172,24 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_pre_release.outputs.upload_url }}
asset_path: ./home-cli-x86_64.tar
asset_name: home-cli-x86_64.tar
asset_content_type: application/tar
asset_path: ./home-cli-x86_64.run
asset_name: home-cli-x86_64.run
asset_content_type: application/octet-stream

- uses: actions/download-artifact@v3
with:
name: home-cli-pack-arm64

- name: Upload Assets arm64
if: "!contains(github.ref, 'nightly')"
if: "! contains(github.ref, 'nightly')"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./home-cli-arm64.tar
asset_name: home-cli-arm64.tar
asset_content_type: application/tar
asset_path: ./home-cli-arm64.run
asset_name: home-cli-arm64.run
asset_content_type: application/octet-stream

- name: Upload Pre-Release Assets arm64
if: contains(github.ref, 'nightly')
Expand All @@ -242,28 +198,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_pre_release.outputs.upload_url }}
asset_path: ./home-cli-arm64.tar
asset_name: home-cli-arm64.tar
asset_content_type: application/tar

- name: Upload Assets install.sh
if: "!contains(github.ref, 'nightly')"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./scripts/install.sh
asset_name: install.sh
asset_content_type: text/plain

- name: Upload Pre-Release Assets install.sh
if: "contains(github.ref, 'nightly')"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_pre_release.outputs.upload_url }}
asset_path: ./scripts/install.sh
asset_name: install.sh
asset_content_type: text/plain
asset_path: ./home-cli-arm64.run
asset_name: home-cli-arm64.run
asset_content_type: application/octet-stream
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "general/alacritty/themes"]
path = general/alacritty/themes
url = https://github.com/alacritty/alacritty-theme
[submodule "scripts/makeself"]
path = scripts/makeself
url = https://github.com/megastep/makeself
51 changes: 51 additions & 0 deletions scripts/_unpack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Usage() {
echo "Usage: $0 --mode <install|uninstall> [--remove-cache <true|false>] [--install-dir <install-dir>] [--help]"
echo "args can be one or more of the following :"
echo " --mode | -m : Mode of operation. Default: install"
echo " --remove-cache | -r : Remove cache. Default: true"
echo " --install-dir : Installation directory. Default: $HOME/.homecli"
echo " --help | -h : Show this help message"
exit 1
}

while true; do
case "$1" in
--mode | -m)
MODE=$2
if [ "$MODE" != "install" ] && [ "$MODE" != "uninstall" ]; then
echo "invalid argument: $MODE (should be install or uninstall)"
Usage
fi
shift 2
;;
--remove-cache | -r)
REMOVE_CACHE=$2
shift 2
;;
--install-dir)
INSTALL_DIR=$2
shift 2
;;
--help | -h)
Usage
;;
-*)
echo "Unknown option: $1"
Usage
;;
*)
break
;;
esac
done

MODE=${MODE:-install}
INSTALL_DIR=${INSTALL_DIR:-$HOME/.homecli}
REMOVE_CACHE=${REMOVE_CACHE:-true}


if [ "$MODE" = "install" ]; then
./install.sh --mode unpack --install-dir $INSTALL_DIR --tarfile homecli.tar.gz --old-install-dir /home/runner/.homecli
elif [ "$MODE" = "uninstall" ]; then
./uninstall.sh --remove-cache $REMOVE_CACHE --install-dir $INSTALL_DIR
fi
90 changes: 76 additions & 14 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,66 @@
set -e
Usage() {
echo "Usage: $0 --mode <mode> --install-dir <install-dir> [--tarfile <tarfile>] [--old-install-dir <old-install-dir>] [--help]"
echo "args can be one or more of the following :"
echo " --mode | -m : Installation mode. local-install, online-install, unpack or relink (local-install is default)"
echo " --tarfile | -t : Tarfile to unpack. Only used when mode is unpack"
echo " --install-dir : Installation directory. Default: $HOME/.homecli"
echo " --old-install-dir: Old installation directory. Only used when mode is unpack. Default: /home/runner/.homecli"
echo " --help | -h : Show this help message"
exit 1
}

while true; do
case "$1" in
--mode | -m)
MODE=$2
shift 2
;;
--tarfile | -t)
TARFILE=$2
shift 2
;;
--install-dir)
INSTALL_DIR=$2
shift 2
;;
--old-install-dir)
OLD_INSTALL_DIR=$2
shift 2
;;
--help | -h)
Usage
;;
-*)
echo "Unknown option: $1"
Usage
;;
*)
break
;;
esac
done
# MODE: local-install, online-install or unpack. Default: online-install
MODE=${1:-online-install}
INSTALL_DIR=${HOMECLI_INSTALL_DIR:-$HOME/.homecli}
if [ -z "$MODE" ]; then
MODE=online-install
fi

# INSTALL_DIR: Installation directory. Default: $HOME/.homecli
if [ -z "$INSTALL_DIR" ]; then
INSTALL_DIR=${HOMECLI_INSTALL_DIR:-$HOME/.homecli}
fi

# remove config files
rm -rf ~/.config/alacritty \
~/.config/nvim \
~/.config/tmux \
~/.config/fish \
~/.gitconfig \
~/.ssh/config \
~/.ssh/id_rsa.pub \
~/.mambarc

# remove nvim plugins
rm -rf ~/.local/share/nvim

if [ "$MODE" = "local-install" ]; then
CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
Expand All @@ -11,13 +70,17 @@ if [ "$MODE" = "local-install" ]; then
cd $INSTALL_DIR/HOME

elif [ "$MODE" = "unpack" ]; then
TARFILE="$2"
if [ -z "$TARFILE" ]; then
echo "Usage: install.sh unpack <tarfile>"
exit 1
echo "Error: tarfile is required for unpack mode."
Usage
fi

if [ ! -f "$TARFILE" ]; then
echo "Error: tarfile not found: $TARFILE"
Usage
fi
# Github action runner default home dir is /home/runner
OLD_INSTALL_DIR=${3:-/home/runner/.homecli}
# Github action runner default home dir is /home/runner
OLD_INSTALL_DIR=${OLD_INSTALL_DIR:-/home/runner/.homecli}
mkdir -p $INSTALL_DIR
tar -xvf "$TARFILE" -C "$INSTALL_DIR"
mkdir -p $INSTALL_DIR/miniconda
Expand All @@ -31,9 +94,8 @@ elif [ "$MODE" = "online-install" ]; then
elif [ "$MODE" = "relink" ]; then
DIR="$INSTALL_DIR/HOME/general"
else
echo "Usage: install.sh <mode> [tarfile]"
echo "mode: local-install, online-install, unpack or relink (local-install is default)"
exit 1
echo "Error: Unknown mode: $MODE"
Usage
fi

# get current dir
Expand All @@ -55,7 +117,7 @@ fi

# link nvim dir if .config/nvim not exist
if [ ! -d ~/.config/nvim ]; then
rm $DIR/NvChad/lua/custom || true
rm -f $DIR/NvChad/lua/custom || true
ln -sf $DIR/custom/ $DIR/NvChad/lua/custom
ln -sf $DIR/NvChad/ ~/.config/nvim
else
Expand Down Expand Up @@ -106,7 +168,7 @@ if [ "$MODE" = "local-install" ] || [ "$MODE" = "online-install" ]; then
ln -sf $INSTALL_DIR/nvim $HOME/.local/share/nvim
elif [ "$MODE" = "unpack" ]; then
mkdir -p ~/.local/share && ln -sf $INSTALL_DIR/nvim/ ~/.local/share/nvim
source $INSTALL_DIR/miniconda/bin/activate
. $INSTALL_DIR/miniconda/bin/activate
CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1 conda unpack

# Re-link broken symlinks
Expand Down Expand Up @@ -149,7 +211,7 @@ elif [ "$MODE" = "unpack" ]; then

for file in $(find $INSTALL_DIR/bin -type l); do
origin_file=$(readlink -m $file)
sed -i "s|$OLD_INSTALL_DIR|$INSTALL_DIR|g" $file
sed -i "s|$OLD_INSTALL_DIR|$INSTALL_DIR|g" $origin_file
done
elif [ "$MODE" = "relink" ]; then
ln -sf $INSTALL_DIR/nvim/ ~/.local/share/nvim
Expand Down
Loading

0 comments on commit fb67173

Please sign in to comment.