Skip to content

Run formatter

Run formatter #32

Workflow file for this run

name: Run formatter
# This action will be run weekly against main and can be run on-demand against main.
# It will run an automated code formatter and commit and push the changes (if any). If the source branch is protected, then the workflow will create a new branch to commit and push the changes.
on:
schedule:
- cron: '30 4 * * SUN'
workflow_dispatch:
jobs:
main:
name: Reformat code
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
env:
# don't print dotnet logo
DOTNET_NOLOGO: true
# disable telemetry (reduces dotnet tool output in logs)
DOTNET_CLI_TELEMETRY_OPTOUT: true
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: npm ci
run: npm ci
working-directory: ./src/vscode-bicep
- name: Format .NET code
run: |
dotnet format
dotnet format style --diagnostics IDE0005 --severity info
- name: Format vscode-bicep
run: npm run format
working-directory: ./src/vscode-bicep
- name: Commit and push formatting updates
if: (!github.ref_protected)
run: |
git config --global user.email "[email protected]"
git config --global user.name "Bicep Automation"
git add .
if ! git diff-index --quiet HEAD --; then
git commit -m "Run code formatter"
git push
fi
- name: Commit formatting updates to branch.
id: commit_for_pr
if: github.ref_protected
env:
BRANCH_ID: chores/format/${{ github.ref_name }}
run: |
git checkout -b $BRANCH_ID
git config --global user.email "[email protected]"
git config --global user.name "Bicep Automation"
git add .
if ! git diff-index --quiet HEAD --; then
git commit -m "Run code formatter"
git push -fu origin $BRANCH_ID
echo "UPDATES_BRANCH=$BRANCH_ID" >> "$GITHUB_OUTPUT"
else
echo "UPDATES_BRANCH=nil" >> "$GITHUB_OUTPUT"
fi
- name: Open issue to merge updates
if: ${{ github.ref_protected && steps.commit_for_pr.outputs.UPDATES_BRANCH != 'nil' }}
uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SOURCE_BRANCH: ${{ steps.commit_for_pr.outputs.UPDATES_BRANCH }}
with:
update_existing: true
filename: .github/workflows/formatter_update.md