GitHub Actions 提供了一种将 CI/CD 集成到存储库中的无缝方式,自动执行各种任务,例如运行测试、构建工件和部署项目。
快照的工作流程
此工作流在非主分支上触发或通过工作流调度事件手动触发。它包括以下步骤:
- 运行测试:确保您的代码通过所有测试。
- 构建 JAR 文件:编译您的 Spring Boot 应用程序。
- 构建 Docker 映像并将其推送到 GitHub Docker 注册表:从生成的工件创建 Docker 映像并将其推送到 GitHub 容器注册表。
name: Test and Build Snapshot on: push: branches-ignore: - main workflow_dispatch: permissions: contents: read packages: write jobs: maven-verify: if: "!contains(github.event.head_commit.message, '[skip ci]')" runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up JDK 21 uses: actions/setup-java@v4 with: java-version: '21' distribution: 'temurin' cache: maven cache-dependency-path: '**/pom.xml' - name: Verify run: mvn -B clean verify --file pom.xml maven-build: needs: maven-verify runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up JDK 21 uses: actions/setup-java@v4 with: java-version: '21' distribution: 'temurin' cache: maven cache-dependency-path: '**/pom.xml' - name: Build run: mvn -B package --file pom.xml - name: Upload artifact uses: actions/upload-artifact@v4 with: name: app.jar path: target/*.jar docker-build-push: needs: maven-build runs-on: ubuntu-latest env: CURRENT_VERSION: '' steps: - uses: actions/checkout@v4 - name: Download artifact uses: actions/download-artifact@v4 with: name: app.jar path: target - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GHCR_PAT }} - name: Get Version run: echo "CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV - name: Build Docker image uses: docker/build-push-action@v6 with: context: . push: true tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.CURRENT_VERSION }}-${{ github.run_id }}
发布的工作流程
此工作流程在将更改推送到主分支时运行,包括以下步骤:
- 构建发布版本:编译项目的发布版本。
- 构建 Docker 映像并将其推送到 GitHub Docker 注册表:创建 Docker 映像并将其推送到 GitHub 容器注册表。
- 增加 SNAPSHOT 版本:更新 pom.xml 中的版本以用于将来的快照版本。
name: Build Release on: push: branches: - main workflow_dispatch: permissions: contents: read packages: write jobs: maven-build-release: if: "!contains(github.event.head_commit.message, '[skip ci]')" runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up JDK 21 uses: actions/setup-java@v4 with: java-version: '21' distribution: 'temurin' cache: maven cache-dependency-path: '**/pom.xml' - name: Prepare Release Version run: mvn versions:set -DremoveSnapshot - name: Build run: mvn -B clean package --file pom.xml -DskipTests - name: Upload artifact uses: actions/upload-artifact@v4 with: name: app.jar path: target/*.jar docker-build-push: needs: maven-build-release runs-on: ubuntu-latest env: CURRENT_VERSION: '' steps: - uses: actions/checkout@v4 - name: Download artifact uses: actions/download-artifact@v4 with: name: app.jar path: target - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GHCR_PAT }} - name: Get Version run: | mvn versions:set -DremoveSnapshot echo "CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV - name: Build Docker image uses: docker/build-push-action@v6 with: context: . push: true tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.CURRENT_VERSION }}-${{ github.run_id }} increment-version: needs: docker-build-push runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/checkout@v4 with: token: ${{ secrets.GIT_PAT }} - name: Configure Git run: | git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" - name: Increment Snapshot Version run: | # Extract current version and increment patch version CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1) MINOR=$(echo $CURRENT_VERSION | cut -d. -f2) PATCH=$(echo $CURRENT_VERSION | cut -d. -f3 | cut -d- -f1) NEW_PATCH=$((PATCH + 1)) NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH-SNAPSHOT" # Update version in pom.xml mvn versions:set -DnewVersion=$NEW_VERSION mvn versions:commit # Commit and push the new snapshot version git add pom.xml git commit -m "Increment version to $NEW_VERSION [skip ci]" git push origin $(git rev-parse --abbrev-ref HEAD)
奖金工作流程
CodeQL 工作流程分析您的 Java 代码以识别潜在的漏洞和问题。
name: CodeQL on: pull_request: branches: [ "main" ] workflow_dispatch: jobs: analyze: name: Analyze runs-on: ubuntu-latest permissions: actions: read contents: read security-events: write strategy: fail-fast: false matrix: language: [ 'java' ] steps: - name: Checkout repository uses: actions/checkout@v4 - name: Setup Java uses: actions/setup-java@v4 with: java-version: '21' distribution: 'temurin' cache: maven cache-dependency-path: '**/pom.xml' - name: Initialize CodeQL uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} - name: Autobuild uses: github/codeql-action/autobuild@v3 - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 with: category: "/language:${{matrix.language}}"
更新的 Dockerfile
### Build stage FROM eclipse-temurin:21-jre-alpine AS builder # Set the working directory inside the container WORKDIR /tmp # Copy the source code into the container COPY target/*.jar app.jar # Extract the layers RUN java -Djarmode=layertools -jar app.jar extract ### Run stage # Create a minimal production image FROM eclipse-temurin:21-jre-alpine # Set the working directory inside the container WORKDIR /app # Set the working directory inside the container COPY --from=builder /tmp/dependencies/ ./ COPY --from=builder /tmp/snapshot-dependencies/ ./ COPY --from=builder /tmp/spring-boot-loader/ ./ COPY --from=builder /tmp/application/ ./ # Run the binary when the container starts ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]
以上是SpringBoot Web 服务 - 部分 Github 操作的详细内容。更多信息请关注PHP中文网其他相关文章!

