-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
76 lines (76 loc) · 2.32 KB
/
action.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
name: 'dotnet-format on Pull Request'
description: 'Run dotnet-format on Pull Request'
author: 'tsubakimoto'
branding:
icon: 'check-circle'
color: 'blue'
inputs:
base-branch:
description: 'Base branch to compare against'
required: true
default: 'main'
project-path:
description: 'Path to the project to format'
required: true
verbosity:
description: 'Verbosity of the output'
required: false
default: 'normal'
github-token:
description: 'GitHub token'
required: true
outputs:
head-branch:
description: 'Head branch to compare against'
value: ${{ steps.commit.outputs.head-branch-name }}
changed:
description: 'Whether there are any changes'
value: ${{ steps.diff.outputs.changed }}
pull-request-url:
description: 'URL of the pull request'
value: ${{ steps.pr.outputs.url }}
runs:
using: 'composite'
steps:
- name: Format source
id: format
run: |
dotnet format ${{ inputs.project-path }} --verbosity ${{ inputs.verbosity }}
shell: bash
- name: Check if there are any changes
id: diff
run: |
git diff --quiet . || echo "changed=true" >> $GITHUB_OUTPUT
shell: bash
- name: Commit changes
if: steps.diff.outputs.changed == 'true'
id: commit
run: |
HEAD_BRANCH=dotnet-format-${{ inputs.base-branch }}
git checkout -b $HEAD_BRANCH
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git add .
git commit -m "[bot] Auto formatted"
git push --set-upstream origin $HEAD_BRANCH
echo "head-branch-name: $HEAD_BRANCH"
echo "head-branch-name=$HEAD_BRANCH" >> $GITHUB_OUTPUT
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
- name: Create a pull request
id: pr
run: |
BASE_BRANCH=${{ inputs.base-branch }}
HEAD_BRANCH=${{ steps.commit.outputs.head-branch-name }}
TITLE="Auto format on $BASE_BRANCH"
url=$(gh pr create \
--base $BASE_BRANCH \
--head $HEAD_BRANCH \
--title "$TITLE" \
--body "$TITLE")
echo "Successfully created pull request: $url"
echo "url=$url" >> $GITHUB_OUTPUT
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}