From 264f549c13a4c604d08542635a846f750d512b6b Mon Sep 17 00:00:00 2001 From: zyf722 Date: Wed, 4 Sep 2024 13:38:08 +0800 Subject: [PATCH] feat(action): Add Windows support to actions --- .github/workflows/test-action.yml | 12 ++++++++++-- action/entrypoint.sh | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index ea047f53a..c0249bd69 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -6,12 +6,16 @@ jobs: name: Spell Check with Typos strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - name: Checkout Actions Repository uses: actions/checkout@v4 + - name: Install wget for Windows + if: matrix.os == 'windows-latest' + run: choco install wget --no-progress + - name: Prepare file with mistakes. run: echo "Finallizes" > file.txt - name: Test force pass with mistakes @@ -31,7 +35,7 @@ jobs: name: Spell Check with Type w/History strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - name: Checkout Actions Repository @@ -39,6 +43,10 @@ jobs: with: fetch-depth: 0 + - name: Install wget for Windows + if: matrix.os == 'windows-latest' + run: choco install wget --no-progress + - name: Prepare file with mistakes. run: echo "Finallizes" > file.txt - name: Test force pass with mistakes diff --git a/action/entrypoint.sh b/action/entrypoint.sh index 875cc6ae2..9a14d2774 100755 --- a/action/entrypoint.sh +++ b/action/entrypoint.sh @@ -27,16 +27,26 @@ if [[ ! -x ${COMMAND} ]]; then else ARCH="x86_64" fi - if [[ "$(uname -s)" == "Darwin" ]]; then + UNAME=$(uname -s) + if [[ "$UNAME" == "Darwin" ]]; then TARGET_FILE="${ARCH}-apple-darwin" + FILE_EXT="tar.gz" + elif [[ "$UNAME" == CYGWIN* || "$UNAME" == MINGW* || "$UNAME" == MSYS* ]] ; then + TARGET_FILE="${ARCH}-pc-windows-msvc" + FILE_EXT="zip" else TARGET_FILE="${ARCH}-unknown-linux-musl" + FILE_EXT="tar.gz" fi - FILE_NAME="typos-v${VERSION}-${TARGET_FILE}.tar.gz" + FILE_NAME="typos-v${VERSION}-${TARGET_FILE}.${FILE_EXT}" log "Downloading 'typos' v${VERSION}" wget --progress=dot:mega "https://github.com/crate-ci/typos/releases/download/v${VERSION}/${FILE_NAME}" mkdir -p ${_INSTALL_DIR} - tar -xzvf "${FILE_NAME}" -C ${_INSTALL_DIR} ./${CMD_NAME} + if [[ "$FILE_EXT" == "zip" ]]; then + unzip -o "${FILE_NAME}" -d ${_INSTALL_DIR} ${CMD_NAME}.exe + else + tar -xzvf "${FILE_NAME}" -C ${_INSTALL_DIR} ./${CMD_NAME} + fi rm "${FILE_NAME}" fi log "jq: $(jq --version)"