Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: 👷 modulize analyse services action #519

Merged
merged 3 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/build-and-push-tagged.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build and Push tagged

on:
push:
tags:
- '*'

jobs:
get-tagged-service:
runs-on: ubuntu-latest
outputs:
TAGGED_SERVICE: ${{ steps.get-tagged-service.outputs.TAGGED_SERVICE }}
steps:
# syntax: [email protected]
- name: Get tagged service
id: get-tagged-service
run: |
service=$(echo "${{ github.ref_name }}" | sed -n 's/^\(.*\)@v.*/\1/p')
serviceJSON=[\"$service\"]
echo "TAGGED_SERVICE=$serviceJSON" >> $GITHUB_OUTPUT
echo $serviceJSON

build-and-push:
uses: ./.github/workflows/build-and-push.yaml
needs: get-tagged-service
with:
changedPackages: ${{ needs.get-tagged-service.outputs.TAGGED_SERVICE }}
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
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: 7 additions & 31 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,14 @@ on:
- 'master'

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 }}
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 }}
43 changes: 9 additions & 34 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 All @@ -74,7 +46,10 @@ jobs:
fetch-depth: 0
token: ${{ secrets.PAT }} # use PAT to being able to push to protected branch later on

- run: git checkout ${{ github.event.repository.default_branch }}
- name: Checkout latest default branch
run: |
git checkout ${{ github.event.repository.default_branch }}
git pull origin ${{ github.event.repository.default_branch }}
if: ${{ contains(github.ref, github.event.repository.default_branch) }}

- uses: pnpm/action-setup@v2
Expand Down