-
Notifications
You must be signed in to change notification settings - Fork 54
/
.gitlab-ci.yml
111 lines (106 loc) · 4 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
image: ubuntu:latest
variables:
REPO_SOURCE: "OreosLab/bili" # 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
BUILD_BRANCH: "" # Empty to be the default branch
CONFIG: ""
# It's not recommended to change the following variables' values
MAVEN_OPTS: "-Dmaven.test.skip=true -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
LANGUAGE: "zh_CN:zh"
LANG: "zh_CN.UTF-8"
DEBIAN_FRONTEND: "noninteractive"
cache:
# Keep cache across branch
key: "$CI_JOB_NAME"
paths:
- .m2/repository
- .apt
- repo_backup
- jar_backup
stages:
- run
before_script:
# CONFIG is necessary
- if [ -z "${CONFIG}" ]; then
echo "Missing variable 'CONFIG'.";
exit 1;
fi
run:
only:
- schedules
stage: run
script:
# Configure apt caching
- export APT_DIR=$CI_PROJECT_DIR/.apt && export APT_STATE_LISTS=$APT_DIR/lists && export APT_CACHE_ARCHIVES=$APT_DIR/archives
- printf "dir::state::lists ${APT_STATE_LISTS};\ndir::cache::archives ${APT_CACHE_ARCHIVES};\n" > /etc/apt/apt.conf
- mkdir -p "${APT_STATE_LISTS}/partial" && mkdir -p "${APT_CACHE_ARCHIVES}/partial"
# 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 get failed use latest
- if [ -z "${VERSION}" ]; then
if wget -O "/tmp/version" "https://api.github.com/repos/${REPO_SOURCE}/releases/latest"; then
VERSION=`cat /tmp/version | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'`;
else
VERSION="latest";
fi;
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 get upstream failed use cached
- if [ -z "`ls ${PACK_NAME}-*.jar 2> /dev/null`" ]; then
apt-get install git -y;
if git clone https://github.com/${REPO_SOURCE} repo; then
rm -rf repo_backup;
cp -r repo repo_backup;
else
echo "Warning... Upstream Unavailable, Using Cached Repo or Jar...";
if [ -d "repo_backup" ]; then
cp -r repo_backup repo;
fi;
fi;
if [ -d "repo" ]; then
cd repo;
if [ ! -z "${BUILD_BRANCH}" ]; then
git checkout ${BUILD_BRANCH};
fi;
if [ ! "${VERSION}" = "latest" ]; then
git reset --hard ${VERSION};
fi;
apt-get install maven -y;
mvn -B package --file pom.xml;
mv -f target/${PACK_NAME}-*.jar ..;
cd ..;
else
if [ ! -z "`ls jar_backup/${PACK_NAME}-*.jar 2> /dev/null`" ]; then
cp jar_backup/${PACK_NAME}-*.jar .;
else
echo "Both Upstream and Cached Repo or Jar are Unavailable!";
exit 1;
fi;
fi;
fi
# Export the config from environment variable to file
- echo ${CONFIG} > config.json
# Start running
- java -jar ${PACK_NAME}-*.jar
# Backup jar file
- mkdir -p jar_backup
- rm -rf jar_backup/*
- cp ${PACK_NAME}-*.jar jar_backup/
artifacts:
paths:
- "*.jar"