Skip to content

Commit

Permalink
ci: 👷 modulize analyse services action
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Ruck <[email protected]>
  • Loading branch information
Manuel Ruck committed Oct 21, 2023
1 parent a08ed09 commit 560b75e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 64 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/build-and-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ on:
required: true
default: '[]'
type: string
secrets:
DOCKER_USERNAME:
description: 'Dockerhub Username'
required: true
DOCKER_PASSWORD:
description: 'Dockerhub Token'
required: true

jobs:
build-and-push:
runs-on: ubuntu-latest
environment: docker
if: ${{ inputs.changedPackages != '[]'}}
strategy:
fail-fast: false
Expand Down Expand Up @@ -69,11 +75,12 @@ jobs:
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-multi-buildx
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Read .node-version
id: node_version
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/get-changed-services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Get Changed Packages

on:
workflow_call:
outputs:
CHANGED_PACKAGES:
value: ${{ jobs.analyse-changed-packages.outputs.changedPackages }}

jobs:
analyse-changed-packages:
runs-on: ubuntu-latest
outputs:
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 }}
38 changes: 10 additions & 28 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,20 @@ on:
- 'master'

jobs:
analyse-changed-packages:
test:
runs-on: ubuntu-latest
outputs:
changedPackages: ${{ steps.changed-packages.outputs.CHANGED_PACKAGES }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: echo docker_username char length
run: echo "${{ secrets.DOCKER_USERNAME }}" | wc -c

- 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 }}
analyse-changed-services:
uses: ./.github/workflows/get-changed-services.yaml

build-and-push:
uses: ./.github/workflows/build-and-push.yaml
needs: analyse-changed-packages
needs: analyse-changed-services
with:
changedPackages: ${{ needs.analyse-changed-packages.outputs.changedPackages }}
changedPackages: ${{ needs.analyse-changed-services.outputs.CHANGED_PACKAGES }}
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
38 changes: 5 additions & 33 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,18 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

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 }}
analyse-changed-services:
uses: ./.github/workflows/get-changed-services.yaml

release:
needs: [analyse-changed-packages]
needs: [analyse-changed-services]
runs-on: ubuntu-latest
if: ${{ needs.analyse-changed-packages.outputs.changedPackages != '[]'}}
if: ${{ needs.analyse-changed-services.outputs.CHANGED_PACKAGES != '[]'}}
strategy:
fail-fast: false
max-parallel: 1
matrix:
package: ${{fromJson(needs.analyse-changed-packages.outputs.changedPackages)}}
package: ${{fromJson(needs.analyse-changed-services.outputs.CHANGED_PACKAGES)}}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
Expand Down

0 comments on commit 560b75e

Please sign in to comment.