-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
154 lines (134 loc) · 4.55 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/metadata-syntax-for-github-actions
name: 'XML reformat'
description: 'Reformat XML files'
author: "@tomschr"
inputs:
config:
description: "The config file to use for xmlformat"
required: false
default: ""
exclude-files:
description: "Exclude files from reformatting"
required: false
default: ""
extensions:
description: "Define file extensions for XML files (without dots or globs)"
required: false
default: "xml"
commit:
description: "Should the formatted files committed? Use true, yes, or 1."
required: false
default: true
commit-message:
description: "Use this commit message for the reformatting step"
required: false
default: "[xml-format-action] Auto reformatting XML Files"
repo-token:
description: "The GitHub token"
required: true
# default: ${{ secrets.GITHUB_TOKEN }}
xmlformat-variant:
description: "Which xmlformat package should be installed? (perl|ruby)"
required: false
default: "perl"
xmlformat-use-tag:
description: "Use the given tag from upstream GH repository"
required: false
default: "1.9"
outputs:
xmlfound:
description: "Does the commit contains some XML files?"
value: ${{ steps.reformat.outputs.xmlfound }}
runs:
using: "composite"
steps:
- id: gh-context
name: Saving the GitHub context as JSON
shell: bash
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: |
FILE="/tmp/github-context.json"
echo $GITHUB_CONTEXT > $FILE
echo "::set-output name=contextfile::$FILE"
# - id: install-packages
# name: Installing packages
# shell: bash
# env:
# PACKAGE: "${{ inputs.xmlformat-variant }}"
# run: |
# if [[ ! ( "$PACKAGE" = "perl" || "$PACKAGE" = "ruby") ]]; then
# echo "::error file=action.yml::Input xmlformat-variant contains an invalid value. Only 'perl' or 'ruby' is allowed."
# exit 10
# fi
# PACKAGES="xmlformat-$PACKAGE"
# echo "::group::Installing package(s) $PACKAGES..."
# sudo apt-get install -y $PACKAGES
# echo "::endgroup::"
- id: install-xmlformat-from-github
name: Install xmlformat from GitHub
shell: bash
env:
UPSTREAM_GIT_REPO: "https://github.com/someth2say/xmlformat.git"
TAG: ${{ inputs.xmlformat-use-tag }}
run: |
echo "::group::Clone from upstream repository${TAG:+ using tag $TAG}..."
git config advice.detachedHead false
git clone -v ${TAG:+--branch $TAG} $UPSTREAM_GIT_REPO
echo "::endgroup::"
- id: create-symbolic-link
name: Create symbolic link to xmlformat
shell: bash
run: |
echo "::group::Create symbolic link to xmlformat..."
if [ -e xmlformat/bin ]; then
cd xmlformat/bin
case "${{ inputs.xmlformat-variant }}" in
Perl|perl|pl)
EXT=pl
;;
Ruby|ruby|rb)
EXT=rb
;;
*)
echo "::error file=action.yml::xmlformat-variant can only contain perl or ruby, got ${{ inputs.xmlformat-variant }}."
;;
esac
# Default to the Perl variant
ln -sv xmlformat.${EXT:-pl} xmlformat
cd - >/dev/null
fi
echo "::endgroup::"
- id: path
name: Export PATH content
shell: bash
run: |
PATH="$PWD/xmlformat/bin:$PATH"
echo "::set-output name=PATH::$PATH"
- id: version
name: Version of xmlformat
shell: bash
run: |
echo "::group::Find appropriate xmlformat variant..."
export PATH="${{ steps.path.outputs.PATH }}"
type xmlformat xmlformat.pl xmlformat.rb
xmlformat --version
echo "::endgroup::"
- id: reformat
shell: bash
run: |
CONFIG="${{ inputs.config }}"
EXCLUDES="${{ inputs.exclude-files }}"
MESSAGE="${{ inputs.commit-message }}"
export PATH="${{ steps.path.outputs.PATH }}"
${{ github.action_path }}/xml-format-action.sh -vv ${CONFIG:+--config-file "$CONFIG"} \
${EXCLUDES:+--excludes="$EXCLUDES"} \
--extensions="${{ inputs.extensions }}" \
--need-commit ${{ inputs.commit }} \
${MESSAGE:+--message="$MESSAGE"} \
--token=${{ inputs.repo-token }} \
--context "${{ steps.gh-context.outputs.contextfile }}" \
"${{ github.sha }}"
branding:
icon: "git-merge"
color: "green"