Skip to content

Commit f687822

Browse files
feat: Add caching for Jython binaries (#19)
* feat: Add Jython cache * feat: Add `cache-hit` output * ci(lint): Add PR title linting
1 parent 3a77c8b commit f687822

4 files changed

Lines changed: 94 additions & 6 deletions

File tree

.github/workflows/lint-pr.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: "Lint Pull Requests"
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
permissions:
11+
pull-requests: write
12+
13+
jobs:
14+
main:
15+
name: Validate PR title
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: amannn/action-semantic-pull-request@v5
19+
id: lint_pr_title
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
23+
- uses: marocchino/sticky-pull-request-comment@v2
24+
# When the previous steps fails, the workflow would stop. By adding this
25+
# condition you can continue the execution with the populated error message.
26+
if: always() && (steps.lint_pr_title.outputs.error_message != null)
27+
with:
28+
header: pr-title-lint-error
29+
message: |
30+
Hey there and thank you for opening this pull request! 👋🏼
31+
32+
We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted.
33+
34+
Details:
35+
36+
```
37+
${{ steps.lint_pr_title.outputs.error_message }}
38+
```
39+
40+
# Delete a previous comment when the issue has been resolved
41+
- if: ${{ steps.lint_pr_title.outputs.error_message == null }}
42+
uses: marocchino/sticky-pull-request-comment@v2
43+
with:
44+
header: pr-title-lint-error
45+
delete: true

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Add installer and jython binaries caching
13+
- Add `cache-hit` output value, which is set to `true` if the Jython data/binaries are retrieved from cache.
14+
15+
## [v5] - 2024-05-16
16+
17+
### Added
18+
1219
- Now it is possible to use Jython 2.0 and 2.1 on `ubuntu` and `macos` runners!
1320
- Added support for Powershell on all runners (previously only on `windows` runners)
1421
- Added support for Windows Command Prompt (`cmd`) on windows runners. Notice that because of how the `cmd` handles single quotes it only works if no single quotes are used to enclose parameters: `jython.bat -c "print 'Hello world'"` will work, while `jython.bat -c 'print "Hello world"'` will not.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ Specify the path where Jython will be installed. Please note that this is usuall
6868
</tbody>
6969
</table>
7070

71+
## Outputs
72+
73+
### `download-url`
74+
75+
The URL from which the Jython installer was downloaded.
76+
77+
### `cache-hit`
78+
79+
Boolean value that indicates whether a cache hit occurred on the primary key.
80+
7181
## Supported versions
7282

7383
This action supports all versions (_both stable and development releases_) currently listed on the official repositories:

action.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ outputs:
2020
download-url:
2121
description: "The URL from which the installer is downloaded"
2222
value: ${{ steps.find_installer.outputs.url }}
23+
cache-hit:
24+
description: "Whether the Jython binaries were restored from the cache"
25+
value: ${{ steps.cache-jython.outputs.cache-hit }}
2326

2427
runs:
2528
using: "composite"
@@ -29,9 +32,34 @@ runs:
2932
echo "Action running on ${{ runner.os }} ${{ runner.arch }} (name: '${{ runner.name }}')"
3033
shell: bash
3134

35+
# See https://github.com/actions/toolkit/issues/1035
36+
- uses: actions/github-script@v7
37+
id: resources-hash
38+
with:
39+
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')
40+
result-encoding: string
41+
42+
- name: Cache Jython binaries
43+
id: cache-jython
44+
uses: actions/cache@v4
45+
with:
46+
key: ${{ runner.os }}-${{ runner.arch }}-${{ inputs.jython-version }}-${{ steps.resources-hash.outputs.result }}
47+
restore-keys: |
48+
${{ runner.os }}-${{ runner.arch }}-${{ inputs.jython-version }}-
49+
path: |
50+
${{ inputs.installation-path }}
51+
~/.local/bin/
52+
53+
- name: Set up JDK 8
54+
uses: actions/setup-java@v4
55+
with:
56+
java-version: '8'
57+
distribution: 'zulu'
58+
3259
# Sadly, macos-latest images use Python 2.7 (dunno why)
3360
- name: Find Jython installer from resource list
3461
id: find_installer
62+
if: ${{ steps.cache-jython.outputs.cache-hit != 'true' }}
3563
shell: python
3664
run: |
3765
import sys, os
@@ -75,14 +103,9 @@ runs:
75103
]
76104
f.write('\n'.join(lines))
77105
78-
- name: Set up JDK 8
79-
uses: actions/setup-java@v4
80-
with:
81-
java-version: '8'
82-
distribution: 'zulu'
83-
84106
- name: Download Jython Installer
85107
id: download_installer
108+
if: ${{ steps.cache-jython.outputs.cache-hit != 'true' }}
86109
shell: bash
87110
run: |
88111
download_url="${{ steps.find_installer.outputs.url }}";
@@ -96,6 +119,7 @@ runs:
96119
97120
- name: Install Jython
98121
id: installation
122+
if: ${{ steps.cache-jython.outputs.cache-hit != 'true' }}
99123
shell: bash
100124
run: |
101125
case "${{ steps.find_installer.outputs.file_type }}" in
@@ -138,6 +162,7 @@ runs:
138162
# rm -f ${{ steps.download_installer.outputs.temporary_file }}
139163
140164
- name: Setup Jython alias
165+
if: ${{ steps.cache-jython.outputs.cache-hit != 'true' }}
141166
shell: bash
142167
run: |
143168
installation_path="$(sed -r 's/^\s+//; s/\s+$//; s/\/+$//;' <<< "${{ inputs.installation-path }}")"
@@ -166,6 +191,7 @@ runs:
166191
chmod +x ~/.local/bin/jython;
167192
168193
- name: Setup Jython alias (pwsh)
194+
if: ${{ steps.cache-jython.outputs.cache-hit != 'true' }}
169195
shell: pwsh
170196
run: |
171197
$installation_path = Convert-Path "${{ inputs.installation-path }}"

0 commit comments

Comments
 (0)