diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95a5c6b5..7608be36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,8 +3,6 @@ name: CI on: push: branches: [master] - release: - types: [created] defaults: run: @@ -14,6 +12,7 @@ jobs: build: runs-on: ubuntu-latest steps: + - name: Checkout source code uses: actions/checkout@v3 with: @@ -27,9 +26,10 @@ jobs: - name: Build env: - BUCKET_NAME: ${{ secrets.BUCKET_NAME }} - QINIU_AK: ${{ secrets.QINIU_AK }} - QINIU_SK: ${{ secrets.QINIU_SK }} + S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} + S3_BUCKET: ${{ secrets.S3_BUCKET }} + S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }} + S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }} run: | yarn install BUILD_MODE=push diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..e202dcd6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,35 @@ +name: Release + +on: + push: + tags: ["**"] + +defaults: + run: + shell: bash + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: latest + cache: yarn + + - name: Build + run: | + yarn install + script/ci-build.sh tag + + - name: Upload asar + uses: actions/upload-artifact@v3 + with: + name: asar + path: build/*.asar diff --git a/script/ci-build.sh b/script/ci-build.sh index 435affbf..e8fb6efd 100755 --- a/script/ci-build.sh +++ b/script/ci-build.sh @@ -1,7 +1,7 @@ #!/bin/bash # environment variables needed: -# BUCKET_NAME QINIU_AK QINIU_SK +# S3_ENDPOINT S3_BUCKET S3_ACCESS_KEY S3_SECRET_KEY # arguments: # - mode: pull_request, push, tag @@ -15,9 +15,7 @@ ARTIFACT_NAME="electron-ncm" PLATFORMS=(linux darwin) VERSION_HASH=$(git rev-parse --short HEAD) PKG_VER="$VERSION_HASH" -QSHELL_VER="v2.12.0" -QSHELL_DIR="node_modules/.cache/qshell" -QSHELL_BIN="$QSHELL_DIR/qshell" +MINIO_CLIENT="node_modules/.bin/minio-client" # functions build_dist() { @@ -46,21 +44,22 @@ build_tar() { done } -qshell_init() { - if [ ! -x "$QSHELL_BIN" ] ; then - curl -Lo "$QSHELL_DIR/qshell.tar.gz" --create-dirs "https://github.com/qiniu/qshell/releases/download/${QSHELL_VER}/qshell-${QSHELL_VER}-linux-amd64.tar.gz" - tar xf "$QSHELL_DIR/qshell.tar.gz" --directory="$QSHELL_DIR" - chmod +x "$QSHELL_BIN" +minio_client_init() { + if [ -z "$S3_ACCESS_KEY" ] || [ -z "$S3_SECRET_KEY" ] ; then + echo "S3_ACCESS_KEY or S3_SECRET_KEY secrets not set" + exit 1 fi - # Usage: qshell account [--overwrite | -w] - "$QSHELL_BIN" account "$QINIU_AK" "$QINIU_SK" default - # Usage: qshell listbucket2 [--prefix | --suffixes ] [--start ] [--max-retry ][--end ] [--readable] [ [-a] -o ] - "$QSHELL_BIN" listbucket2 --readable "$BUCKET_NAME" + if [ ! -x "$MINIO_CLIENT" ] ; then + curl --silent -Lo "$MINIO_CLIENT" --create-dirs --compressed "https://dl.min.io/client/mc/release/linux-amd64/mc" + chmod +x "$MINIO_CLIENT" + fi + "$MINIO_CLIENT" --version + # Usage: mc alias set --api --path + "$MINIO_CLIENT" --quiet alias set artifacts "$S3_ENDPOINT" "$S3_ACCESS_KEY" "$S3_SECRET_KEY" } -qshell_upload() { - # Usage: qshell rput [] [] [] [] - "$QSHELL_BIN" rput "$BUCKET_NAME" "$1" "build/$1" +minio_client_upload() { + "$MINIO_CLIENT" --quiet cp "build/$1" "artifacts/$S3_BUCKET/" } echo "BUILD_MODE=$BUILD_MODE" @@ -81,10 +80,10 @@ push) describe_version build_asar build_tar - qshell_init - qshell_upload "${PKG_NAME}_${PKG_VER}.asar" + minio_client_init + minio_client_upload "${PKG_NAME}_${PKG_VER}.asar" for PLAT in "${PLATFORMS[@]}"; do - qshell_upload "${ARTIFACT_NAME}_${PKG_VER}_${PLAT}.tar.gz" + minio_client_upload "${ARTIFACT_NAME}_${PKG_VER}_${PLAT}.tar.gz" done ;; *)