From e9d1af2fe14baee9e02376f71b932d5e38f0f3db Mon Sep 17 00:00:00 2001 From: Alan Yeh Date: Sun, 13 Oct 2024 01:21:44 +0800 Subject: [PATCH] =?UTF-8?q?[UPDATE]=20=E6=9B=B4=E6=96=B0=E6=8C=81=E7=BB=AD?= =?UTF-8?q?=E9=9B=86=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alan Yeh --- .github/.m2/settings.xml | 135 +++++++++++++++++++++++++++ .github/workflows/release.yml | 101 +++++++++----------- .github/workflows/release_github.yml | 102 ++++++++++++++++++++ 3 files changed, 279 insertions(+), 59 deletions(-) create mode 100644 .github/.m2/settings.xml create mode 100644 .github/workflows/release_github.yml diff --git a/.github/.m2/settings.xml b/.github/.m2/settings.xml new file mode 100644 index 00000000..dfd20c6b --- /dev/null +++ b/.github/.m2/settings.xml @@ -0,0 +1,135 @@ + + + + + + centralx + ${env.MAVEN_USERNAME} + ${env.MAVEN_PASSWORD} + + + sonatype + ${env.MAVEN_USERNAME} + ${env.MAVEN_PASSWORD} + + + github + ${env.MAVEN_USERNAME} + ${env.MAVEN_PASSWORD} + + + gpg.passphrase + ${env.GPG_PASSPHRASE} + + + + + + centralx + + + centralx + CentralX Repository + https://mirror.central-x.com/repository/maven-public/ + + always + + + + + + centralx + CentralX Repository + https://mirror.central-x.com/repository/maven-public/ + + always + + + + + + + sonatype + + + sonatype + Sonatype Repository + https://s01.oss.sonatype.org/content/groups/public/ + + always + + + + central + Maven Central Repository + https://repo1.maven.org/maven2/ + + always + + + + + + sonatype + Sonatype Repository + https://s01.oss.sonatype.org/content/groups/public/ + + always + + + + central + Maven Central Repository + https://repo1.maven.org/maven2/ + + always + + + + + + + github + + + github + GitHub Repository + https://maven.pkg.github.com/central-x/*/ + + true + always + + + + central + Maven Central Repository + https://repo1.maven.org/maven2/ + + always + + + + + + github + GitHub Repository + https://maven.pkg.github.com/central-x/*/ + + true + always + + + + central + Maven Central Repository + https://repo1.maven.org/maven2/ + + always + + + + + + \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e999c2b5..78dee78d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,47 +1,31 @@ -name: Release +name: Release to Sonatype on: push: - branches: - - master - - '*.x' + # 只发布正式版到 Maven Central + tags: + - '*.RELEASE' + jobs: - # 编译类库并发布到 GitHub Packages - release-libraries-to-github-packages: - name: Release Libraries to GitHub Packages + # 构建应用组件并发布到 Maven Central + release-to-sonatype: + name: Release to Sonatype (Maven Central) runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Set up java - uses: actions/setup-java@v4 + - name: Set up nodejs + uses: actions/setup-node@v4 with: - java-version: 17 - distribution: zulu - server-id: github - server-username: MAVEN_USERNAME - server-password: MAVEN_PASSWORD - gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} - gpg-passphrase: GPG_PASSPHRASE - - name: Echo settings.xml - run: cat /home/runner/.m2/settings.xml - - name: Release packages - run: mvn -P github --batch-mode clean deploy - env: - MAVEN_USERNAME: ${{ secrets.GHPKG_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.GHPKG_TOKEN }} - GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} - # 编译类库并发布到 Maven Central - release-libraries-to-maven-central: - name: Release Libraries to Maven Central - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 + node-version: 22 + - name: Cache maven packages + uses: actions/cache@v4 with: - fetch-depth: 0 + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 - name: Set up java uses: actions/setup-java@v4 with: @@ -52,30 +36,37 @@ jobs: server-password: MAVEN_PASSWORD gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} gpg-passphrase: GPG_PASSPHRASE - - name: Echo settings.xml - run: cat /home/runner/.m2/settings.xml - - name: Release packages - run: mvn -P sonatype --batch-mode clean deploy + - name: Release packages to Sonatype (Maven Central) + run: | + # 覆盖 maven settings.xml 文件,添加自定义 profiles + # 先 install maven-studio-parent 到 local repository + # 再安装 central-studio-views 下项目的 npm 依赖 + # 最后再来发布类库 + rm ~/.m2/settings.xml & cp ${{ github.workspace }}/.github/.m2/settings.xml ~/.m2/settings.xml & + mvn -P sonatype --batch-mode clean install -pl :central-studio-parent & + mvn -P sonatype exec:exec@npm-install -pl :central-dashboard-view,:central-identity-view & + mvn -P sonatype --batch-mode clean deploy env: - MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + MAVEN_USERNAME: ${{ secrets.GHPKG_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.GHPKG_TOKEN }} GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} - # 构建应用组件并发布 Docker 镜像 - release-studio-images: + + # 构建应用组件并发布到 DockerHub + release-docker-images: name: Release Docker Images runs-on: ubuntu-latest - needs: [release-libraries-to-github-packages, release-libraries-to-maven-central] + needs: [ release-to-sonatype ] steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 17 distribution: zulu - server-id: github + server-id: sonatype server-username: MAVEN_USERNAME server-password: MAVEN_PASSWORD gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} @@ -87,34 +78,26 @@ jobs: with: driver-opts: image=moby/buildkit:master platforms: linux/amd64,linux/arm64 - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to GitHub Packages uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ secrets.GHPKG_USERNAME }} password: ${{ secrets.GHPKG_TOKEN }} - - name: Build packages - run: mvn -P github clean package + - name: Package + run: | + # 覆盖 maven settings.xml 文件,添加自定义 profiles + # 打包应用组件 + rm ~/.m2/settings.xml & cp ${{ github.workspace }}/.github/.m2/settings.xml ~/.m2/settings.xml & + mvn -P sonatype --batch-mode clean package -pl :central-bootstrap env: MAVEN_USERNAME: ${{ secrets.GHPKG_USERNAME }} MAVEN_PASSWORD: ${{ secrets.GHPKG_TOKEN }} GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} - - name: Release to DockerHub + - name: Release images to DockerHub uses: docker/bake-action@v5 with: push: true env: REGISTRY: docker.io - REPOSITORY: centralx - - name: Release to GitHub Packages - uses: docker/bake-action@v5 - with: - push: true - env: - REGISTRY: ghcr.io - REPOSITORY: central-x \ No newline at end of file + REPOSITORY: centralx \ No newline at end of file diff --git a/.github/workflows/release_github.yml b/.github/workflows/release_github.yml new file mode 100644 index 00000000..f87967b3 --- /dev/null +++ b/.github/workflows/release_github.yml @@ -0,0 +1,102 @@ +name: Release to Github Packages + +on: + push: + branches: + - master + - '*.x' + +jobs: + # 构建应用组件并发布到 GitHub Packages + release-to-github-packages: + name: Release to Github Packages + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up nodejs + uses: actions/setup-node@v4 + with: + node-version: 22 + - name: Cache maven packages + uses: actions/cache@v4 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: Set up java + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: zulu + server-id: github + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: GPG_PASSPHRASE + - name: Release packages to GitHub Packages + run: | + # 覆盖 maven settings.xml 文件,添加自定义 profiles + # 先 install maven-studio-parent 到 local repository + # 再安装 central-studio-views 下项目的 npm 依赖 + # 最后再来发布类库 + rm ~/.m2/settings.xml & cp ${{ github.workspace }}/.github/.m2/settings.xml ~/.m2/settings.xml & + mvn -P github --batch-mode clean install -pl :central-studio-parent & + mvn -P github exec:exec@npm-install -pl :central-dashboard-view,:central-identity-view & + mvn -P github --batch-mode clean deploy + env: + MAVEN_USERNAME: ${{ secrets.GHPKG_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.GHPKG_TOKEN }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + # 构建应用组件并发布到 GitHub Packages + release-docker-images: + name: Release Docker Images + runs-on: ubuntu-latest + needs: [release-to-github-packages] + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up java + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: zulu + server-id: github + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: GPG_PASSPHRASE + - name: Set up Docker(QEMU) + uses: docker/setup-qemu-action@v3 + - name: Set up Docker(Buildx) + uses: docker/setup-buildx-action@v3 + with: + driver-opts: image=moby/buildkit:master + platforms: linux/amd64,linux/arm64 + - name: Login to GitHub Packages + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ secrets.GHPKG_USERNAME }} + password: ${{ secrets.GHPKG_TOKEN }} + - name: Package + run: | + # 覆盖 maven settings.xml 文件,添加自定义 profiles + # 打包应用组件 + rm ~/.m2/settings.xml & cp ${{ github.workspace }}/.github/.m2/settings.xml ~/.m2/settings.xml & + mvn -P github --batch-mode clean package -pl :central-bootstrap + env: + MAVEN_USERNAME: ${{ secrets.GHPKG_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.GHPKG_TOKEN }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + - name: Release images to GitHub Packages + uses: docker/bake-action@v5 + with: + push: true + env: + REGISTRY: ghcr.io + REPOSITORY: central-x