-
Notifications
You must be signed in to change notification settings - Fork 3
72 lines (61 loc) · 1.89 KB
/
format.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
name: Format With Prettier
on:
pull_request:
branches:
- main
push:
branches:
- main
permissions:
contents: write
actions: read
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Pull latest changes
run: |
if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then
git fetch origin
git checkout "${GITHUB_HEAD_REF}"
git pull origin "${GITHUB_HEAD_REF}"
elif [ "${GITHUB_EVENT_NAME}" == "push" ]; then
git fetch origin
git pull origin "${GITHUB_REF#refs/heads/}"
fi
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "16"
- name: Clean Install
run: |
if [ -d "node_modules" ]; then
rm -rf node_modules
fi
npm install
- name: Apply Prettier Foramtting
run: npx prettier --write "**/*.java"
- name: Check for Changes
id: git-check
run: |
git diff --exit-code || echo "Changes detected"
continue-on-error: true
- name: Commit Changes
if: steps.git-check.outcome == 'success'
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
git add .
git commit -m 'Apply Prettier format' || echo "No changes to commit"
if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then
git push origin "${GITHUB_HEAD_REF}"
elif [ "${GITHUB_EVENT_NAME}" == "push" ]; then
git push origin "${GITHUB_REF#refs/heads/}"
fi
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Notify if no Changes
if: steps.git-check.outcome == 'failure'
run: echo "Formatting not Required"