From 82596edd3cadd50680331ae171da457006e43c35 Mon Sep 17 00:00:00 2001 From: borland Date: Fri, 14 Mar 2025 09:36:50 +1300 Subject: [PATCH 1/2] Add dotnet format workflow --- .github/workflows/dotnet-format.yaml | 69 ++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/dotnet-format.yaml diff --git a/.github/workflows/dotnet-format.yaml b/.github/workflows/dotnet-format.yaml new file mode 100644 index 0000000..da1b8f7 --- /dev/null +++ b/.github/workflows/dotnet-format.yaml @@ -0,0 +1,69 @@ +name: "Dotnet Format" + +# Controls when the action will run. +on: + schedule: + # Weekly At 19:00 on Monday. - 5am Australian/Brisbane time + - cron: '0 19 * * 1' + pull_request: + types: [opened, synchronize, reopened] + workflow_dispatch: + # Allows you to run this workflow manually from the Actions tab + +jobs: + build: + name: "Format code and Create Pull Request if any changes" + runs-on: ubuntu-latest + permissions: + contents: write # Read Required to check out code, Write to create Git Tags + pull-requests: write + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Run dotnet format + run: dotnet format --verbosity normal + working-directory: ./source + + - name: Check for changes + id: detect_changes + run: | + set +e + git diff --quiet + + if [ "$?" -eq 0 ]; then + echo "No changes detected." + else + echo "Changes detected." + echo "changes_detected=true" >> "$GITHUB_OUTPUT" + fi + + - name: Create Pull Request if Changes Detected + if: steps.detect_changes.outputs.changes_detected == 'true' + env: + GH_TOKEN: ${{ secrets.RENOVATE_GITHUB_TOKEN }} + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} + GITHUB_REPOSITORY: ${{ github.repository }} + run: | + git config user.email "bob@octopus.com" + git config user.name "GitHub Actions" + + dateTimeStamp="$(date +'%Y%m%d%H%M%S')" + branchName="dotnet-format/$dateTimeStamp" + + git checkout -b "$branchName" + git add -A ./source + git commit -m "Run dotnet format" + git push -f --set-upstream origin "$branchName" + + # Always target PR's at the default branch + targetBranchName="${{ github.event.repository.default_branch }}" + gh pr create -t "$branchName" --head "$branchName" --base "$targetBranchName" --body "This PR was created automatically by the dotnet-format workflow." + From 6e8b1ad03cc538a8951189093c00024fa5cb9b9a Mon Sep 17 00:00:00 2001 From: borland Date: Fri, 14 Mar 2025 09:40:04 +1300 Subject: [PATCH 2/2] Experiment: Severity info --- .github/workflows/dotnet-format.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet-format.yaml b/.github/workflows/dotnet-format.yaml index da1b8f7..e92d265 100644 --- a/.github/workflows/dotnet-format.yaml +++ b/.github/workflows/dotnet-format.yaml @@ -29,7 +29,7 @@ jobs: dotnet-version: 8.0.x - name: Run dotnet format - run: dotnet format --verbosity normal + run: dotnet format --verbosity normal --severity info working-directory: ./source - name: Check for changes