Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/dotnet-format.yaml
Original file line number Diff line number Diff line change
@@ -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 --severity info
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."

Loading