Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Tencent/bk-job into github_perf/e…
Browse files Browse the repository at this point in the history
…sb_api_normalization
  • Loading branch information
tyleryuwang committed Jul 12, 2021
2 parents b314228 + d4beaa5 commit 20f7822
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 20 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This is a basic workflow to help you get started with Actions

name: Backend CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
paths:
- 'src/backend/**'
pull_request:
branches: [ master, 3.* ]
paths:
- 'src/backend/**'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: init mysql
run: |
sudo /etc/init.d/mysql start
export MYSQL_PWD=root
for i in */*.sql;do echo $i;mysql -h localhost -uroot < $i;done
working-directory: support-files/sql
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache Gradle
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Gradle Build
working-directory: src/backend
run: ./gradlew clean build -DmysqlURL=127.0.0.1:3306 -DmysqlUser=root -DmysqlPasswd=root -DmavenRepoUrl="http://maven.aliyun.com/nexus/content/groups/public/"
27 changes: 27 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Frontend CI

on:
push:
branches: [ master ]
paths:
- 'src/frontend/**'
pull_request:
branches: [ master, 3.* ]
paths:
- 'src/frontend/**'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- run: echo "npm version=$(npm -v)"
- name: build
run: |
export JOB_VERSION=3.latest
npm i && npm run build
working-directory: src/frontend
80 changes: 80 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Tag Realse
on:
push:
tags:
- 'v*'

jobs:
build:
name: Build whole project and release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up variables
id: variables
run: |
tag="$(basename $GITHUB_REF)"
version=${tag##v}
echo "::set-output name=tag::${tag}"
echo "::set-output name=version::${version}"
- name: init mysql
run: |
sudo /etc/init.d/mysql start
export MYSQL_PWD=root
for i in */*.sql;do echo $i;mysql -h localhost -uroot < $i;done
working-directory: support-files/sql
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache Gradle
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Gradle Build Backend
working-directory: src/backend
run: ./gradlew clean build -Dversion=${{ steps.variables.outputs.version }} -DmysqlURL=127.0.0.1:3306 -DmysqlUser=root -DmysqlPasswd=root -DmavenRepoUrl="http://maven.aliyun.com/nexus/content/groups/public/"

