From 10a651cab40566673f9ec3f84013b88952e8d993 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Tue, 20 Feb 2024 23:27:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5CI-CD=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yml | 42 ++++++++++++++++++++++++++++++++++++ .github/workflows/main.yml | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 .gitea/workflows/build.yml create mode 100644 .github/workflows/main.yml diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..687c001 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,42 @@ +name: Java CI-CD with Maven + +on: + push: + tags: + - '*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: "Pull & Checkout" + uses: https://ssl.lunadeer.cn:14446/actions/checkout@v3 + with: + fetch-depth: 0 + - name: "Set up Maven" + uses: https://ssl.lunadeer.cn:14446/actions/setup-maven@v4 + - name: "Set up JDK 17" + uses: https://ssl.lunadeer.cn:14446/actions/setup-java@v3 + with: + java-version: '17' + distribution: 'zulu' + cache: maven + - name: "Build with Maven" + run: mvn -B package --file pom.xml + - name: "Copy jar to staging" + run: mkdir staging && cp target/*.jar staging + - name: "Build & test" + run: | + echo "done!" + - name: "setup go for release script" + run: | + wget --no-check-certificate https://go.dev/dl/go1.21.6.linux-amd64.tar.gz + rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz + ln -s /usr/local/go/bin/go /usr/bin/go + go version + - name: "Release" + uses: https://ssl.lunadeer.cn:14446/actions/release-action@main + with: + files: |- + staging/*.jar + api_key: '${{secrets.RELEASE_TOKEN}}' \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c7d46da --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,44 @@ +name: Java CI with Maven + +# 检测到 src 文件内 .java 文件有变动执行编译 +on: + push: + paths: + - '**/*src/**/*.java' + +jobs: + build: +# 配置权限 + permissions: write-all + runs-on: ubuntu-latest + steps: +# 下载代码 + - uses: actions/checkout@v3 + - name: Set up JDK 17 +# 安装 JDK + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven +# Maven 打包 + - name: Build with Maven + run: mvn -B package --file pom.xml +# 将打包好的 Jar 包 放到 staging 文件夹 + - run: mkdir staging && cp target/*.jar staging +# 设置 jobs Maven pom 版本环境变量 + - name: Set Release version env variable + run: | + echo "RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV + - name: "Build & test" + run: | + echo "done!" +# 上传文件并发布 Release + - uses: "marvinpinto/action-automatic-releases@latest" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: "${{ env.RELEASE_VERSION }}" + prerelease: false + title: "Release ${{ env.RELEASE_VERSION }}" + files: | + staging/*.jar