Java如何缓解平台特定的问题?Java通过JVM和标准库来实现平台无关性。1)使用字节码和JVM抽象操作系统差异;2)标准库提供跨平台API,如Paths类处理文件路径,Charset类处理字符编码;3)实际项目中使用配置文件和多平台测试来优化和调试。

java'splatformentenceenhancesenhancesmicroservicesharchitecture byferingDeploymentFlexible,一致性,可伸缩性和便携性。1)DeploymentFlexibilityAllowsibilityAllowsOllowsOllowSorlowsOllowsOllowsOllowSeStorunonAnyPlatformwithajvM.2)penterencyCrossServAccAcrossServAcrossServiCessImplifififiesDeevelopmentandeDe

GraalVM通过三种方式增强了Java的平台独立性:1.跨语言互操作,允许Java与其他语言无缝互操作;2.独立的运行时环境,通过GraalVMNativeImage将Java程序编译成本地可执行文件;3.性能优化,Graal编译器生成高效的机器码,提升Java程序的性能和一致性。

效率testjavaapplicationsforplatformcompatibility oftheSesteps:1)setUpautomatedTestingTestingActingAcrossMultPlatFormSusingCitoolSlikeSlikeJenkinSorgithUbactions.2)contuctualtemualtemalualTesteTESTENRETESTINGINREALHARTWARETOLEALHARDOELHARDOLEATOCATCHISSUSESUSEUSENINCIENVIRENTMENTS.3)schictcross.3)schoscross.3)

Java编译器通过将源代码转换为平台无关的字节码,实现了Java的平台独立性,使得Java程序可以在任何安装了JVM的操作系统上运行。

ByteCodeachievesPlatFormIndenceByByByByByByExecutedBoviratualMachine(VM),允许CodetorunonanyplatformwithTheApprepreprepvm.Forexample,Javabytecodecodecodecodecanrunonanydevicewithajvm

Java不能做到100%的平台独立性,但其平台独立性通过JVM和字节码实现,确保代码在不同平台上运行。具体实现包括:1.编译成字节码;2.JVM的解释执行;3.标准库的一致性。然而,JVM实现差异、操作系统和硬件差异以及第三方库的兼容性可能影响其平台独立性。

Java通过“一次编写,到处运行”实现平台独立性,提升代码可维护性:1.代码重用性高,减少重复开发;2.维护成本低,只需一处修改;3.团队协作效率高,方便知识共享。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

SublimeText3 Linux新版
SublimeText3 Linux最新版

禅工作室 13.0.1
功能强大的PHP集成开发环境