Skip to content

Commit

Permalink
build: migrate from travis-ci to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rocka committed Jul 7, 2023
1 parent 34a553c commit daf698c
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 63 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
push:
branches: [master]
release:
types: [created]

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
env:
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
QINIU_AK: ${{ secrets.QINIU_AK }}
QINIU_SK: ${{ secrets.QINIU_SK }}
run: |
yarn install
BUILD_MODE=push
if [[ "$GITHUB_REF_TYPE" == "tag" ]]; then
BUILD_TYPE=tag
fi
script/ci-build.sh "$BUILD_MODE"
- name: Upload asar
uses: actions/upload-artifact@v3
with:
name: asar
path: build/*.asar
34 changes: 34 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Pull Request

on:
pull_request:

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 pull_request
- name: Upload asar
uses: actions/upload-artifact@v3
with:
name: asar
path: build/*.asar
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

58 changes: 30 additions & 28 deletions script/travis-ci.sh → script/ci-build.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
#!/bin/bash

# environment variables needed:
# BUCKET_NAME QINIU_AK QINIU_SK

# arguments:
# - mode: pull_request, push, tag

BUILD_MODE="${1:-push}"

# variables
APP_NAME="Electron NCM"
PKG_NAME="electron-netease-cloud-music"
ARTIFACT_NAME="electron-ncm"
PLATFORMS=(linux darwin)
BUCKET_NAME="electron-ncm-ci"
VERSION_HASH="${TRAVIS_COMMIT:0:7}"
VERSION_HASH=$(git rev-parse --short HEAD)
PKG_VER="$VERSION_HASH"
QSHELL_VER="v2.4.1"
QSHELL_DIR="node_modules/.cache/qshell/$QSHELL_VER"
QSHELL_BIN="$QSHELL_DIR/bin/qshell-linux-x64-$QSHELL_VER"
QSHELL_VER="v2.12.0"
QSHELL_DIR="node_modules/.cache/qshell"
QSHELL_BIN="$QSHELL_DIR/qshell"

# functions
build_dist() {
Expand All @@ -33,16 +40,16 @@ build_asar() {
}

build_tar() {
for PLAT in ${PLATFORMS[*]}; do
for PLAT in "${PLATFORMS[@]}"; do
yarn run build "$PLAT"
tar zcf "build/${ARTIFACT_NAME}_${PKG_VER}_${PLAT}.tar.gz" -C build "${APP_NAME}-${PLAT}-x64"
done
}

qshell_init() {
if [ ! -x "$QSHELL_BIN" ] ; then
curl -Lo "$QSHELL_DIR/qshell.zip" --create-dirs "http://devtools.qiniu.com/qshell-linux-x64-${QSHELL_VER}.zip"
unzip "$QSHELL_DIR/qshell.zip" -d "$QSHELL_DIR/bin"
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"
fi
# Usage: qshell account [--overwrite | -w]<Your AccessKey> <Your SecretKey> <Your Account Name>
Expand All @@ -56,37 +63,32 @@ qshell_upload() {
"$QSHELL_BIN" rput "$BUCKET_NAME" "$1" "build/$1"
}

transfer_sh_upload() {
local TRANSFER_TMP
TRANSFER_TMP=$(mktemp)
echo "Uploading '$1' to transfer.sh ..."
curl --upload-file "build/$1" "https://transfer.sh/$1" -o "$TRANSFER_TMP"
echo "Got URL:"
cat "$TRANSFER_TMP"
echo ""
rm -r "$TRANSFER_TMP"
}
echo "BUILD_MODE=$BUILD_MODE"

# entrypoint
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
# build is triggered by a pull request
case "$BUILD_MODE" in
pull_request)
build_dist
describe_version
build_asar
transfer_sh_upload "${PKG_NAME}_${PKG_VER}.asar"
elif [ "$TRAVIS_BRANCH" == "$TRAVIS_TAG" ]; then
# build is triggered by a git tag
PKG_VER="$TRAVIS_TAG"
;;
tag)
PKG_VER=$(git describe --tags --abbrev=0)
build_dist
build_asar
else
;;
push)
build_dist
describe_version
build_asar
build_tar
qshell_init
qshell_upload "${PKG_NAME}_${PKG_VER}.asar"
for PLAT in ${PLATFORMS[*]}; do
for PLAT in "${PLATFORMS[@]}"; do
qshell_upload "${ARTIFACT_NAME}_${PKG_VER}_${PLAT}.tar.gz"
done
fi
;;
*)
echo "unknown build mode: '$BUILD_MODE'"
exit 1
;;
esac
4 changes: 2 additions & 2 deletions script/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ if (argv.length === 0) {
process.argv = process.argv.slice(0, 2);
}

// yeah! patch packages!
cp.execSync('patch-packages');
// yeah! patch package!
cp.execSync('patch-package');

process.env.NODE_ENV = 'production';

Expand Down

0 comments on commit daf698c

Please sign in to comment.