feat(workflows) renaming after convention and introduced shared workflows #4
Workflow file for this run
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
# Run it locally with act | |
# 1. Install act: | |
# `brew install act` | |
# 2. Create a .secret file with the following content: | |
# `GITHUB_TOKEN=your_github_token` | |
# PULL REQUEST | |
# 1. Create a act_pull_request.json file in case of a pull request with the following content: | |
# `{"pull_request": {"number": <PR number>, "head": {"ref": "<PR branch name>", "sha": "PR commit sha"}, "base": {"ref": "main"}}, "repository": {"name": "juno", "owner": {"login": "cloudoperators"}}}` | |
# 2. Run the following command: | |
# `act pull_request --container-architecture linux/amd64 -P default=catthehacker/ubuntu:act-latest -j run-ci-npm-package -e act_pull_request.json` | |
name: Detect Changes and trigger Pipeline | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
paths: | |
- "apps/**" | |
- "libs/**" | |
jobs: | |
detect-changes: | |
runs-on: [default] | |
outputs: | |
changes: ${{ steps.create-matrix-changes.outputs.changes}} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Generate app and lib filters | |
run: | | |
for folder in apps/*; do | |
folder_name=$(basename "$folder") | |
echo "$folder_name: $folder/**" >> temp_app_filters.yaml | |
done | |
for folder in libs/*; do | |
folder_name=$(basename "$folder") | |
echo "$folder_name: $folder/**" >> temp_lib_filters.yaml | |
done | |
- uses: dorny/paths-filter@v3 | |
id: filters | |
with: | |
list-files: shell | |
filters: | | |
apps: apps/** | |
libs: libs/** | |
- uses: dorny/paths-filter@v3 | |
id: app-filters | |
with: | |
list-files: shell | |
filters: temp_app_filters.yaml | |
- uses: dorny/paths-filter@v3 | |
id: lib-filters | |
with: | |
list-files: shell | |
filters: temp_lib_filters.yaml | |
- name: Create changes array for the matrix strategy | |
id: create-matrix-changes | |
run: | | |
app_changes=$(echo '${{ steps.app-filters.outputs.changes }}' | jq -c '.[]') | |
lib_changes=$(echo '${{ steps.lib-filters.outputs.changes }}' | jq -c '.[]') | |
changes=() | |
for app in $app_changes; do | |
changes+=( "{\"type\":\"apps\",\"asset\":$app}" ) | |
done | |
for change in $lib_changes; do | |
changes+=( "{\"type\":\"libs\",\"asset\":$change}" ) | |
done | |
echo "changes=[$(IFS=,; echo "${changes[*]}")]" >> $GITHUB_OUTPUT | |
- name: Show outputs | |
run: | | |
echo "===${{ github.workflow }} Outputs===" | |
cat temp_app_filters.yaml | |
echo "========" | |
cat temp_lib_filters.yaml | |
echo "========" | |
echo apps: ${{ steps.filters.outputs.apps}} | |
echo apps_files: ${{ steps.filters.outputs.apps_files}} | |
echo app changes: ${{ steps.app-filters.outputs.changes}} | |
echo libs: ${{ steps.filters.outputs.libs}} | |
echo libs_files: ${{ steps.filters.outputs.libs_files}} | |
echo lib changes: ${{ steps.lib-filters.outputs.changes}} | |
echo changes: ${{ toJson(steps.create-matrix-changes.outputs.changes) }} | |
echo "====================" | |
run-ci-npm-package: | |
needs: [detect-changes] | |
strategy: | |
matrix: | |
change: ${{fromJson(needs.detect-changes.outputs.changes)}} | |
node: [20.x] | |
fail-fast: false # Allow other jobs to continue if one fails | |
uses: cloudoperators/juno/.github/workflows/pipeline-npm-package.yaml@workflows-name-convention | |
with: | |
change: ${{ toJson(matrix.change) }} | |
node: "${{ matrix.node }}" |