Repository navigation
100 lines (86 loc) · 2.97 KB
/
Copy pathautoformat-v2.yml
File metadata and controls
100 lines (86 loc) · 2.97 KB
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
91
92
93
94
95
96
97
98
99
100
name: Autoformat code v2
on: pull_request
env:
DOTNET_CLI_TELEMETRY_OPTOUT: '1'
permissions: {}
jobs:
# Job for same-repo PRs: format and push directly
autoformat-push:
name: Autoformat and push
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: write
steps:
- name: 'Checkout'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.head_ref }}
fetch-depth: 1
persist-credentials: false
- name: 'Install .NET'
uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0
with:
global-json-file: ./global.json
- name: 'Autoformat'
run: ./tools/autoformat.sh
- name: 'Check for changes'
id: check
run: |
if git diff --quiet; then
echo "changes=false" >> "$GITHUB_OUTPUT"
else
echo "changes=true" >> "$GITHUB_OUTPUT"
fi
- name: 'Commit and push'
if: steps.check.outputs.changes == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
git config user.email 'github-actions-autoformatter@xamarin.com'
git config user.name 'GitHub Actions Autoformatter'
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}"
git add -A
git commit -m 'Auto-format source code'
git push
# Job for fork PRs: format and upload patch as artifact
autoformat-artifact:
name: Autoformat and upload patch
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name != github.repository
permissions:
contents: read
steps:
- name: 'Checkout'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
fetch-depth: 1
- name: 'Install .NET'
uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0
with:
global-json-file: ./global.json
- name: 'Autoformat'
run: ./tools/autoformat.sh
- name: 'Create patch'
id: patch
run: |
if git diff --quiet; then
echo "changes=false" >> "$GITHUB_OUTPUT"
else
echo "changes=true" >> "$GITHUB_OUTPUT"
git config user.email 'github-actions-autoformatter@xamarin.com'
git config user.name 'GitHub Actions Autoformatter'
git add -A
git commit -m 'Auto-format source code'
mkdir -p autoformat-output
git format-patch HEAD~1 --stdout > autoformat-output/autoformat.patch
fi
- name: 'Upload patch'
if: steps.patch.outputs.changes == 'true'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: autoformat
path: autoformat-output/