From a3361bdc973b4324a6398225bc8a74556cc631eb Mon Sep 17 00:00:00 2001 From: luca-sartori-zupit Date: Thu, 26 Sep 2024 10:40:40 +0200 Subject: [PATCH] chore: create conditional workflow for dotnet-workflow-common --- .github/workflows/dotnet-workflow-common.yml | 45 ++++++++++++++++++-- .prettierrc | 4 ++ package-lock.json | 18 ++++++++ package.json | 7 ++- 4 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 .prettierrc diff --git a/.github/workflows/dotnet-workflow-common.yml b/.github/workflows/dotnet-workflow-common.yml index 64502df1..548f4dfb 100644 --- a/.github/workflows/dotnet-workflow-common.yml +++ b/.github/workflows/dotnet-workflow-common.yml @@ -12,19 +12,19 @@ on: RUN_ON: required: false type: string - default: 'zupit-agents' + default: "zupit-agents" RUNNERS_CONTAINER_GROUP: required: false type: string - default: 'Container' + default: "Container" DOTNET_IMAGE_ENV_VARIABLES: required: false type: string - default: '{}' + default: "{}" CSHARPIER_VERSION: required: false type: string - default: '' + default: "" RUN_LINT: required: false type: boolean @@ -33,10 +33,47 @@ on: required: false type: boolean default: true + CHECK_WORKDIR_CHANGES: + required: true + type: boolean + default: false + CHECK_CUSTOM_DIR: + required: false + type: string + default: "" + CHECK_CHANGES_BY_JOBS: + required: false + type: string + default: "all" + +env: + CHECK_DIR: ${{ inputs.WORKING_DIRECTORY }} jobs: + workdir-has-changes: + runs-on: ubuntu-latest + outputs: + changes-detected: ${{ steps.filter.outputs.changes-detected }} + steps: + - name: Set CHECK_DIR to custom directory if provided + if: ${{ inputs.CHECK_CUSTOM_DIR != '' }} + run: echo "CHECK_DIR=${{ inputs.CHECK_CUSTOM_DIR }}" >> $GITHUB_ENV + - name: Set default CHECK_DIR + if: ${{ inputs.CHECK_CUSTOM_DIR == '' }} + run: echo "CHECK_DIR=${{ inputs.WORKING_DIRECTORY }}" >> $GITHUB_ENV + + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + changes-detected: + - ${{ env.CHECK_DIR }} + dotnet-common: + needs: workdir-has-changes name: Run .NET build, check formatting and test + if: ${{ !inputs.CHECK_WORKDIR_CHANGES || (needs.workdir-has-changes.outputs.changes-detected == 'true' && (inputs.CHECK_CHANGES_BY_JOBS == 'all' || contains(fromJson(inputs.CHECK_CHANGES_BY_JOBS), github.job))) }} runs-on: labels: ${{ inputs.RUN_ON }} group: ${{ inputs.RUNNERS_CONTAINER_GROUP }} diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..b27104bb --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "singleQuote": false, + "printWidth": 120 +} diff --git a/package-lock.json b/package-lock.json index eabb5302..f6e46ee7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "pipeline-templates", "version": "0.0.0-development", "license": "ISC", + "dependencies": { + "prettier": "^3.3.3" + }, "devDependencies": { "@commitlint/cli": "^17.6.5", "@commitlint/config-conventional": "^17.6.5", @@ -7591,6 +7594,21 @@ "node": ">=4" } }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/process-nextick-args": { "version": "2.0.1", "dev": true, diff --git a/package.json b/package.json index 01d8f19f..95fb159d 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "semantic-release": "^21.0.3" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", + "format": "prettier --write .", "semantic-release": "semantic-release" }, "repository": { @@ -34,5 +34,8 @@ "bugs": { "url": "https://github.com/zupit-it/pipeline-templates/issues" }, - "homepage": "https://github.com/zupit-it/pipeline-templates#readme" + "homepage": "https://github.com/zupit-it/pipeline-templates#readme", + "dependencies": { + "prettier": "^3.3.3" + } }