-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
228 lines (192 loc) · 9.62 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
name: 'Setup Jython'
description: 'Set up a specific version of Jython and add the command-line tools to the PATH.'
author: 'Luca Salvarani'
branding:
icon: 'package'
color: 'green'
inputs:
jython-version:
description: 'The version of Jython to use'
required: true
installation-path:
description: 'The path where Jython will be installed'
required: false
default: "~/jython/"
outputs:
download-url:
description: "The URL from which the installer is downloaded"
value: ${{ steps.find_installer.outputs.url }}
cache-hit:
description: "Whether the Jython binaries were restored from the cache"
value: ${{ steps.cache-jython.outputs.cache-hit }}
runs:
using: "composite"
steps:
- name: Print runner information
run: |
echo "Action running on ${{ runner.os }} ${{ runner.arch }} (name: '${{ runner.name }}')"
shell: bash
# See https://github.com/actions/toolkit/issues/1035
- uses: actions/github-script@v7
id: resources-hash
with:
script: return require('fs').createReadStream(require('path').join(process.env.GITHUB_ACTION_PATH, 'bin', 'resources.json')).pipe(require('crypto').createHash('sha1').setEncoding('hex'), 'finish').digest('hex')
result-encoding: string
- name: Cache Jython binaries
id: cache-jython
uses: actions/cache@v4
with:
key: ${{ runner.os }}-${{ runner.arch }}-${{ inputs.jython-version }}-${{ steps.resources-hash.outputs.result }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-${{ inputs.jython-version }}-
path: |
${{ inputs.installation-path }}
~/.local/bin/
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'zulu'
# Sadly, macos-latest images use Python 2.7 (dunno why)
- name: Find Jython installer from resource list
id: find_installer
if: ${{ steps.cache-jython.outputs.cache-hit != 'true' }}
shell: python
run: |
import sys, os
import json
with open(r"${{ github.action_path }}/bin/resources.json", "r") as f:
json_content = json.load(f)
matching_versions = [
el for el in json_content
if el["version"] == "${{ inputs.jython-version }}".strip()
]
if not matching_versions:
print("::error title=No matching versions found::No versions were found that matched the string '${{ inputs.jython-version }}'")
sys.exit(1)
print("Found {} versions matching the input string".format(len(matching_versions)))
if len(matching_versions) > 1:
print("::error title=Too many versions found::Too many versions were found ({}) that matched the string '${{ inputs.jython-version }}'".format(len(matching_versions)))
sys.exit(1)
current_runner_os = "${{ runner.os }}-${{ runner.arch }}"
if (
type(matching_versions[0]['available']) == list
and current_runner_os.lower() not in [s.lower() for s in matching_versions[0]['available']]
):
print("::warning title=Version not available for current runner::Runner '{}' not supported".format(current_runner_os))
print("::error title=Version not available for current runner::The specified version (${{ inputs.jython-version }}) is currently available only for the following runners: {} (current is '{}').".format(', '.join(matching_versions[0]['available']), current_runner_os))
sys.exit(1)
elif not matching_versions[0]['available']:
print("::error title=Version not available::The specified version (${{ inputs.jython-version }}) is currently not available for download.")
sys.exit(1)
with open(os.getenv("GITHUB_OUTPUT"), "a+") as f:
file_extension = os.path.splitext(matching_versions[0]["resource_urls"]["official"])[1]
file_extension = file_extension[1:] if file_extension.startswith(".") else file_extension
lines = [
"details='{}'".format(json.dumps(matching_versions[0])),
"url=" + matching_versions[0]['resource_urls']['official'],
"version=" + matching_versions[0]['version'],
"modified_on=" + matching_versions[0]['modified_on'],
"file_type=" + file_extension,
"file_name=jython_installer." + (file_extension if file_extension else ".jar")
]
f.write('\n'.join(lines))
- name: Download Jython Installer
id: download_installer
if: ${{ steps.cache-jython.outputs.cache-hit != 'true' }}
shell: bash
run: |
download_url="${{ steps.find_installer.outputs.url }}";
output_file="/tmp/${{ steps.find_installer.outputs.file_name }}";
printf "Downloading %s file from '%s'...\n" "${{ steps.find_installer.outputs.file_type }}" "${download_url}";
curl -L "${download_url}" --output "${output_file}";
echo "temporary_file=${output_file}" >> "$GITHUB_OUTPUT"
- name: Install Jython
id: installation
if: ${{ steps.cache-jython.outputs.cache-hit != 'true' }}
shell: bash
run: |
case "${{ steps.find_installer.outputs.file_type }}" in
class)
unzip ${{ steps.download_installer.outputs.temporary_file }} -d ${{ inputs.installation-path }}
chmod -R +rwx ${{ inputs.installation-path }};
;;
jar)
# Installation types:
# - all : everything (including src)
# - standard : core, mod, demo, doc, ensurepip
# standard is the default
# - minimum : core
# - standalone: install a single, executable .jar,
# containing all the modules
#
# Note - standalone installation may fail with the following stacktrace (tested on 2.7.2):1
# org.python.util.install.InstallerException: Error accessing jar file
# at org.python.util.install.JarInstaller.inflate(JarInstaller.java:177)
# at org.python.util.install.ConsoleInstaller.install(ConsoleInstaller.java:66)
# at org.python.util.install.Installation.internalMain(Installation.java:389)
# at org.python.util.install.Installation.main(Installation.java:43)
# Caused by: java.util.zip.ZipException: duplicate entry: module-info.class
# at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:232)
# at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:109)
# at org.python.util.install.StandalonePackager.addJarFile(StandalonePackager.java:92)
# at org.python.util.install.JarInstaller.inflate(JarInstaller.java:163)
# ... 3 more
java -jar ${{ steps.download_installer.outputs.temporary_file }} \
--silent \
--directory ${{ inputs.installation-path }} \
--type standard;
;;
esac
printf "Jython installed in the directory '%s'\n\n" "${{ inputs.installation-path }}"
# rm -f ${{ steps.download_installer.outputs.temporary_file }}
- name: Setup Jython alias
if: ${{ steps.cache-jython.outputs.cache-hit != 'true' }}
shell: bash
run: |
installation_path="$(sed -r 's/^\s+//; s/\s+$//; s/\/+$//;' <<< "${{ inputs.installation-path }}")"
mkdir -p ~/.local/bin;
case "${{ steps.find_installer.outputs.file_type }}" in
class)
# cat installer/jython_template.unix_sh
# #!/bin/sh
# ###############################################################################
# #
# # This file generated by Jython installer
# # Created on XXX by @user.name@
#
# "@jvm@" -Dpython.home="@location._top_@" -classpath "@location._top_@/jython.jar:$CLASSPATH" "@classname@" "$@"
jython_cmd="java -cp ${installation_path}/jython.jar org.python.util.jython \"\$@\""
;;
jar)
jython_cmd="java -jar ${installation_path}/jython.jar \"\$@\""
;;
esac
echo "#!/bin/bash" >> ~/.local/bin/jython;
echo "$jython_cmd" >> ~/.local/bin/jython;
chmod +x ~/.local/bin/jython;
- name: Setup Jython alias (pwsh)
if: ${{ steps.cache-jython.outputs.cache-hit != 'true' }}
shell: pwsh
run: |
$installation_path = Convert-Path "${{ inputs.installation-path }}"
$jython_path = Convert-Path "$installation_path\jython.jar"
if ("${{ steps.find_installer.outputs.file_type }}" -eq "class") {
$jython_cmd = "java -cp $jython_path org.python.util.jython %*"
$jython_pws = "java -cp $jython_path org.python.util.jython @args"
} else {
$jython_cmd = "java -jar $jython_path %*"
$jython_pws = "java -jar $jython_path @args"
}
Write-Output $jython_cmd | Out-File -FilePath ~\.local\bin\jython.bat -Append
Write-Output "#!/usr/bin/env pwsh" | Out-File -FilePath ~\.local\bin\jython.ps1
Write-Output $jython_pws | Out-File -FilePath ~\.local\bin\jython.ps1 -Append
- name: Add to PATH (Linux and macOS)
if: runner.os != 'Windows'
shell: bash
run: echo ~/.local/bin >> $GITHUB_PATH
- name: Add to PATH (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
"$HOME\.local\bin" | Out-File -FilePath $env:GITHUB_PATH -Append