diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..effff96 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,60 @@ +image: ubuntu:latest + +variables: + REPO_SOURCE: "JunzhouLiu/BILIBILI-HELPER-PRE" # Expect to be at GitHub + PACK_NAME: "BILIBILI-HELPER" + VERSION: "" # tag names from https://github.com/JunzhouLiu/BILIBILI-HELPER-PRE/tags or "latest" to use the latest commit + USE_MAVEN: "" # "TRUE" to force packing using maven when running + CONFIG: "" + # It's not recommended to change the following variables' values + LANGUAGE: "zh_CN:zh" + LANG: "zh_CN.UTF-8" + DEBIAN_FRONTEND: "noninteractive" + +stages: + - run + +run: + stage: run + script: + # CONFIG is necessary + - if [ -z "${CONFIG}" ]; then + echo "Missing variable 'CONFIG'."; + exit 1; + fi + # Install dependencies + - apt-get update && apt-get install openjdk-8-jdk wget locales unzip -y + # Generate locale to resolve the mistaken Chinese code when pushing messages + - locale-gen zh_CN.UTF-8 + # Get the latest version number if not specify VERSION + - if [ -z "${VERSION}" ]; then + VERSION=`wget -O - "https://api.github.com/repos/${REPO_SOURCE}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'`; + fi + - echo "Package ${PACK_NAME} Uses Version ${VERSION}, Source from https://github.com/${REPO_SOURCE}." + # If possible, directly get the latest release package from GitHub + - if [ ! "${USE_MAVEN}" = "TRUE" ] && [ ! "${VERSION}" = "latest" ]; then + mkdir -p "/tmp/release"; + if wget -O "/tmp/release/${PACK_NAME}.zip" "https://github.com/${REPO_SOURCE}/releases/download/${VERSION}/${PACK_NAME}-${VERSION}.zip"; then + if unzip -o "/tmp/release/${PACK_NAME}.zip" -d "/tmp/release"; then + if [ ! -z "`ls /tmp/release/${PACK_NAME}-*.jar 2> /dev/null`" ]; then + mv -f /tmp/release/${PACK_NAME}-*.jar .; + fi; + fi; + fi; + fi + # Otherwise, pack the jar file using maven + - if [ -z "`ls ${PACK_NAME}-*.jar 2> /dev/null`" ]; then + apt-get install git maven -y; + git clone https://github.com/${REPO_SOURCE} repo; + cd repo; + if [ ! "${VERSION}" = "latest" ]; then + git reset --hard ${VERSION}; + fi; + mvn -B package --file pom.xml -Dmaven.test.skip=true; + mv -f target/${PACK_NAME}-*.jar ..; + cd ..; + fi + # Export the config from environment variable to file + - echo ${CONFIG} > config.json + # Start running + - java -jar ${PACK_NAME}-*.jar diff --git a/README.md b/README.md index d5d35a7..279ce74 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ BILIBILI-HELPER - [一、快速使用](#一快速使用) - [二、使用 Docker](#二使用-docker) - [三、使用 腾讯云函数](#三使用-腾讯云函数) + - [四、使用 GitLab CI/CD](#四使用-gitlab-cicd) - [自定义功能配置](#自定义功能配置) - [配置文件参数](#配置文件参数) - [免责声明](#免责声明) @@ -102,6 +103,10 @@ ps :需要本地有 java8 执行环境。 请参考[腾讯云函数部署](https://github.com/JunzhouLiu/BILIBILI-HELPER-PRE/blob/main/docs/scf.md) +### 四、使用 GitLab CI/CD + +请参考[GitLab CI/CD 部署](docs/gitlab.md) + ### 自定义功能配置 配置文件示例: diff --git a/docs/IMG/gitlab/0.png b/docs/IMG/gitlab/0.png new file mode 100644 index 0000000..211294e Binary files /dev/null and b/docs/IMG/gitlab/0.png differ diff --git a/docs/IMG/gitlab/1.png b/docs/IMG/gitlab/1.png new file mode 100644 index 0000000..f958014 Binary files /dev/null and b/docs/IMG/gitlab/1.png differ diff --git a/docs/IMG/gitlab/2.png b/docs/IMG/gitlab/2.png new file mode 100644 index 0000000..04eae9f Binary files /dev/null and b/docs/IMG/gitlab/2.png differ diff --git a/docs/IMG/gitlab/3.png b/docs/IMG/gitlab/3.png new file mode 100644 index 0000000..99b12e3 Binary files /dev/null and b/docs/IMG/gitlab/3.png differ diff --git a/docs/IMG/gitlab/4.png b/docs/IMG/gitlab/4.png new file mode 100644 index 0000000..35acd1f Binary files /dev/null and b/docs/IMG/gitlab/4.png differ diff --git a/docs/IMG/gitlab/5.png b/docs/IMG/gitlab/5.png new file mode 100644 index 0000000..5f6f2ed Binary files /dev/null and b/docs/IMG/gitlab/5.png differ diff --git a/docs/IMG/gitlab/6.png b/docs/IMG/gitlab/6.png new file mode 100644 index 0000000..d5af935 Binary files /dev/null and b/docs/IMG/gitlab/6.png differ diff --git a/docs/IMG/gitlab/7.png b/docs/IMG/gitlab/7.png new file mode 100644 index 0000000..de42626 Binary files /dev/null and b/docs/IMG/gitlab/7.png differ diff --git a/docs/gitlab.md b/docs/gitlab.md new file mode 100644 index 0000000..ee96e06 --- /dev/null +++ b/docs/gitlab.md @@ -0,0 +1,111 @@ +## 使用 GitLab CI/CD 部署教程 + +### 1. 创建仓库 + +如果你还没有GitLab账号请先注册。 + +首先访问GitLab,[创建一个空白项目](https://gitlab.com/projects/new#blank_project)。(公开或私有都可) + +### 2. 变量配置 + +![](IMG/gitlab/1.png) +在你刚刚创建的空白项目页面中,依次按上图序号点击,进行变量的配置。 + +环境变量: + +| key | 必须 | value | +| ------------- | ---- | --------------------------------------------------------------------------------------- | +| `CONFIG` | 是 | `复制下方完整的config样例,填好对应的值,直接复制粘贴即可,值的具体含义可在项目READEME查看。` | +| `VERSION` | 否 | `不填或空自动使用最新发布版本;如指定,则填写对应tag号;如使用仓库中最新commit,请填写latest。` | +| `USE_MAVEN` | 否 | `值为TRUE时强制每次都打包;其他值或不填首先会尝试从GitHub仓库release中下载zip包,失败则打包。` | +| `REPO_SOURCE` | 否 | `必为GitHub仓库,不填或空默认为本仓库(JunzhouLiu/BILIBILI-HELPER-PRE),格式为 ID/仓库名。` | + +**config 样例** + +```json +{ + "biliVerify": { + "biliCookies": "你的bilibili cookies,完整的cookies获取方法见项目README" + }, + "taskConfig": { + "skipDailyTask": false, + "matchGame": false, + "showHandModel": false, + "predictNumberOfCoins": 1, + "minimumNumberOfCoins": 100, + "taskIntervalTime": 20, + "numberOfCoins": 5, + "reserveCoins": 10, + "selectLike": 0, + "monthEndAutoCharge": true, + "giveGift": true, + "silver2Coin": true, + "upLive": "0", + "chargeForLove": "14602398", + "chargeDay": 8, + "devicePlatform": "ios", + "coinAddPriority": 1, + "userAgent": "你的默认UA" + }, + "pushConfig": { + "SC_KEY": "", + "SCT_KEY": "", + "TG_BOT_TOKEN": "", + "TG_USER_ID": "", + "TG_USE_CUSTOM_URL": false, + "DING_TALK_URL": "", + "DING_TALK_SECRET": "", + "PUSH_PLUS_TOKEN": "", + "WE_COM_GROUP_TOKEN": "", + "WE_COM_APP_CORPID": "", + "WE_COM_APP_CORP_SECRET": "", + "WE_COM_APP_AGENT_ID": 0, + "WE_COM_APP_TO_USER": "", + "WE_COM_APP_MEDIA_ID": "", + "PROXY_HTTP_HOST": "", + "PROXY_SOCKET_HOST": "", + "PROXY_PORT": 0 + } +} +``` + +**如果不知道自己的 UA 之类数据,以及看不懂每个值的含义,可以[点击进入配置自动生成页面](https://utils.misec.top/index) 此页面暂不支持生成 v2.0.0 的配置** + +![](IMG/gitlab/2.png) + +完成后界面如下图所示: +![](IMG/gitlab/3.png) + +### 3. 配置 CI/CD 流水线 + +![](IMG/gitlab/0.png) +依次按上图序号点击,创建一个新的 CI/CD 流水线。 + +如果你希望 CI/CD 流水线内容始终跟随[上游](https://github.com/JunzhouLiu/BILIBILI-HELPER-PRE),直接将以下内容复制覆盖粘贴到编辑器中。 + +```yaml +include: + - remote: 'https://github.com/JunzhouLiu/BILIBILI-HELPER-PRE/raw/main/.gitlab-ci.yml' +``` + +如果你希望自定义 CI/CD 流水线,可以将本仓库中[.gitlab-ci.yml](https://github.com/JunzhouLiu/BILIBILI-HELPER-PRE/blob/main/.gitlab-ci.yml)文件内容复制覆盖粘贴到编辑器中,随后自定义。 + +确保编辑后的工作流显示`此GitLab CI配置有效`,随后点击页面下方`提交更改`。 + +之后会提示`您的更改已成功提交`,并自动触发一次流水线运行,你可以点击`查看流水线`查询流水线运行日志。 + +![](IMG/gitlab/4.png) + +最终流水线提示`已通过`,并一切按配置正常工作,则成功。否则请检查上述操作中是否有疏漏之处。 + +### 4. 配置定时运行 + +![](IMG/gitlab/5.png) +依次按上图序号点击,创建一个新的流水线计划。 + +随后按下图说明创建: +![](IMG/gitlab/6.png) + +创建成功,可查看你刚刚配置完成的流水线计划,下一次运行的时间等。点击右方最左边▶️按钮还可以立即触发一次流水线运行。 + +![](IMG/gitlab/7.png)