-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (74 loc) · 2.65 KB
/
auto-format.yaml
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
name: Auto-format
on:
workflow_call:
inputs:
base_branch:
required: false
type: string
workflow_dispatch:
inputs:
base_branch:
description: 'Branch to modify and target for pull request'
default: 'main'
required: false
type: string
jobs:
auto-format:
name: Run JuliaFormatter and create pull request
runs-on: ubuntu-latest
steps:
- name: Set base branch automatically
if: inputs.base_branch == ''
run: |
echo "base_branch=${{ github.head_ref || github.ref_name }}" >> $GITHUB_ENV
echo 'formatter_branch=auto-formatter/${{ github.head_ref || github.ref_name }}' >> $GITHUB_ENV
- name: Read base branch from inputs
if: inputs.base_branch
run: |
echo 'base_branch=${{ inputs.base_branch }}' >> $GITHUB_ENV
echo 'formatter_branch=auto-formatter/${{ inputs.base_branch }}' >> $GITHUB_ENV
- name: View variables
run: |
echo event type: ${{ github.event_name }}
echo base branch: ${{ env.base_branch }}
echo formatter branch: ${{ env.formatter_branch }}
- uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ env.base_branch }}
- name: Set up Github CLI
run: (command -V gh || sudo apt-get -y install gh) && gh --version
- uses: julia-actions/setup-julia@v2
with:
version: '1'
- name: Checkout branch
run: git checkout -B "${{ env.formatter_branch }}"
- uses: julia-actions/cache@v2
- name: Install JuliaFormatter and format
run: make autoformat
- name: Create pull request with changes
run: |
if git diff --quiet ; then
echo "No formatting changes were made"
if q=`gh pr view --json state --template '{{.state}}'` && test "$q" = "OPEN"; then
gh pr close "${{ env.formatter_branch }}" -d
fi
else
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add -u
git commit -m "$base_branch - Automatic JuliaFormatter.jl"
git push -f -u origin "${{ env.formatter_branch }}"
if q=`gh pr view --json state --template '{{.state}}'` && test "$q" != "MERGED"; then
if test "$q" = "OPEN"; then
gh pr view
else
gh pr reopen "${{ env.formatter_branch }}" || gh pr create -B "${{ env.base_branch }}" --fill
fi
else
gh pr create -B "${{ env.base_branch }}" --fill
fi
exit 1
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}