Skip to content

Commit

Permalink
ci: 👷 seperate analyse-changed-package into reusable workflow job (#512)
Browse files Browse the repository at this point in the history
* bump version

Signed-off-by: Manuel Ruck <[email protected]>

* ci: 👷 seperate analyse-changed-package into reusable workflow job

Signed-off-by: Manuel Ruck <[email protected]>

* ci: 👷 add auto releasing

Signed-off-by: Manuel Ruck <[email protected]>

---------

Signed-off-by: Manuel Ruck <[email protected]>
Co-authored-by: Manuel Ruck <[email protected]>
  • Loading branch information
ManAnRuck and Manuel Ruck committed Oct 17, 2023
1 parent 6feab69 commit fa2804d
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 43 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/analyse-changed-packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Analyse changed packages

on:
workflow_call:
outputs:
changed:
description: 'Changed packages (comma separated names)'
value: ${{ jobs.analyse_changed_packages.outputs.changed }}
changedPackages:
description: 'Changed packages (JSON array of objects with package and directory properties)'
value: ${{ jobs.analyse_changed_packages.outputs.changedPackages }}

env:
DEFAULT_BRANCH: origin/master
DEFAULT_BRANCH_REF: refs/heads/master

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

- name: Read .node-version
id: node_version
run: echo "version=$(cat .node-version | tr -d 'v')" >> $GITHUB_OUTPUT

- name: Set Up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ steps.node_version.outputs.version }}
cache: 'yarn'

- run: yarn global add turbo

- name: Identifying Changed Bap-Services
id: changed-packages
run: |
turboChanges=""
if [ "${{ github.ref }}" = "${{ env.DEFAULT_BRANCH_REF }}" ]; \
then turboChanges=$(turbo run build --dry-run=json --since="${{ github.event.before }}"); \
else turboChanges=$(turbo run build --dry-run=json --since="${{ env.DEFAULT_BRANCH }}"); fi
changedPackages=$(node -e "const results = $turboChanges.tasks.map((task) => ({ package: task.package, directory: task.directory })); process.stdout.write(JSON.stringify(results));")
echo "$changedPackages"
changedPackagesFiltered=$(node -e "const fs = require('fs'); const results = $changedPackages.filter(({directory}) => {const private = JSON.parse(fs.readFileSync(\`./\${directory}/package.json\`, 'utf8')).private; return private === false || private === undefined;}); process.stdout.write(JSON.stringify(results));")
echo "$changedPackagesFiltered"
echo "changedPackages=$changedPackages" >> $GITHUB_OUTPUT
changed=$(node -e "const results = $changedPackagesFiltered.map(({package}) => package); process.stdout.write(JSON.stringify(results));")
echo "changed=$changed" >> $GITHUB_OUTPUT
- name: Print Changed Packages
run: echo ${{ steps.changed-packages.outputs.changed }}
43 changes: 1 addition & 42 deletions .github/workflows/build-and-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,9 @@ on:
branches:
- 'master'

env:
DEFAULT_BRANCH: origin/master
DEFAULT_BRANCH_REF: refs/heads/master

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

- name: Read .node-version
id: node_version
run: echo "version=$(cat .node-version | tr -d 'v')" >> $GITHUB_OUTPUT

- name: Set Up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ steps.node_version.outputs.version }}
cache: 'yarn'

- run: yarn global add turbo

- name: Identifying Changed Bap-Services
id: changed-packages
run: |
turboChanges=""
if [ "${{ github.ref }}" = "${{ env.DEFAULT_BRANCH_REF }}" ]; \
then turboChanges=$(turbo run build --dry-run=json --since="${{ github.event.before }}"); \
else turboChanges=$(turbo run build --dry-run=json --since="${{ env.DEFAULT_BRANCH }}"); fi
changedPackages=$(node -e "const results = $turboChanges.tasks.map((task) => ({ package: task.package, directory: task.directory })); process.stdout.write(JSON.stringify(results));")
echo "$changedPackages"
changedPackagesFiltered=$(node -e "const fs = require('fs'); const results = $changedPackages.filter(({directory}) => {const private = JSON.parse(fs.readFileSync(\`./\${directory}/package.json\`, 'utf8')).private; return private === false || private === undefined;}); process.stdout.write(JSON.stringify(results));")
echo "$changedPackagesFiltered"
echo "changedPackages=$changedPackages" >> $GITHUB_OUTPUT
changed=$(node -e "const results = $changedPackagesFiltered.map(({package}) => package); process.stdout.write(JSON.stringify(results));")
echo "changed=$changed" >> $GITHUB_OUTPUT
- name: Print Changed Packages
run: echo ${{ steps.changed-packages.outputs.changed }}
uses: demokratie-live/democracy-development/.github/workflows/analyse-changed-packages.yaml@feature/changelog

push:
runs-on: ubuntu-latest
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on: workflow_dispatch

permissions:
contents: write
pull-requests: write

name: release-please

jobs:
analyse-changed-packages:
uses: demokratie-live/democracy-development/.github/workflows/analyse-changed-packages.yaml@master

release-please:
runs-on: ubuntu-latest
environment: docker
needs: [analyse-changed-packages]
if: ${{ needs.analyse-changed-packages.outputs.changed != '[]' && needs.analyse-changed-packages.outputs.changed != '' }}
strategy:
fail-fast: false
matrix:
package: ${{fromJson(needs.analyse-changed-packages.outputs.changed)}}
steps:
- name: get directory for package
id: get-directory
run: |
# Variablen setzen
matrix_package="${{ matrix.package }}"
changed_packages_json='${{ needs.analyse-changed-packages.outputs.changedPackages }}'
# Verzeichnis mit jq finden
directory=$(echo "$changed_packages_json" | jq -r --arg package "$matrix_package" '.[] | select(.package == $package) | .directory')
# Ausgabe
echo "$directory"
echo "directory=$directory" >> $GITHUB_OUTPUT
- uses: google-github-actions/release-please-action@v3
with:
path: ${{ steps.get-directory.outputs.directory }}
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
monorepo-tags: true
package-name: ${{ matrix.package }}
command: github-release
2 changes: 1 addition & 1 deletion services/qr-code-handler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qr-code-handler",
"version": "1.0.6",
"version": "1.0.7",
"main": "build/index.js",
"scripts": {
"dev": "tsup src/index.ts --watch --onSuccess 'node build/index.js'",
Expand Down

0 comments on commit fa2804d

Please sign in to comment.