-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d1f133
commit 9674752
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: 'Build Matrix' | ||
|
||
description: 'Builds components based on matrix configuration' | ||
|
||
inputs: | ||
event: # Event type (e.g., push, pull_request) | ||
required: true | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Check Event Type | ||
id: check-event | ||
run: | | ||
if [ "${{ inputs.event }}" != "push" ] && [ "${{ inputs.event }}" != "pull_request" ]; then | ||
echo "Invalid event type. Only 'push' and 'pull_request' are supported." | ||
exit 1 | ||
fi | ||
- name: Set Matrix Outputs | ||
id: set-matrix | ||
run: | | ||
components=() | ||
paths=() | ||
docker_files=() | ||
working_dirs=() | ||
image_names=() | ||
# Check if it's a pull request and get changed files | ||
if [ "${{ inputs.event }}" == "pull_request" ]; then | ||
files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }}) | ||
else | ||
files=$(git diff --name-only HEAD^ HEAD) | ||
fi | ||
# Function to add a component | ||
add_component() { | ||
components+=("$1") | ||
paths+=("$2") | ||
docker_files+=("$3") | ||
working_dirs+=("$4") | ||
image_names+=("$5") | ||
} | ||
# Check if paths of each component are in the changed files | ||
if echo "$files" | grep -qE '^backend/'; then | ||
add_component "Backend" "backend/models/** backend/ops_api/** backend/Dockerfile.ops-api" "Dockerfile.ops-api" "backend" "ops-backend" | ||
fi | ||
if echo "$files" | grep -qE '^backend/data-tools/'; then | ||
add_component "Data-Tools" "backend/data-tools/** backend/Dockerfile.data-tools" "Dockerfile.data-tools" "backend" "ops-data-tools" | ||
fi | ||
if echo "$files" | grep -qE '^frontend/'; then | ||
add_component "Frontend" "frontend/** frontend/Dockerfile.azure" "Dockerfile.azure" "frontend" "ops-frontend" | ||
fi | ||
# Set matrix outputs | ||
echo "::set-output name=matrix::[${components[@]}]" | ||
echo "::set-output name=paths::[${paths[@]}]" | ||
echo "::set-output name=docker_file::[${docker_files[@]}]" | ||
echo "::set-output name=working_dir::[${working_dirs[@]}]" | ||
echo "::set-output name=image_name::[${image_names[@]}]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Build Components | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
event: ["push", "pull_request"] | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set Matrix and Build | ||
id: set-matrix | ||
uses: ./.github/actions/test_matrix | ||
with: | ||
event: ${{ matrix.event }} | ||
|
||
- name: Use Matrix in Another Step | ||
run: | | ||
echo "Component: ${{ matrix.component }}" | ||
echo "Paths: ${{ matrix.paths }}" | ||
echo "Dockerfile: ${{ matrix.docker_file }}" | ||
echo "Working Directory: ${{ matrix.working_dir }}" | ||
echo "Image Name: ${{ matrix.image_name }}" |