-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
119 lines (115 loc) · 4.67 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Enforce-CRLF
description: 'Enforce CRLF.'
branding:
icon: "corner-down-left"
color: "blue"
inputs:
extensions:
description: 'List of extensions (including the dot) seperated by a comma.'
required: true
do-checkout:
description: 'Set to true in order to let the action perform the checkout for you (default = false).'
default: false
do-push:
description: 'Set to true in order to let the action perform the checkout for you (default = false).'
default: false
bot-name:
description: 'Name of the bot that will perform the commit.'
default: 'github-actions[bot]'
bot-email:
description: 'Email of the bot that will perform the commit.'
default: '41898282+github-actions[bot]@users.noreply.github.com'
runs:
using: "composite"
steps:
- name: Check inputs
run: |
echo "extensions: '${{ inputs.extensions }}'"
if [[ -z "${{ inputs.extensions }}" ]]; then
echo "🔴 Error: No extensions provided."
echo "Make sure you include the extensions input parameter. ie.:"
echo " uses: DecimalTurn/Enforce-CRLF@main"
echo " with:"
echo " extensions: .bas, .frm, .cls"
exit 1
fi
IFS=',' read -r -a ext_array <<< "${{ inputs.extensions }}"
for ext in "${ext_array[@]}"; do
ext=$(echo "$ext" | xargs) # Trim leading and trailing spaces
if [[ $ext != .* ]]; then
echo "🔴 Error: Extension '${ext}' does not begin with a dot."
exit 1
fi
if [[ $ext =~ \ ]]; then
echo "🔴 Error: Extension '${ext}' contains a space."
exit 1
fi
done
shell: bash
- name: Configure Git
run: |
git config --global core.autocrlf false
git config --global core.eol lf
shell: bash
- name: Checkout
if: ${{ inputs.do-checkout }}
uses: actions/checkout@v4
- name: Check EOL configs
run: |
IFS=',' read -r -a ext_array <<< "${{ inputs.extensions }}"
for ext in "${ext_array[@]}"; do
result=$(git check-attr text *"${ext}")
echo "$result"
if [[ $result == *"text: auto" || $result == *"text: text" ]]; then
echo "There is an issue with the ${ext} extension. The `text` attribute is set or it has a value of `auto` for that extension."
echo "This means that you won't be able to commit changes with CRLF. You need to make sure that `text` is unspecified or unset (-text)"
exit 1
fi
done
shell: bash
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Get tofrodos package
uses: awalsh128/cache-apt-pkgs-action@a6c3917cc929dd0345bfb2d3feaf9101823370ad #v1.4.2
with:
packages: tofrodos
version: 1.0
- name: Run script
run: |
python '${{ github.action_path }}/enforce-crlf.py' "${{ inputs.extensions }}"
shell: bash
- name: Push content
if: ${{ inputs.do-push }}
uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842 #v5.0.1
with:
# Optional. Commit message for the created commit.
# Defaults to "Apply automatic changes"
commit_message: "Enforce CRLF\n\nGitHub Action: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
# Optional commit user and author settings
commit_user_name: ${{ inputs.bot-name }} # defaults to "github-actions[bot]"
commit_user_email: ${{ inputs.bot-email }} # defaults to "41898282+github-actions[bot]@users.noreply.github.com"
# Alternative approach to Push content using a bash script
# - name: Push content
# run: |
# git config user.name "${{ inputs.bot-name }}"
# git config user.email "${{ inputs.bot-email }}"
# # Create an array of extensions
# IFS=',' read -r -a extensions <<< "${{ inputs.extensions }}"
# # Add files with the specified extensions
# for ext in "${extensions[@]}"; do
# trimmed_ext=$(echo "$ext" | xargs) # Trim spaces
# echo "Adding files with extension: *$trimmed_ext"
# git add -v *"$trimmed_ext" || true
# done
# git status
# if [ -n "$(git diff --cached --exit-code)" ]; then
# echo "Changes detected"
# commit_message=$(printf "Enforce CRLF\n\nGitHub Action: %s/%s/actions/runs/%s" "${{ github.server_url }}" "${{ github.repository }}" "${{ github.run_id }}")
# git commit -m "$commit_message"
# git push --set-upstream origin $branch_name
# else
# echo "No changes to commit"
# fi
# shell: bash