From 1b3be49a2352aa4afa45f7cc6492f2efc7de1ca7 Mon Sep 17 00:00:00 2001 From: richardo2016 Date: Wed, 17 Apr 2024 18:42:54 +0800 Subject: [PATCH] build: fix actions. --- .github/workflows/fns.sh | 73 +++++++++++++++++++++++++++++++ .github/workflows/run-ci.yml | 33 +++++++------- .github/workflows/set-env-vars.sh | 25 +++++++++-- 3 files changed, 110 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/fns.sh diff --git a/.github/workflows/fns.sh b/.github/workflows/fns.sh new file mode 100644 index 0000000..d169ddf --- /dev/null +++ b/.github/workflows/fns.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +vercomp () { + if [[ $1 == $2 ]] + then + return 0 + fi + local IFS=. + local i ver1=($1) ver2=($2) + # fill empty fields in ver1 with zeros + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) + do + ver1[i]=0 + done + for ((i=0; i<${#ver1[@]}; i++)) + do + if [[ -z ${ver2[i]} ]] + then + # fill empty fields in ver2 with zeros + ver2[i]=0 + fi + if ((10#${ver1[i]} > 10#${ver2[i]})) + then + return 1 + fi + if ((10#${ver1[i]} < 10#${ver2[i]})) + then + return 2 + fi + done + return 0 +} + +install_fibjs() { + local version=$1 + if [[ -z "$version" ]]; then + echo "[install_fibjs] version is required" + exit 1 + fi + local os=$2 + if [[ -z "$os" ]]; then + echo "[install_fibjs] os is required" + exit 1 + fi + local arch=$3 + if [[ -z "$arch" ]]; then + echo "[install_fibjs] arch is required" + exit 1 + fi + + local url_base="https://github.com/fibjs/fibjs/releases/download/v${version}/fibjs-v${version}-${os}-${arch}" + + # in fact, for version <= 0.36.0, there's also non-archived linux fibjs + if [[ "$RUNNER_OS" == "Linux" ]]; then + if [ "$lower_than_0_37_0" == "true" ]; then + local remote_url="${url_base}.xz" + curl -SL "$remote_url" -o ./node_modules/.bin/fibjs.xz; + xz -d ./node_modules/.bin/fibjs.xz; + else + local remote_url="${url_base}" + curl -SL "$url_base" -o ./node_modules/.bin/fibjs; + fi + chmod a+x ./node_modules/.bin/fibjs; + elif [[ "$RUNNER_OS" == "macOS" ]]; then + local remote_url="${url_base}" + curl -SL "$remote_url" -o ./node_modules/.bin/fibjs; + chmod a+x ./node_modules/.bin/fibjs; + else + local remote_url="${url_base}.exe" + curl -SL "$remote_url" -o ./node_modules/.bin/fibjs.exe; + fi + echo "[install_fibjs] Downloading fibjs from ${remote_url}" +} diff --git a/.github/workflows/run-ci.yml b/.github/workflows/run-ci.yml index 85a4726..86d9a3a 100644 --- a/.github/workflows/run-ci.yml +++ b/.github/workflows/run-ci.yml @@ -24,19 +24,24 @@ jobs: continue-on-error: true strategy: matrix: - os: + os: + - windows-2019 - ubuntu-20.04 - # since fibjs 0.37.0, windows-2019 not supported - - windows-2022 - macos-11 - version: [0.34.0, 0.35.0, 0.36.0, 0.37.0] + fibjs: [0.34.0, 0.35.0, 0.36.0, 0.37.0] arch: [amd64, i386] exclude: - - os: windows-2022 + - os: windows-2019 arch: i386 - os: macos-11 arch: i386 - + include: + - os: windows-2022 + arch: arm64 + fibjs: 0.37.0 + - os: macos-11 + arch: arm64 + fibjs: 0.37.0 steps: - name: Check out Git repository uses: actions/checkout@v2 @@ -55,26 +60,20 @@ jobs: env: ARCH: ${{ matrix.arch }} OS: ${{ matrix.os }} + FIBJS_VERSION: ${{ matrix.fibjs }} - name: Install FIBJS shell: bash run: | mkdir -p ./node_modules/.bin; rm -rf ./node_modules/.bin/fibjs; - if [[ "$RUNNER_OS" == "Linux" ]]; then - curl -SL "https://github.com/fibjs/fibjs/releases/download/v${FIBJS_VERSION}/fibjs-v${FIBJS_VERSION}-${FIBJS_OS}-${FIBJS_ARCH}.xz" -o ./node_modules/.bin/fibjs.xz; - xz -d ./node_modules/.bin/fibjs.xz; - chmod a+x ./node_modules/.bin/fibjs; - elif [[ "$RUNNER_OS" == "macOS" ]]; then - curl -SL "https://github.com/fibjs/fibjs/releases/download/v${FIBJS_VERSION}/fibjs-v${FIBJS_VERSION}-${FIBJS_OS}-${FIBJS_ARCH}" -o ./node_modules/.bin/fibjs; - chmod a+x ./node_modules/.bin/fibjs; - else - curl -SL "https://github.com/fibjs/fibjs/releases/download/v${FIBJS_VERSION}/fibjs-v${FIBJS_VERSION}-${FIBJS_OS}-${FIBJS_ARCH}.exe" -o ./node_modules/.bin/fibjs.exe; - fi + . ./.github/workflows/fns.sh --source-only + install_fibjs $FIBJS_VERSION $FIBJS_OS $FIBJS_ARCH; env: FIBJS_OS: ${{ steps.set-env-vars.outputs.FIBJS_OS }} FIBJS_ARCH: ${{ steps.set-env-vars.outputs.FIBJS_ARCH }} - FIBJS_VERSION: ${{ matrix.version }} + lower_than_0_37_0: ${{ steps.set-env-vars.outputs.lower_than_0_37_0 }} + FIBJS_VERSION: ${{ matrix.fibjs }} - name: Run CI shell: bash diff --git a/.github/workflows/set-env-vars.sh b/.github/workflows/set-env-vars.sh index 9798ca8..6022b5e 100644 --- a/.github/workflows/set-env-vars.sh +++ b/.github/workflows/set-env-vars.sh @@ -1,3 +1,5 @@ +. ./.github/workflows/fns.sh --source-only + export GIT_BRANCH=${GITHUB_REF#refs/heads/} echo "::set-output name=GIT_BRANCH::$GIT_BRANCH" export GIT_TAG=$(git tag | grep $(git describe --tags HEAD)) @@ -25,9 +27,20 @@ if [ -z "$IS_GIT_TAG_MATCH_SEMVER" ]; then fi echo "::set-output name=RELEASE_TAG::$RELEASE_TAG"; +vercomp "${FIBJS_VERSION}" "0.37.0" +lower_than_0_37_0="false" +[ "$?" -eq "2" ] && lower_than_0_37_0="true" + +echo "::set-output name=lower_than_0_37_0::$lower_than_0_37_0"; + case "${RUNNER_OS}" in Windows) - export FIBJS_OS=windows + # lower than 0.37.0 + if [[ "$lower_than_0_37_0" -eq "true" ]]; then + export FIBJS_OS=windows + else + export FIBJS_OS=win32 + fi ;; macOS) export FIBJS_OS=darwin @@ -43,10 +56,14 @@ esac echo "::set-output name=FIBJS_OS::$FIBJS_OS"; case "${ARCH}" in - i386) - export FIBJS_ARCH=x86 + i386|ia32|x86) + if [[ "$lower_than_0_37_0" -eq "true" ]]; then + export FIBJS_ARCH=x86 + else + export FIBJS_ARCH=ia32 + fi ;; - amd64) + amd64|x64) export FIBJS_ARCH=x64 ;; *)