diff --git a/.github/actions/docfx-build/action.yml b/.github/actions/documentation/docfx-build/action.yml similarity index 100% rename from .github/actions/docfx-build/action.yml rename to .github/actions/documentation/docfx-build/action.yml diff --git a/.github/actions/docfx-metadata/action.yml b/.github/actions/documentation/docfx-metadata/action.yml similarity index 100% rename from .github/actions/docfx-metadata/action.yml rename to .github/actions/documentation/docfx-metadata/action.yml diff --git a/.github/actions/push-changes/action.yml b/.github/actions/git/push-changes/action.yml similarity index 100% rename from .github/actions/push-changes/action.yml rename to .github/actions/git/push-changes/action.yml diff --git a/.github/actions/write-file-to-summary/action.yml b/.github/actions/github/write-file-to-summary/action.yml similarity index 100% rename from .github/actions/write-file-to-summary/action.yml rename to .github/actions/github/write-file-to-summary/action.yml diff --git a/.github/actions/publish-nuget-package/action.yml b/.github/actions/nuget/publish-package/action.yml similarity index 100% rename from .github/actions/publish-nuget-package/action.yml rename to .github/actions/nuget/publish-package/action.yml diff --git a/.github/actions/compile/action.yml b/.github/actions/source/compile/action.yml similarity index 96% rename from .github/actions/compile/action.yml rename to .github/actions/source/compile/action.yml index 849364dd..7e6eea46 100644 --- a/.github/actions/compile/action.yml +++ b/.github/actions/source/compile/action.yml @@ -1,4 +1,4 @@ -name: 'Compile with .NET CLI' +name: 'Compile source code' author: 'Pete Sramek' description: 'Compiles source code, uploads build artifacts.' inputs: @@ -71,4 +71,4 @@ runs: uses: actions/upload-artifact@v4 with: name: ${{ inputs.build-artifacts-name }} - path: ${{ inputs.build-artifacts-glob-pattern }} \ No newline at end of file + path: ${{ inputs.build-artifacts-glob-pattern }} diff --git a/.github/actions/source/format/action.yml b/.github/actions/source/format/action.yml new file mode 100644 index 00000000..f932a166 --- /dev/null +++ b/.github/actions/source/format/action.yml @@ -0,0 +1,73 @@ +name: 'Format source code' +author: 'Pete Sramek' +description: 'Formats source code using dotnet format tool. Pushes changes to the current branch.' +inputs: +# Required + project-path: + description: 'Path to the project or solution file.' + required: true +# Optional + dotnet_sdk_version: + description: '.NET SDK version. Default: ''9.x''' + required: false + default: '9.x' + format-whitespace: + description: 'Format whitespace. Default: ''true''' + required: false + default: 'true' + format-style: + description: 'Format style. Default: ''true''' + required: false + default: 'true' + format-analyzers: + description: 'Format analyzers. Default: ''false''' + required: false + default: 'false' + format-analyzers-diagnostics-parameter: + description: 'Format analyzers diagnostics parameter. Default: ''''' + required: false + default: '' + +runs: + using: "composite" + steps: + - name: 'Checkout ${{ github.head_ref || github.ref }}' + uses: actions/checkout@v5 + + - name: 'Setup .NET ${{ inputs.dotnet_sdk_version }}' + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ inputs.dotnet_sdk_version }} + + - name: Format whitespace + if: ${{ inputs.format-whitespace == 'true' }} + shell: bash + run: | + dotnet format whitespace + working-directory: ${{ github.workspace }} + + - name: Format style + if: ${{ inputs.format-style == 'true' }} + shell: bash + run: | + dotnet format style + working-directory: ${{ github.workspace }} + + - name: 'Set target branch' + if: ${{ inputs.format-analyzers == 'true' && inputs.format-analyzers-diagnostics-parameter != '' }} + id: set-diagnostics-parameter + shell: bash + run: | + echo "format-analyzers-diagnostics-parameter=--diagnostics ${{ inputs.format-analyzers-diagnostics-parameter }}" >> $GITHUB_OUTPUT + + - name: Format analyzers + if: ${{ inputs.format-analyzers == 'true' }} + shell: bash + run: | + dotnet format analyzers ${{ env.format-analyzers-diagnostics-parameter }} + working-directory: ${{ github.workspace }} + + - name: 'Push changes' + uses: './.github/actions/git/push-changes' + with: + commit-message: 'Formatted csharp files' diff --git a/.github/actions/code-coverage/action.yml b/.github/actions/testing/code-coverage/action.yml similarity index 100% rename from .github/actions/code-coverage/action.yml rename to .github/actions/testing/code-coverage/action.yml diff --git a/.github/actions/test-report/action.yml b/.github/actions/testing/test-report/action.yml similarity index 100% rename from .github/actions/test-report/action.yml rename to .github/actions/testing/test-report/action.yml diff --git a/.github/actions/test/action.yml b/.github/actions/testing/test/action.yml similarity index 100% rename from .github/actions/test/action.yml rename to .github/actions/testing/test/action.yml diff --git a/.github/actions/extract-version/action.yml b/.github/actions/versioning/extract-version/action.yml similarity index 100% rename from .github/actions/extract-version/action.yml rename to .github/actions/versioning/extract-version/action.yml diff --git a/.github/actions/format-version/action.yml b/.github/actions/versioning/format-version/action.yml similarity index 100% rename from .github/actions/format-version/action.yml rename to .github/actions/versioning/format-version/action.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 81c49dd9..874720b6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,7 +43,7 @@ jobs: echo "is-preview:${{ startsWith(github.ref_name, 'preview') }}" versioning: - name: 'Extract version (new)' + name: 'Extract version' runs-on: ubuntu-latest outputs: friendly-version: ${{ steps.format-version.outputs.friendly-version }} @@ -60,7 +60,7 @@ jobs: dotnet-version: ${{ env.dotnet-sdk-version }} - name: 'Extract version from branch name' id: extract-version - uses: './.github/actions/extract-version' + uses: './.github/actions/versioning/extract-version' with: branch-name: ${{ github.ref_name }} - name: 'Create pre-release tag' @@ -82,7 +82,7 @@ jobs: echo "build-number=$build_number" >> $GITHUB_OUTPUT - name: 'Format version' id: format-version - uses: ./.github/actions/format-version + uses: ./.github/actions/versioning/format-version with: version: ${{ steps.extract-version.outputs.version }} patch: ${{ github.run_number }} @@ -90,9 +90,22 @@ jobs: sha: ${{ github.sha }} pre-release-tag: ${{ steps.create-pre-release-tag.outputs.pre-release-tag }} + format: + name: 'Format source code' + runs-on: ubuntu-latest + + steps: + - name: 'Checkout ${{ github.head_ref || github.ref }}' + uses: actions/checkout@v5 + + - name: 'Format source code' + uses: ./.github/actions/source/format + with: + project-path: '**/PolylineAlgorithm.csproj' + build: name: 'Compile source code' - needs: [workflow-variables, versioning] + needs: [workflow-variables, versioning, format] runs-on: ubuntu-latest env: @@ -105,7 +118,7 @@ jobs: uses: actions/checkout@v5 - name: 'Compile source code' - uses: ./.github/actions/compile + uses: ./.github/actions/source/compile with: project-path: '**/PolylineAlgorithm.csproj' assembly-version: ${{ env.assembly-version }} @@ -127,14 +140,14 @@ jobs: dotnet-version: ${{ env.dotnet-sdk-version }} - name: 'Run tests' - uses: ./.github/actions/test + uses: ./.github/actions/testing/test with: project-path: '**/PolylineAlgorithm.Tests.csproj' test-results-directory: '${{ runner.temp }}/${{ env.test-result-directory }}/' code-coverage-settings-file: '${{ github.workspace}}/code-coverage-settings.xml' - name: 'Generate test report' - uses: ./.github/actions/test-report + uses: ./.github/actions/testing/test-report id: test-report with: test-result-folder: '${{ runner.temp }}/${{ env.test-result-directory }}/' @@ -143,7 +156,7 @@ jobs: run: cat ${{ steps.test-report.outputs.test-report-file }} >> $GITHUB_STEP_SUMMARY - name: 'Generate code coverage' - uses: ./.github/actions/code-coverage + uses: ./.github/actions/testing/code-coverage id: code-coverage-report with: test-result-folder: '${{ runner.temp }}/${{ env.test-result-directory }}/' @@ -206,7 +219,7 @@ jobs: dotnet-version: ${{ env.dotnet-sdk-version }} - name: 'Publish package to Azure Artifact feed' - uses: ./.github/actions/publish-nuget-package + uses: ./.github/actions/nuget/publish-package with: package-artifact-name: ${{ env.package-artifact-name }} nuget-feed-url: ${{ vars.NUGET_PACKAGE_FEED_URL }} @@ -225,14 +238,14 @@ jobs: - name: 'Checkout ${{ github.head_ref || github.ref }}' uses: actions/checkout@v5 - name: 'Generate assembly metadata' - uses: ./.github/actions/docfx-metadata + uses: ./.github/actions/documentation/docfx-metadata with: artifact-name: 'assembly-metadata' docfx-json-manifest: './api-reference/assembly-metadata.json' temporary-directory: './api-reference/temp' output-directory: './api-reference/${{ env.friendly-version }}' - name: 'Push assembly metadata artifact' - uses: ./.github/actions/push-changes + uses: ./.github/actions/git/push-changes with: artifact-name: 'assembly-metadata' commit-message: 'Updated docs for version ${{ env.friendly-version }}' diff --git a/.github/workflows/format-cs-files.yml b/.github/workflows/format-cs-files.yml deleted file mode 100644 index d08225aa..00000000 --- a/.github/workflows/format-cs-files.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Format *.cs files - -on: - pull_request: - branches: - - 'main' - - 'preview/**' - - 'release/**' - - 'support/**' - paths: - - '**.cs' - -permissions: - actions: read - contents: write - -concurrency: - group: format-${{ github.head_ref || github.ref }} - cancel-in-progress: false - -env: - dotnet-sdk-version: '9.x' - -jobs: - formatting: - name: Format whitespace, code style and file header - runs-on: ubuntu-latest - steps: - - name: Checkout ${{ github.head_ref || github.ref }} - uses: actions/checkout@v5 - with: - fetch-depth: 0 - - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: ${{ env.dotnet-sdk-version }} - - - name: Format with .NET CLI - run: | - dotnet format whitespace - dotnet format style - dotnet format analyzers --diagnostics IDE0005 IDE0073 - working-directory: ${{ github.workspace }} - - - name: 'Push changes' - uses: './.github/actions/push-changes' - with: - commit-message: 'Formatted csharp files' diff --git a/.github/workflows/promote-branch.yml b/.github/workflows/promote-branch.yml index 6ddbbb3f..671f0df2 100644 --- a/.github/workflows/promote-branch.yml +++ b/.github/workflows/promote-branch.yml @@ -33,7 +33,7 @@ env: jobs: versioning: - name: 'Extract version (new)' + name: 'Extract version' runs-on: ubuntu-latest outputs: friendly-version: ${{ steps.extract-version.outputs.version }} @@ -46,7 +46,7 @@ jobs: dotnet-version: ${{ env.dotnet-sdk-version }} - name: 'Extract version from branch name' id: extract-version - uses: './.github/actions/extract-version' + uses: './.github/actions/versioning/extract-version' with: branch-name: ${{ github.ref_name }} workflow-variables: diff --git a/.github/workflows/publish-documentation.yml b/.github/workflows/publish-documentation.yml index 15259491..f5024c62 100644 --- a/.github/workflows/publish-documentation.yml +++ b/.github/workflows/publish-documentation.yml @@ -27,7 +27,7 @@ jobs: echo "github-run-number:${{ github.run_number }}" versioning: - name: 'Extract version (new)' + name: 'Extract version' needs: [workflow-variables] runs-on: ubuntu-latest outputs: @@ -44,7 +44,7 @@ jobs: dotnet-version: ${{ env.dotnet-sdk-version }} - name: 'Extract version from branch name' id: versioning - uses: './.github/actions/extract-version' + uses: './.github/actions/versioning/extract-version' with: branch-name: ${{ github.ref_name }} @@ -59,7 +59,7 @@ jobs: uses: actions/checkout@v5 - name: 'Generate documentation' - uses: ./.github/actions/docfx-build + uses: ./.github/actions/documentation/docfx-build with: artifact-name: 'documentation' docfx-json-manifest: './api-reference/api-reference.json' diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index bf96035e..29075501 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,4 +1,4 @@ -name: Build +name: 'Pull Request' on: pull_request_target: @@ -60,7 +60,7 @@ jobs: dotnet-version: ${{ env.dotnet-sdk-version }} - name: 'Extract version from branch name' id: extract-version - uses: './.github/actions/extract-version' + uses: './.github/actions/versioning/extract-version' with: branch-name: ${{ github.ref_name }} - name: 'Create pre-release tag' @@ -82,7 +82,7 @@ jobs: echo "build-number=$build_number" >> $GITHUB_OUTPUT - name: 'Format version' id: format-version - uses: ./.github/actions/format-version + uses: ./.github/actions/versioning/format-version with: version: ${{ steps.extract-version.outputs.version }} patch: ${{ github.run_number }} @@ -105,7 +105,7 @@ jobs: uses: actions/checkout@v5 - name: 'Compile source code' - uses: ./.github/actions/compile + uses: ./.github/actions/source/compile with: project-path: '**/PolylineAlgorithm.csproj' assembly-version: ${{ env.assembly-version }} @@ -127,14 +127,14 @@ jobs: dotnet-version: ${{ env.dotnet-sdk-version }} - name: 'Run tests' - uses: ./.github/actions/test + uses: ./.github/actions/testing/test with: project-path: '**/PolylineAlgorithm.Tests.csproj' test-results-directory: '${{ runner.temp }}/${{ env.test-result-directory }}/' code-coverage-settings-file: '${{ github.workspace}}/code-coverage-settings.xml' - name: 'Generate test report' - uses: ./.github/actions/test-report + uses: ./.github/actions/testing/test-report id: test-report with: test-result-folder: '${{ runner.temp }}/${{ env.test-result-directory }}/' @@ -143,7 +143,7 @@ jobs: run: cat ${{ steps.test-report.outputs.test-report-file }} >> $GITHUB_STEP_SUMMARY - name: 'Generate code coverage' - uses: ./.github/actions/code-coverage + uses: ./.github/actions/testing/code-coverage id: code-coverage-report with: test-result-folder: '${{ runner.temp }}/${{ env.test-result-directory }}/' @@ -206,7 +206,7 @@ jobs: dotnet-version: ${{ env.dotnet-sdk-version }} - name: 'Publish package to Azure Artifact feed' - uses: ./.github/actions/publish-nuget-package + uses: ./.github/actions/nuget/publish-package with: package-artifact-name: ${{ env.package-artifact-name }} nuget-feed-url: ${{ vars.NUGET_PACKAGE_FEED_URL }}