Skip to content

Commit

Permalink
ci: 👷 modularize build and push action
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Ruck committed Oct 21, 2023
1 parent 3adb68e commit 166df88
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 43 deletions.
52 changes: 9 additions & 43 deletions .github/workflows/build-and-push.yaml
Original file line number Diff line number Diff line change
@@ -1,57 +1,23 @@
name: Docker – Build and Push

on:
workflow_dispatch:
push:
tags:
- '*'
pull_request:
paths:
- 'services/**'
branches:
- 'master'
workflow_call:
inputs:
changedPackages:
description: 'Changed Packages'
required: true
default: '[]'
type: string

jobs:
analyse-changed-packages:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.changed-packages.outputs.CHANGED }}
changedPackages: ${{ steps.changed-packages.outputs.CHANGED_PACKAGES }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- run: |
SINCE=$(git rev-list --tags --max-count=1)
echo SINCE=$SINCE >> $GITHUB_OUTPUT
echo SINCE=$SINCE
id: since
- run: |
pnpm list -r --json --filter "...[$SINCE]" | jq '[.[] | select(.private == false) | {name, path}]' > ./tmp.json
CHANGED_PACKAGES=$(jq '[.[] | .name]' ./tmp.json)
echo CHANGED_PACKAGES=$CHANGED_PACKAGES >> $GITHUB_OUTPUT
echo CHANGED_PACKAGES=$CHANGED_PACKAGES
id: changed-packages
env:
SINCE: ${{ steps.since.outputs.SINCE }}
build-and-push:
runs-on: ubuntu-latest
environment: docker
needs: [analyse-changed-packages]
if: ${{ needs.analyse-changed-packages.outputs.changedPackages != '[]'}}
if: ${{ inputs.changedPackages != '[]'}}
strategy:
fail-fast: false
matrix:
package: ${{fromJson(needs.analyse-changed-packages.outputs.changedPackages)}}
package: ${{fromJson(inputs.changedPackages)}}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Pull Request

on:
workflow_dispatch:
pull_request:
paths:
- 'services/**'
branches:
- 'master'

jobs:
analyse-changed-packages:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.changed-packages.outputs.CHANGED }}
changedPackages: ${{ steps.changed-packages.outputs.CHANGED_PACKAGES }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- run: |
SINCE=$(git rev-list --tags --max-count=1)
echo SINCE=$SINCE >> $GITHUB_OUTPUT
echo SINCE=$SINCE
id: since
- run: |
pnpm list -r --json --filter "...[$SINCE]" | jq '[.[] | select(.private == false) | {name, path}]' > ./tmp.json
CHANGED_PACKAGES=$(jq '[.[] | .name]' ./tmp.json)
echo CHANGED_PACKAGES=$CHANGED_PACKAGES >> $GITHUB_OUTPUT
echo CHANGED_PACKAGES=$CHANGED_PACKAGES
id: changed-packages
env:
SINCE: ${{ steps.since.outputs.SINCE }}
build-and-push:
uses: .github/workflows/build-and-push.yaml
needs: analyse-changed-packages
with:
changed: ${{ needs.analyse-changed-packages.outputs.changed }}
changedPackages: ${{ needs.analyse-changed-packages.outputs.changedPackages }}

0 comments on commit 166df88

Please sign in to comment.