-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
211 lines (198 loc) · 7.29 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# SPDX-FileCopyrightText: 2022 Alec Delaney, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
name: 'Build package of .mpy files'
description: 'Build mpy-cross for usage in GitHub Actions'
inputs:
github-token:
description: 'Your GitHub token, needed to upload the ZIP file'
required: true
circuitpy-tag:
description: 'The CircuitPython version of mpy-cross to build'
required: true
zip-filename:
description: 'The name of the ZIP file to attach'
required: true
default: "mpy-release.zip"
circuitpython-repo-name:
description: >
The name for the CircuitPython repo. The default is 'circuitpython-repo',
and there typically isn't any reason to change this unless it conflicts
with an existing folder name in your repository.
required: true
default: 'circuitpython-repo'
mpy-directory:
description: >
The directory to look for files to compile with mpy-cross. If none
is provided, the root directory will be used. This also becomess the
basis for filepaths in the mpy manifest file, if one is provided.
required: true
default: "."
mpy-manifest-file:
description: >
Path to a manifest file containing filepaths to convert. If no
manifest is provided, all applicable files will be converted.
required: true
default: ""
mpy-manifest-type:
description: >
The type of manifest to use for compiling if one is provided. The
default is "include", but if "exclude" is provided, then all Python
files EXCEPT the ones listed will be compuled with mpy-cross.
required: true
default: "include"
zip-directory:
description: >
The directory of files to bundle. If none is provided, the root
directory will be used. This also becomess the basis for filepaths
in the zip manifest file, if one is provided.
required: true
default: "."
zip-manifest-file:
description: >
Path to a manifest file containing filepaths to include in the zip
file. If no manifest is provided, all files will be included. Either
this or exclude-zip-manifest can be defined.
required: true
default: ""
zip-manifest-type:
description: >
The type of manifest to use for zipping, if one is provided. The
default is "include", but if "exclude" is provided, then all files
EXCEPT the ones listed will be zipped.
required: true
default: "include"
runs:
using: "composite"
steps:
- name: Install zip
shell: bash
run: |
sudo apt install zip
- name: Install build tools
shell: bash
run: |
sudo apt install build-essential
sudo add-apt-repository ppa:pybricks/ppa
sudo apt install git gettext uncrustify
- name: Clone adafruit/circuitpython
uses: actions/checkout@v3
with:
repository: adafruit/circuitpython
path: ${{ inputs.circuitpython-repo-name }}
- name: Enter CircuitPython repo, checkout tag, and update
shell: bash
run: |
function version() {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
}
cd ${{ inputs.circuitpython-repo-name }}
git fetch
git checkout ${{ inputs.circuitpy-tag }}
if [ $(version "${{ inputs.circuitpy-tag }}") -ge $(version "8.2.0") ]; then
make fetch-all-submodules
else
make fetch-submodules
fi
- name: Build mpy-cross
shell: bash
run: |
cd ${{ inputs.circuitpython-repo-name }}/mpy-cross
make clean
make
- name: Compile MPY files
shell: bash
run: |
# Store repo name
reponame="${{ inputs.circuitpython-repo-name }}"
# Read MPY manifest file contents, if needed
if [[ "${{ inputs.mpy-manifest-file }}" != "" ]]
then
readarray mpymanifestfiles < "${{ inputs.mpy-manifest-file }}"
for file in ${mpymanifestfiles[@]}
do
if [[ $file = *[[:space:]]* ]] || [[ $file == "#*" ]]
then
mpymanifestfiles=( $"{mpymanifestfiles[@]/$file}" )
fi
done
fi
# Compile MPY files
mpyresults=()
prempyfiles=()
pyfiles=$(find ${{ inputs.mpy-directory }} -name "*.py" ! -path "./${{ inputs.circuitpython-repo-name }}/*" ! -name "code.py" -printf '%P\n')
for file in ${pyfiles[@]}
do
if [[ "${{ inputs.mpy-manifest-file }}" == "" ]] || \
[[ ( "${{ inputs.mpy-manifest-type }}" == "include" && "${mpymanifestfiles[*]}" =~ "${file}" ) || \
( "${{ inputs.mpy-manifest-type }}" == "exclude" && ! "${mpymanifestfiles[*]}" =~ "${file}" ) ]]
then
echo "Compiling $file"
outputmpy="${{ inputs.mpy-directory }}/${file%.*}.mpy"
mpyresults+=("$outputmpy")
prempyfile="${{ inputs.mpy-directory }}/$file"
prempyfiles+=("$prempyfile")
${reponame}/mpy-cross/mpy-cross $prempyfile -o $outputmpy
fi
done
# Delete the CircuitPython repo
echo "Deleting CircuitPython repository folder"
rm -r ${{ inputs.circuitpython-repo-name }}
# Read ZIP manifest file contents, if needed
if [[ "${{ inputs.zip-manifest-file }}" != "" ]]
then
readarray zipmanifestfiles < "${{ inputs.zip-manifest-file }}"
for file in ${zipmanifestfiles[@]}
do
if [[ $file = *[[:space:]]* ]] || [[ $file == "#*" ]]
then
zipmanifestfiles=( $"{zipmanifestfiles[@]/$file}" )
fi
done
fi
# Zip files
zipresults=()
allfiles=$(find ${{ inputs.zip-directory }} -type f ! -path "./.git/*" -printf '%P\n')
for file in ${allfiles[@]}
do
if [[ "${{ inputs.zip-manifest-file }}" == "" ]] || \
[[ ( "${{ inputs.zip-manifest-type }}" == "include" && "${zipmanifestfiles[*]}" =~ "${file}" ) || \
( "${{ inputs.zip-manifest-type }}" == "exclude" && ! "${zipmanifestfiles[*]}" =~ "${file}" ) ]]
then
potentialmpy="${file%.*}.mpy"
potentialfile="$file"
if [[ "${{ inputs.zip-directory }}" != "." ]]
then
potentialmpy="${{ inputs.zip-directory }}/$potentialmpy"
potentialfile="${{ inputs.zip-directory }}/$file"
fi
if [[ "${prempyfiles[*]}" =~ "${potentialfile}" ]]
then
continue
fi
if [[ "${mpyresults[*]}" =~ "${potentialmpy}" ]] && [[ ! -a "$file" ]]
then
zipresults+=("$potentialmpy")
else
zipresults+=("$potentialfile")
fi
fi
done
# Create the ZIP file
zip ${{ inputs.zip-filename }} "${zipresults[@]}"
# Delete MPY files
for file in ${mpyresults[@]}
do
echo "Deleting $file"
rm $file
done
- name: Upload ZIP file to release
uses: shogo82148/actions-upload-release-asset@v1
with:
asset_path: ${{ inputs.zip-filename }}
github_token: ${{ inputs.github-token }}
upload_url: ${{ github.event.release.upload_url }}
- name: Delete ZIP file
shell: bash
run: |
rm ${{ inputs.zip-filename }}