-
Notifications
You must be signed in to change notification settings - Fork 756
109 lines (89 loc) · 3.1 KB
/
run-formatter.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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: Format .NET code
run: |
dotnet format
dotnet format style --diagnostics IDE0005 --severity info
- name: Format Bicep.Cli.E2eTests
run: |
npm ci
npm run format
working-directory: ./src/Bicep.Cli.E2eTests
- name: Format Bicep.MSBuild.E2eTests
run: |
npm ci
npm run format
working-directory: ./src/Bicep.MSBuild.E2eTests
- name: Format vscode-bicep-ui
run: |
npm ci
npm run format
working-directory: ./src/vscode-bicep-ui
- name: Format vscode-bicep
run: |
npm ci
npm run format
working-directory: ./src/vscode-bicep
- name: Commit and push formatting updates
if: (!github.ref_protected)
run: |
git config --global user.email "bicep@noreply.github.com"
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 "bicep@noreply.github.com"
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