diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 19925c9..ca874af 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,8 +18,8 @@ jobs: goarch: [amd64, arm64] steps: - - uses: actions/checkout@v4 - - uses: aadam-ali/go-release-action@62026c9f20e38c208e44b24d9d511d424149aea9 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: wangyoucao577/go-release-action@279495102627de7960cbc33434ab01a12bae144b # v1.55 with: github_token: ${{ secrets.GITHUB_TOKEN }} goos: ${{ matrix.goos }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 722be16..33eb9d0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,10 +12,10 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v5 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Set up Go - uses: actions/setup-go@v5 + uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 with: go-version: '1.23.12' diff --git a/.gitignore b/.gitignore index 6f72f89..355ea82 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ go.work.sum # env file .env + +# build directory +bin/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 342e0fe..a46b7c2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - - repo: https://github.com/TekWizely/pre-commit-golang - rev: v0.8.3 - hooks: - - id: go-imports - - id: go-test-repo-mod diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index d51545d..0000000 --- a/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -golang 1.23.12 diff --git a/install.sh b/install.sh deleted file mode 100755 index bef29eb..0000000 --- a/install.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -install_dir="${HOME}/.local/bin" - -[[ -d "${install_dir}" ]] || mkdir -p "${install_dir}" - -if [[ -f "${install_dir}/sb" ]]; then - mv "${install_dir}/sb" "${install_dir}/sb.old" -fi - -go get . -go build -o "${install_dir}/sb" -ldflags "-X github.com/aadam-ali/second-brain-cli/config.version=$(git rev-parse --short HEAD)" main.go diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..f5ea7af --- /dev/null +++ b/mise.toml @@ -0,0 +1,26 @@ +[tools] +go = "1.23.12" +pre-commit = "latest" + +[tasks.pre-commit-install] +description = "Install pre-commit hooks using pre-commit and mise" +run = [ + "mise generate git-pre-commit -w", + "pre-commit install" +] + +[tasks.pre-commit] +description = "Run tasks for pre-commit hook" +depends = ["test"] + +[tasks.deps] +description = "Update and Install Dependencies" +run = ["go get -u ./...", "go mod tidy"] + +[tasks.test] +description = "Run Tests" +run = "go test -v ./..." + +[tasks.build] +description = "Build" +run = ["go build -o ./bin/sb -ldflags \"-X github.com/aadam-ali/second-brain-cli/config.version=$(git rev-parse --short HEAD)\" main.go"] diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..2a095c0 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SB_INSTALL_DIR=${SB_INSTALL_DIR:-${HOME}/.local/bin} + +get_latest_release() { + curl --silent "https://api.github.com/repos/$1/releases/latest" | jq --raw-output .tag_name +} + +get_architecture() { + case "$(uname -m)" in + aarch64|arm64) + echo "arm64" + ;; + x86_64|amd64) + echo "amd64" + ;; + *) + echo "" + ;; + esac +} + +get_kernel() { + case "$(uname -s)" in + Darwin) + echo "darwin" + ;; + Linux) + echo "linux" + ;; + *) + echo "" + ;; + esac +} + +ARCH=$(get_architecture) +KERNEL=$(get_kernel) + +if [ -z "$ARCH" ]; then + echo 1>&2 "ERROR: Architecture $(uname -m) is not supported." + exit 1 +fi + +if [ -z "$KERNEL" ]; then + echo 1>&2 "ERROR: Kernel $(uname -s) is not supported." + exit 1 +fi + +RELEASE_TAG=$(get_latest_release aadam-ali/second-brain-cli) +TARBALL="sb-${RELEASE_TAG}-${KERNEL}-${ARCH}.tar.gz" +TARBALL_PATH="/tmp/${TARBALL}" +TARBALL_MD5="${TARBALL}.md5" +TARBALL_MD5_PATH="/tmp/${TARBALL_MD5}" + +curl -Lo "${TARBALL_PATH}" "https://github.com/aadam-ali/second-brain-cli/releases/download/${RELEASE_TAG}/${TARBALL}" +curl -Lo "${TARBALL_PATH}.md5" "https://github.com/aadam-ali/second-brain-cli/releases/download/${RELEASE_TAG}/${TARBALL_MD5}" + +echo "$(cat "${TARBALL_MD5_PATH}") ${TARBALL_PATH}" | md5sum -c - + +tar -C "${SB_INSTALL_DIR}" -xzf "${TARBALL_PATH}"