diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index eb99c75..048267a 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -1,11 +1,2 @@ # Automatically delete head branches after merging PRs. Defaults to `true`. deleteBranchOnMerge: true - -# Rules for branch protection (add multiple entries to configure multiple branches) -branchProtectionRules: - # Identifies the protection rule pattern. Name of the branch to be protected. - # Defaults to `master` - - pattern: main - # Number of approving reviews required to update matching branches. - # Defaults to `1` - requiredApprovingReviewCount: 0 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 101aa9c..4229525 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,45 +15,6 @@ PYTHON_VERSION: "3.11" jobs: - detect-build: - name: Detect Build Script - runs-on: ubuntu-latest - outputs: - build: ${{ steps.detect.outputs.build }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - id: detect - name: Detect Build Script - run: | - if [[ -f scripts/build.sh ]]; then - echo "build=true" >> "${GITHUB_OUTPUT}" - echo ":heavy_check_mark: Build Script Detected" >> "${GITHUB_STEP_SUMMARY}" - else - echo "build=false" >> "${GITHUB_OUTPUT}" - echo ":x: Build Script Not Found" >> "${GITHUB_STEP_SUMMARY}" - fi - - detect-publish: - name: Detect PyPI Credential - runs-on: ubuntu-latest - outputs: - publish: ${{ steps.detect.outputs.publish }} - steps: - - id: detect - name: Detect PyPI Credential - run: | - if [[ -n "${PYPI_USERNAME}" && -n "${PYPI_PASSWORD}" ]]; then - echo "publish=true" >> "${GITHUB_OUTPUT}" - echo ":heavy_check_mark: PyPI Credential Detected" >> "${GITHUB_STEP_SUMMARY}" - else - echo "publish=false" >> "${GITHUB_OUTPUT}" - echo ":x: PyPI Credential Not Found" >> "${GITHUB_STEP_SUMMARY}" - fi - env: - PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} - PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - build-pkg: name: Build Package runs-on: ubuntu-latest @@ -98,13 +59,10 @@ - name: Install Dependencies run: poetry install --no-interaction - name: Build Executable - run: poetry run bash scripts/build.sh - - if: runner.os != 'Windows' - name: Rename Build Artifact - run: mv dist/* "dist/${{ github.event.repository.name }}-${{ runner.os }}-${{ runner.arch }}" - - if: runner.os == 'Windows' - name: Rename Build Artifact - run: mv dist/* "dist/${{ github.event.repository.name }}-${{ runner.os }}-${{ runner.arch }}.exe" + run: poetry run make rename + env: + RUNNER_OS: ${{ runner.os }} + RUNNER_ARCH: ${{ runner.arch }} - name: Upload Build Artifact uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/license.yaml b/.github/workflows/license.yaml index e690d61..9767db7 100644 --- a/.github/workflows/license.yaml +++ b/.github/workflows/license.yaml @@ -1,16 +1,22 @@ -name: Update Copyright Year(s) in License File +name: Update LICENSE Copyright Year(s) on: schedule: - - cron: "0 3 1 1 *" # 03:00 AM on January 1 + - cron: 0 3 1 1 * # 03:00 AM on January 1 + +permissions: + contents: write jobs: - update-license-year: + license: + name: Update LICENSE Copyright Year(s) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: FantasticFiasco/action-update-license-year@v2 + - name: Update LICENSE Copyright Year + uses: FantasticFiasco/action-update-license-year@v2 with: token: ${{ github.token }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5c89d79..af468de 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ hooks: - id: commitizen - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v3.0.0-alpha.4" + rev: "v3.0.0-alpha.5" hooks: - id: prettier stages: @@ -24,7 +24,6 @@ - id: check-yaml - id: destroyed-symlinks - id: end-of-file-fixer - exclude: requirements.txt - id: mixed-line-ending - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..07b7be8 --- /dev/null +++ b/Makefile @@ -0,0 +1,42 @@ +BIN := $(HOME)/.local/bin +DIST := $(CURDIR)/dist +NAME := thu-learn-downloader + +OS != echo $(RUNNER_OS) | tr '[:upper:]' '[:lower:]' +ARCH != echo $(RUNNER_ARCH) | tr '[:upper:]' '[:lower:]' +ifeq ($(OS), windows) + EXE := .exe +else + EXE := +endif + +TARGET := $(DIST)/$(NAME)$(EXE) + +.PHONY: build +build: + pyinstaller --distpath $(DIST) --onefile --name $(NAME) $(CURDIR)/main.py + +clean: + $(RM) --recursive $(CURDIR)/build + $(RM) --recursive $(CURDIR)/outputs + $(RM) --recursive $(DIST) + $(RM) $(CURDIR)/*.spec + +demo: +ifeq ($(BW_SESSION),) + $(error Bitwarden Locked) +else + vhs < $(CURDIR)/demo.tape +endif + +install: build + install --target-directory=$(BIN) $(TARGET) + +pretty: + isort --profile black $(CURDIR) + black $(CURDIR) + +rename: build +ifneq ($(and $(OS), $(ARCH)), ) + mv $(TARGET) $(DIST)/$(NAME)-$(OS)-$(ARCH)$(EXE) +endif diff --git a/entry_point.py b/entry_point.py deleted file mode 100644 index 5078d73..0000000 --- a/entry_point.py +++ /dev/null @@ -1,4 +0,0 @@ -from thu_learn_downloader.__main__ import main - -if __name__ == "__main__": - main() diff --git a/main.py b/main.py new file mode 100644 index 0000000..5078d73 --- /dev/null +++ b/main.py @@ -0,0 +1,4 @@ +from thu_learn_downloader.__main__ import main + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml index b2153b4..46f11dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ authors = ["Qin Li "] description = "Download everything from Web Learning of Tsinghua University" name = "thu-learn-downloader" -packages = [{include = "thu_learn_downloader"}] +packages = [{ include = "thu_learn_downloader" }] readme = "README.md" repository = "https://github.com/liblaf/thu-learn-downloader" version = "0.1.5" @@ -23,3 +23,6 @@ [tool.poetry.group.dev.dependencies] pyinstaller = "^5.8.0" + +[tool.poetry.scripts] +thu-learn-downloader = "thu_learn_downloader.__main__:main" diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100644 index 9157642..0000000 --- a/scripts/build.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -set -o errexit -set -o nounset -set -o pipefail - -function run() { - if command -v gum > /dev/null 2>&1; then - prefix="$(gum style --background=14 --padding="0 1" RUN)" - message="$(gum style --foreground=14 "${*}")" - gum join --horizontal "${prefix}" " " "${message}" - fi - "${@}" -} - -workspace="$(git rev-parse --show-toplevel || pwd)" -cd "${workspace}" -name="$(poetry version | awk '{ print $1 }')" - -run poetry install --with dev -run poetry run pyinstaller --onefile --name "${name}" "${workspace}/entry_point.py" diff --git a/scripts/format.sh b/scripts/format.sh deleted file mode 100644 index e6a644c..0000000 --- a/scripts/format.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -set -o errexit -set -o nounset -set -o pipefail - -function run() { - if command -v gum > /dev/null 2>&1; then - prefix="$(gum style --background=14 --padding="0 1" RUN)" - message="$(gum style --foreground=14 "${*}")" - gum join --horizontal "${prefix}" " " "${message}" - fi - "${@}" -} - -workspace="$(git rev-parse --show-toplevel || pwd)" - -run isort --profile black "${workspace}" -run black "${workspace}" diff --git a/scripts/install.sh b/scripts/install.sh deleted file mode 100644 index 8d6621d..0000000 --- a/scripts/install.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -set -o errexit -set -o nounset -set -o pipefail - -BIN="${BIN:-"${HOME}/.local/bin"}" - -function run() { - if command -v gum > /dev/null 2>&1; then - prefix="$(gum style --background=14 --padding="0 1" RUN)" - message="$(gum style --foreground=14 "${*}")" - gum join --horizontal "${prefix}" " " "${message}" - fi - "${@}" -} - -function copy() { - mkdir --parents "$(dirname "${2}")" - cp "${1}" "${2}" - if command -v gum > /dev/null 2>&1; then - prefix="$(gum style --background=10 --padding="0 1" COPY)" - message="$(gum style --foreground=10 "${1} -> ${2}")" - gum join --horizontal "${prefix}" " " "${message}" - fi -} - -workspace="$(git rev-parse --show-toplevel || pwd)" -cd "${workspace}" -name="$(poetry version | awk '{ print $1 }')" - -run bash "${workspace}/scripts/build.sh" -copy "${workspace}/dist/${name}" "${BIN}/${name}"