This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
90 lines (89 loc) · 3.31 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: 'action-update-dprint-plugins'
description: 'Update dprint plugins in dprint.json config file'
author: 'Kenichi Kamiya <[email protected]>'
branding:
icon: 'arrow-up-circle'
color: 'blue'
inputs:
base-branch:
description: 'The branch into which you want updating PR merged'
required: true
github-token:
description: 'The token will be used to create PR'
required: true
default: ${{ github.token }}
dprint-version:
description: 'Specific dprint version to use (ex. 0.40.1)'
required: true
config-path:
description: 'Specific dprint config to use (ex. dprint-ci.json)'
required: true
default: 'dprint.json'
fmt:
description: 'Run fmt and outputs the result in outputs.fmt if enabled. It may fail from some reasons'
required: false
default: false
outputs:
pr_url:
description: 'Created PR URL'
value: ${{ steps.pr.outputs.pr_url }}
fmt:
description: 'diff was made with `dprint fmt` after updating plugins'
value: ${{ steps.fmt.outputs.fmt }}
runs:
using: 'composite'
steps:
- name: Checkout
uses: actions/checkout@v3
- id: setup
run: |
timestamp=`date +"%Y%m%d-%H%M-UTC"`
echo "timestamp=${timestamp}" >> $GITHUB_OUTPUT
echo "branch=action-update-dprint-plugins-${timestamp}" >> $GITHUB_OUTPUT
shell: bash
- name: git setting
run: |
git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com'
git config --local user.name 'github-actions[bot]'
shell: bash
# Referenced https://github.com/dprint/check/blob/2f1cf31537886c3bfb05591c031f7744e48ba8a1/action.yml#L16-L20
- name: Install dprint
shell: bash
run: |
curl -fsSL https://dprint.dev/install.sh | sh -s ${{ inputs.dprint-version }} > /dev/null 2>&1
echo "/home/runner/.dprint/bin" >> $GITHUB_PATH
- name: Create branch
run: |
git switch -c "${{ steps.setup.outputs.branch }}"
shell: bash
- id: update_plugins
run: |
command="dprint config update --yes --config ${{ inputs.config-path }}"
~/.dprint/bin/${command}
if git add --intent-to-add . && git diff --exit-code; then
echo 'update=false' >> $GITHUB_OUTPUT
else
echo 'update=true' >> $GITHUB_OUTPUT
git commit -a -m "chore: \`${command}\`"
fi
shell: bash
- id: fmt
if: ${{ inputs.fmt == 'true' && steps.update_plugins.outputs.update == 'true' }}
run: |
command="dprint fmt --config ${{ inputs.config-path }}"
~/.dprint/bin/${command}
if git add --intent-to-add . && git diff --exit-code; then
echo 'fmt=false' >> $GITHUB_OUTPUT
else
echo 'fmt=true' >> $GITHUB_OUTPUT
git commit -a -m "chore: \`${command}\`"
fi
shell: bash
- id: pr
if: ${{ steps.update_plugins.outputs.update == 'true' && (inputs.fmt == 'false' || steps.fmt.outputs.fmt == 'true') }}
run: |
git push -u origin "${{ steps.setup.outputs.branch }}"
echo "pr_url=$(gh pr create --fill --base ${{ inputs.base-branch}} --title 'Update dprint plugins' --body 'This PR has been created by https://github.com/kachick/action-update-dprint-plugins')" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: '${{ inputs.github-token }}'
shell: bash