如何在单个存储库中使用多个Travis CI文件?

问题描述 投票:0回答:1

我有一个在前端使用Angular,在后端使用Spring Boot的项目。

目前,前端和后端位于两个单独的存储库中,在这些存储库中,我已经准备了特定的travis.yaml文件,例如Spring Boot应用程序:

language: java
services: docker
addons:
  sonarcloud:
    organization: "mixeway" # the key of the org you chose at step #3
    token:
      secure: $SONAR_TOKEN


script:
  - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar -Dmaven.test.skip=true -Dsonar.projectKey=Mixeway_MixewayBackend
  - mvn package -Dmaven.test.skip=true
  - docker build --build-arg JAR_FILE=target/mixeway-0.9.jar -t mixeway/backend:0.9 .
  - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
  - docker push mixeway/backend:0.9

Angular travis.yaml非常相似(除了Angular应用的构建时间长几倍)。我想将两个存储库合并为一个,将后端和前端的代码合并到一个存储库中。我希望有两个单独的管道,因此更改后端代码将不会执行用于构建前端映像的管道。

这可能吗?如果是这样,怎么办?

continuous-integration travis-ci monorepo
1个回答
0
投票

在我自己面对travis CI完全相同的问题并且没有找到令人满意的解决方案之后,我发现使用新的github actions可以很容易地做到这一点。

基本上,您为存储库中的每个项目创建一个工作流文件(类似于.travis.yml,它是自包含的,并且仅负责构建其所属的项目。

这是基本的monorepo结构:

.
├── .github
│   └── workflows
│       ├── project1.yml
│       ├── project2.yml
├── project1
│   └── build.gradle
├── project2
│   └── build.gradle

并且在工作流文件本身中,假设为project1.yml,您可以指定哪个路径应触发该项目的构建:

on:
  push:
    paths:
      - 'project1/*'

我有a repository with this structure(有一个弹簧靴项目和一个角形项目,您可以看一下。

© www.soinside.com 2019 - 2024. All rights reserved.