-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: 👷 seperate analyse-changed-package into reusable workflow job (#512)
* 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
Showing
4 changed files
with
102 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters