-
-
Notifications
You must be signed in to change notification settings - Fork 77
65 lines (56 loc) · 2.36 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
name: Format sources and commit to branch
on:
workflow_dispatch:
jobs:
format:
# setting the environment on the job is mandatory, otherwise it cannot access environment secrets.
runs-on: ubuntu-latest
steps:
- name: Check write access to repo
run: |
token_login=$(curl -H "Authorization: Bearer ${token}" https://api.github.com/user | jq -r '.login')
echo token login is ${token_login}
echo $(curl -H "Authorization: Bearer ${token}" https://api.github.com/repos/${repo}/collaborators/${token_login}/permission) > result
cat result | jq '.permission == "admin" // .permission == "write"' > /dev/null || ( echo "Token does not have write access to ${repo}" >> ${GITHUB_STEP_SUMMARY}; exit 1)
curl -sS -f -I -H "Authorization: Bearer ${token}" https://api.github.com | grep 'x-oauth-scopes:' | grep 'repo' > /dev/null && exit 0 || echo "Token does not have repo scope on ${repo}" >> ${GITHUB_STEP_SUMMARY}
env:
repo: ${{ github.repository }}
token: ${{ secrets.GITHUB_TOKEN }}
# Set up java with maven cache
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
# configure git
- name: Setup git config
run: |
git config user.name ${{ github.actor }}
git config user.email "<>"
# Check formatting and exit early (with success) if format is ok
- name: Check formatting
run: |
if mvn spotless:check; then
echo "Source was already formatted, nothing was touched." >> $GITHUB_STEP_SUMMARY
exit 0
else
echo "Sources need formatting, we'll do that now"
fi
# Apply formatting (changelog was touched)
- name: Apply formatting
run: mvn spotless:apply
# Commit changes
- name: Commit changes
run: |
git add --all
git commit -m "Apply formatting rules"
# Push changes to branch
- name: Push changes to branch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: git push origin
# print the summary
- name: Print summary
run: echo "Successfully formatted the source files and made a commit." >> $GITHUB_STEP_SUMMARY