I tried to use CodeBuild as suggested in other answers, but it ended more complicated than I expected for my setup.
I ended up with a solution using GitHub Actions and source branches per stack.
1) I created a branch per stack
pipelines/api
pipelines/data
2) Then I created a GitHub Action per stack
These actions are only being triggered on main pushes and are filtered based on the changed files.
If an api matching change then merge into pipelines/api
, similarly for the data stack and pipelines/data
# .github/workflows/sync-pipelines-api-yaml
name: Sync pipelines/api
on:
push:
branches:
- main
paths:
- "package-lock.json"
- "lib/api/**"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
run: |
git switch -c main
git remote set-url origin "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY"
git push origin main:pipelines/api --force
# .github/workflows/sync-pipelines-data-yaml
name: Sync pipelines/data
on:
push:
branches:
- main
paths:
- "package-lock.json"
- "lib/data/**"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
run: |
git switch -c main
git remote set-url origin "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY"
git push origin main:pipelines/data --force
3) Then, I changed the source branch for each CodePipeline accordingly
// lib/api/stack.ts
const sourceAction = new actions.GitHubSourceAction({
owner,
repo,
branch: "pipelines/api"
});
// lib/data/stack.ts
const sourceAction = new actions.GitHubSourceAction({
owner,
repo,
branch: "pipelines/data"
});
Some benefits of this setup:
- If I want to deploy all stacks, I can push directly to each branch bypassing the stack action
- Very powerful filtering options
- Easy to test and change. CodeBuild/CodePipeline test cycle can take some time
- Minimal CodePipeline change