Skip to content

using matrix

using matrix #112

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: Get current version
id: get_version
run: |
COMPONENT="${{ matrix.component }}"
VERSION_FILE="${COMPONENT//-/_}/build.gradle.kts"
[[ $COMPONENT == lega-commander ]] && VERSION_FILE="cli/$VERSION_FILE" || VERSION_FILE="$([[ $COMPONENT == *Tests ]] && echo "" || echo "services/")$VERSION_FILE"
CURRENT_VERSION=$(grep -oP 'version = "\K[0-9]+\.[0-9]+\.[0-9]+' $VERSION_FILE)
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: |
COMPONENT="${{ matrix.component }}"
VERSION_FILE="${COMPONENT//-/_}/build.gradle.kts"
[[ $COMPONENT == lega-commander ]] && VERSION_FILE="cli/$VERSION_FILE" || VERSION_FILE="$([[ $COMPONENT == *Tests ]] && echo "" || echo "services/")$VERSION_FILE"
sed -i "s/version = \".*\"/version = \"${{ steps.bump_version.outputs.new_version }}\"/" $VERSION_FILE
- name: Build and publish
if: ${{ matrix.component != 'lega-commander' && matrix.component != 'e2eTests' }}
run: |
COMPONENT="${{ matrix.component }}"
./gradlew :$([[ $COMPONENT == clearinghouse || $COMPONENT == crypt4gh || $COMPONENT == tsd-file-api-client ]] && echo "lib:" || echo "services:")$COMPONENT:build
./gradlew :$([[ $COMPONENT == clearinghouse || $COMPONENT == crypt4gh || $COMPONENT == tsd-file-api-client ]] && echo "lib:" || echo "services:")$COMPONENT:publish
- 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: 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