diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 0000000000..c70f8b181e --- /dev/null +++ b/.github/workflows/backend.yml @@ -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/" diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml new file mode 100644 index 0000000000..4f92e912cb --- /dev/null +++ b/.github/workflows/frontend.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..5fdf62417b --- /dev/null +++ b/.github/workflows/release.yml @@ -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 diff --git a/src/backend/commons/build.gradle b/src/backend/commons/build.gradle index 06ecd5b4a5..b100261dc9 100644 --- a/src/backend/commons/build.gradle +++ b/src/backend/commons/build.gradle @@ -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") } diff --git a/src/backend/commons/common/src/test/java/com/tencent/bk/job/common/util/date/DateUtilTest.java b/src/backend/commons/common/src/test/java/com/tencent/bk/job/common/util/date/DateUtilTest.java index c97d1806df..19057c2842 100644 --- a/src/backend/commons/common/src/test/java/com/tencent/bk/job/common/util/date/DateUtilTest.java +++ b/src/backend/commons/common/src/test/java/com/tencent/bk/job/common/util/date/DateUtilTest.java @@ -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; @@ -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 diff --git a/src/backend/job-analysis/build.gradle b/src/backend/job-analysis/build.gradle index 5fc624cba9..1b35003490 100644 --- a/src/backend/job-analysis/build.gradle +++ b/src/backend/job-analysis/build.gradle @@ -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") } diff --git a/src/backend/job-backup/build.gradle b/src/backend/job-backup/build.gradle index b52153f72e..865a2ea854 100644 --- a/src/backend/job-backup/build.gradle +++ b/src/backend/job-backup/build.gradle @@ -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") } diff --git a/src/backend/job-config/build.gradle b/src/backend/job-config/build.gradle index 1cd2c9b9dd..ab77808017 100644 --- a/src/backend/job-config/build.gradle +++ b/src/backend/job-config/build.gradle @@ -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") } diff --git a/src/backend/job-crontab/build.gradle b/src/backend/job-crontab/build.gradle index e52a27f88c..8afb9ed663 100644 --- a/src/backend/job-crontab/build.gradle +++ b/src/backend/job-crontab/build.gradle @@ -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") } diff --git a/src/backend/job-execute/build.gradle b/src/backend/job-execute/build.gradle index 6634c005f3..ddd6de0c7f 100644 --- a/src/backend/job-execute/build.gradle +++ b/src/backend/job-execute/build.gradle @@ -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") } diff --git a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/util/MacroUtilTest.java b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/util/MacroUtilTest.java index 3bce4e6390..b7b15bf4ce 100644 --- a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/util/MacroUtilTest.java +++ b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/util/MacroUtilTest.java @@ -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 { @@ -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/"); diff --git a/src/backend/job-file-gateway/build.gradle b/src/backend/job-file-gateway/build.gradle index 9d10893555..121b3e6475 100644 --- a/src/backend/job-file-gateway/build.gradle +++ b/src/backend/job-file-gateway/build.gradle @@ -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") } diff --git a/src/backend/job-file-worker-sdk/build.gradle b/src/backend/job-file-worker-sdk/build.gradle index 552871b9b7..626253faa1 100644 --- a/src/backend/job-file-worker-sdk/build.gradle +++ b/src/backend/job-file-worker-sdk/build.gradle @@ -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") } diff --git a/src/backend/job-file-worker/build.gradle b/src/backend/job-file-worker/build.gradle index 86707533a7..3442be5a84 100644 --- a/src/backend/job-file-worker/build.gradle +++ b/src/backend/job-file-worker/build.gradle @@ -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") } diff --git a/src/backend/job-gateway/build.gradle b/src/backend/job-gateway/build.gradle index f01e54c7d8..7de4a162cc 100644 --- a/src/backend/job-gateway/build.gradle +++ b/src/backend/job-gateway/build.gradle @@ -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") } diff --git a/src/backend/job-logsvr/build.gradle b/src/backend/job-logsvr/build.gradle index e09f019080..27c12e5c4a 100644 --- a/src/backend/job-logsvr/build.gradle +++ b/src/backend/job-logsvr/build.gradle @@ -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") } diff --git a/src/backend/job-manage/build.gradle b/src/backend/job-manage/build.gradle index b5f5d3622e..e32dfbae1d 100644 --- a/src/backend/job-manage/build.gradle +++ b/src/backend/job-manage/build.gradle @@ -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") } diff --git a/src/backend/job-ticket/build.gradle b/src/backend/job-ticket/build.gradle index 44130e7cc8..816bec307b 100644 --- a/src/backend/job-ticket/build.gradle +++ b/src/backend/job-ticket/build.gradle @@ -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") } diff --git a/src/backend/upgrader/build.gradle b/src/backend/upgrader/build.gradle index 45cd21d468..49e88b98b6 100644 --- a/src/backend/upgrader/build.gradle +++ b/src/backend/upgrader/build.gradle @@ -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") }