Skip to content

using matrix

using matrix #115

Workflow file for this run

name: Publish
on:
push:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
lega-commander: ['cli/lega-commander/**']
e2eTests: ['e2eTests/**']
clearinghouse: ['lib/clearinghouse/**']
crypt4gh: ['lib/crypt4gh/**']
tsd-file-api-client: ['lib/tsd-file-api-client/**']
cega-mock: ['services/cega-mock/**']
localega-tsd-proxy: ['services/localega-tsd-proxy/**']
mq-interceptor: ['services/mq-interceptor/**']
tsd-api-mock: ['services/tsd-api-mock/**']
- id: set-matrix
run: |
MATRIX=$(echo '${{ toJson(steps.changes.outputs) }}' | jq -c '{include: [to_entries[] | select(.value == "true") | {component: .key}]}')
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
update-version-and-publish:
needs: detect-changes
if: ${{ needs.detect-changes.outputs.matrix != '{"include":[]}' }}
runs-on: ubuntu-latest
strategy:
matrix: ${{fromJson(needs.detect-changes.outputs.matrix)}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Java
if: ${{ matrix.component != 'lega-commander' }}
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Set up Go
if: ${{ matrix.component == 'lega-commander' }}
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Setup Gradle
if: ${{ matrix.component != 'lega-commander' }}
uses: gradle/actions/[email protected]
- name: Determine build.gradle.kts path
id: gradle_path
run: |
COMPONENT="${{ matrix.component }}"
if [[ $COMPONENT == lega-commander ]]; then
GRADLE_PATH="cli/lega-commander/build.gradle.kts"
elif [[ $COMPONENT == e2eTests ]]; then
GRADLE_PATH="e2eTests/build.gradle.kts"
elif [[ $COMPONENT == clearinghouse || $COMPONENT == crypt4gh || $COMPONENT == tsd-file-api-client ]]; then
GRADLE_PATH="lib/$COMPONENT/build.gradle.kts"
else
GRADLE_PATH="services/$COMPONENT/build.gradle.kts"
fi
echo "gradle_path=$GRADLE_PATH" >> $GITHUB_OUTPUT
- name: Get current version
id: get_version
run: |
GRADLE_PATH="${{ steps.gradle_path.outputs.gradle_path }}"
if [[ ! -f $GRADLE_PATH ]]; then
echo "Error: build.gradle.kts not found at $GRADLE_PATH"
exit 1
fi
CURRENT_VERSION=$(grep -oP 'version = "\K[0-9]+\.[0-9]+\.[0-9]+' $GRADLE_PATH)
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Bump version
id: bump_version
run: |
CURRENT_VERSION="${{ steps.get_version.outputs.current_version }}"
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$((VERSION_PARTS[2] + 1))"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Update version in file
run: |
GRADLE_PATH="${{ steps.gradle_path.outputs.gradle_path }}"
sed -i "s/version = \".*\"/version = \"${{ steps.bump_version.outputs.new_version }}\"/" $GRADLE_PATH
- name: Build and publish
if: ${{ matrix.component != 'lega-commander' && matrix.component != 'e2eTests' }}
run: |
COMPONENT="${{ matrix.component }}"
if [[ $COMPONENT == clearinghouse || $COMPONENT == crypt4gh || $COMPONENT == tsd-file-api-client ]]; then
./gradlew :lib:$COMPONENT:build
./gradlew :lib:$COMPONENT:publish
fi
- name: Build and push Docker image
if: ${{ matrix.component != 'lega-commander' && matrix.component != 'clearinghouse' && matrix.component != 'crypt4gh' && matrix.component != 'tsd-file-api-client' && matrix.component != 'e2eTests' }}
uses: docker/build-push-action@v6
with:
context: ./services/${{ matrix.component }}
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ matrix.component }}-${{ steps.bump_version.outputs.new_version }}
ghcr.io/${{ github.repository }}:${{ matrix.component }}-latest
- name: Create and push new tag
if: ${{ matrix.component == 'lega-commander' }}
run: |
git tag v${{ steps.bump_lega_commander_version.outputs.new_lega_commander_version }} ${{ github.sha }}
- name: Run GoReleaser
if: ${{ matrix.component == 'lega-commander' }}
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
workdir: cli/lega-commander
- name: Commit and push changes
run: |
git config user.name github-actions
git config user.email [email protected]
git add .
git commit -m "Bump ${{ matrix.component }} version to ${{ steps.bump_version.outputs.new_version }}"
git push
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: "${{ matrix.component }}-${{ steps.bump_version.outputs.new_version }}"
name: "${{ matrix.component }} ${{ steps.bump_version.outputs.new_version }}"
generate_release_notes: true