- name: Npm Build Frontend
run: |
echo "npm version=$(npm -v)"
export JOB_VERSION=${{ steps.variables.outputs.version }}
npm i && npm run build
mkdir -p release/job/frontend
cp -r dist/* release/job/frontend
working-directory: src/frontend

- name: Build VersionLogs
run: python genBundledVersionLog.py
working-directory: versionLogs

- name: Create artifact - make package
id: create_artifact
run: |
echo ${{ steps.variables.outputs.version }} > ./VERSION
chmod 755 ./package.sh
./package.sh -m all -v ${{ steps.variables.outputs.version }}
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: bk-job ${{ github.ref }}
draft: true
prerelease: true

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./release/job_ce-${{ steps.variables.outputs.version }}.tgz
asset_name: job_ce-${{ steps.variables.outputs.version }}.tgz
asset_content_type: application/gzip
2 changes: 2 additions & 0 deletions src/backend/commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobCommonVersion")) {
set("jobCommonVersion", System.getProperty("jobCommonVersion"))
} else if (System.getProperty("version")) {
set("jobCommonVersion", System.getProperty("version"))
} else {
set("jobCommonVersion", "1.0.0")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
Expand Down Expand Up @@ -85,16 +86,20 @@ public void testCalculateMillsBetweenDateTime() {

@Test
void testConvertFromMillSeconds() {
ZoneId zoneId = ZoneOffset.systemDefault();
String zoneIdStr = zoneId.getId();
System.out.println("systemDefault zoneId=" + zoneIdStr);
long timestamp = 1572766266451L;
LocalDateTime actual = DateUtils.convertFromMillSeconds(timestamp);
assertThat(actual.getYear()).isEqualTo(2019);
assertThat(actual.getMonthValue()).isEqualTo(11);
assertThat(actual.getDayOfMonth()).isEqualTo(3);
assertThat(actual.getHour()).isEqualTo(15);
assertThat(actual.getMinute()).isEqualTo(31);
assertThat(actual.getSecond()).isEqualTo(6);
assertThat(actual.getNano()).isEqualTo(451_000_000);

if ("Asia/Shanghai".equals(zoneIdStr)) {
assertThat(actual.getYear()).isEqualTo(2019);
assertThat(actual.getMonthValue()).isEqualTo(11);
assertThat(actual.getDayOfMonth()).isEqualTo(3);
assertThat(actual.getHour()).isEqualTo(15);
assertThat(actual.getMinute()).isEqualTo(31);
assertThat(actual.getSecond()).isEqualTo(6);
assertThat(actual.getNano()).isEqualTo(451_000_000);
}
}

@Test
Expand Down
2 changes: 2 additions & 0 deletions src/backend/job-analysis/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobAnalysisVersion")) {
set("jobAnalysisVersion", System.getProperty("jobAnalysisVersion"))
} else if (System.getProperty("version")) {
set("jobAnalysisVersion", System.getProperty("version"))
} else {
set("jobAnalysisVersion", "1.0.0")
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/job-backup/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobBackupVersion")) {
set("jobBackupVersion", System.getProperty("jobBackupVersion"))
} else if (System.getProperty("version")) {
set("jobBackupVersion", System.getProperty("version"))
} else {
set("jobBackupVersion", "1.0.0")
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/job-config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobConfigVersion")) {
set("jobConfigVersion", System.getProperty("jobConfigVersion"))
} else if (System.getProperty("version")) {
set("jobConfigVersion", System.getProperty("version"))
} else {
set("jobConfigVersion", "1.0.0")
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/job-crontab/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobCrontabVersion")) {
set("jobCrontabVersion", System.getProperty("jobCrontabVersion"))
} else if (System.getProperty("version")) {
set("jobCrontabVersion", System.getProperty("version"))
} else {
set("jobCrontabVersion", "1.0.0")
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/job-execute/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobExecuteVersion")) {
set("jobExecuteVersion", System.getProperty("jobExecuteVersion"))
} else if (System.getProperty("version")) {
set("jobExecuteVersion", System.getProperty("version"))
} else {
set("jobExecuteVersion", "1.0.0")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

import org.junit.jupiter.api.Test;

import java.time.ZoneId;
import java.time.ZoneOffset;

import static org.assertj.core.api.Assertions.assertThat;

public class MacroUtilTest {
Expand All @@ -34,21 +37,26 @@ void testResolveDate() {
String str = "/tmp/[DATE:yyyy-MM-dd]/test/";
// 2021-01-01 12:01:01
long timestamp = 1609473661000L;
String result = MacroUtil.resolveDate(str, timestamp);
assertThat(result).isEqualTo("/tmp/2021-01-01/test/");
ZoneId zoneId = ZoneOffset.systemDefault();
String zoneIdStr = zoneId.getId();
System.out.println("systemDefault zoneId=" + zoneIdStr);
String result = null;
if ("Asia/Shanghai".equals(zoneIdStr)) {
result = MacroUtil.resolveDate(str, timestamp);
assertThat(result).isEqualTo("/tmp/2021-01-01/test/");

str = "/tmp/[DATE:YYYY-MM-dd]/test/";
result = MacroUtil.resolveDate(str, timestamp);
assertThat(result).isEqualTo("/tmp/2021-01-01/test/");
str = "/tmp/[DATE:YYYY-MM-dd]/test/";
result = MacroUtil.resolveDate(str, timestamp);
assertThat(result).isEqualTo("/tmp/2021-01-01/test/");

str = "/tmp/[DATE:yyyy-MM-dd_HH:mm:ss]/test/";
result = MacroUtil.resolveDate(str, timestamp);
assertThat(result).isEqualTo("/tmp/2021-01-01_12:01:01/test/");

str = "/tmp/[DATE:yyyy-MM-dd]/[DATE:HH:mm:ss]/test/";
result = MacroUtil.resolveDate(str, timestamp);
assertThat(result).isEqualTo("/tmp/2021-01-01/12:01:01/test/");
str = "/tmp/[DATE:yyyy-MM-dd_HH:mm:ss]/test/";
result = MacroUtil.resolveDate(str, timestamp);
assertThat(result).isEqualTo("/tmp/2021-01-01_12:01:01/test/");

str = "/tmp/[DATE:yyyy-MM-dd]/[DATE:HH:mm:ss]/test/";
result = MacroUtil.resolveDate(str, timestamp);
assertThat(result).isEqualTo("/tmp/2021-01-01/12:01:01/test/");
}
str = "/tmp/test/";
result = MacroUtil.resolveDate(str, timestamp);
assertThat(result).isEqualTo("/tmp/test/");
Expand Down
2 changes: 2 additions & 0 deletions src/backend/job-file-gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobFileGatewayVersion")) {
set("jobFileGatewayVersion", System.getProperty("jobFileGatewayVersion"))
} else if (System.getProperty("version")) {
set("jobFileGatewayVersion", System.getProperty("version"))
} else {
set("jobFileGatewayVersion", "1.0.0")
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/job-file-worker-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobFileWorkerSdkVersion")) {
set("jobFileWorkerSdkVersion", System.getProperty("jobFileWorkerSdkVersion"))
} else if (System.getProperty("version")) {
set("jobFileWorkerSdkVersion", System.getProperty("version"))
} else {
set("jobFileWorkerSdkVersion", "1.0.0")
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/job-file-worker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobFileWorkerVersion")) {
set("jobFileWorkerVersion", System.getProperty("jobFileWorkerVersion"))
} else if (System.getProperty("version")) {
set("jobFileWorkerVersion", System.getProperty("version"))
} else {
set("jobFileWorkerVersion", "1.0.0")
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/job-gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobGatewayVersion")) {
set("jobGatewayVersion", System.getProperty("jobGatewayVersion"))
} else if (System.getProperty("version")) {
set("jobGatewayVersion", System.getProperty("version"))
} else {
set("jobGatewayVersion", "1.0.0")
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/job-logsvr/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobLogVersion")) {
set("jobLogVersion", System.getProperty("jobLogVersion"))
} else if (System.getProperty("version")) {
set("jobLogVersion", System.getProperty("version"))
} else {
set("jobLogVersion", "1.0.0")
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/job-manage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobManageVersion")) {
set("jobManageVersion", System.getProperty("jobManageVersion"))
} else if (System.getProperty("version")) {
set("jobManageVersion", System.getProperty("version"))
} else {
set("jobManageVersion", "1.0.0")
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/job-ticket/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ext {
if (System.getProperty("jobTicketVersion")) {
set("jobTicketVersion", System.getProperty("jobTicketVersion"))
} else if (System.getProperty("version")) {
set("jobTicketVersion", System.getProperty("version"))
} else {
set("jobTicketVersion", "1.0.0")
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/upgrader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ plugins {
ext {
if (System.getProperty("jobVersion")) {
set("jobVersion", System.getProperty("jobVersion"))
} else if (System.getProperty("version")) {
set("jobVersion", System.getProperty("version"))
} else {
set("jobVersion", "1.0.0")
}
Expand Down

0 comments on commit 20f7822

Please sign in to comment.