Skip to content

Commit cf36221

Browse files
committed
Download url for leiningen
1 parent e6e77cd commit cf36221

File tree

6 files changed

+334
-43
lines changed

6 files changed

+334
-43
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
name: Test Leiningen JAR Download
2+
3+
# This workflow tests the fix for issue #128
4+
# https://github.com/DeLaGuardo/setup-clojure/issues/128
5+
#
6+
# Leiningen is moving from GitHub to Codeberg. This workflow verifies that
7+
# setup-clojure downloads the JAR directly from GitHub Releases instead of
8+
# relying on `lein self-install` (which would download from Codeberg for
9+
# newer versions).
10+
11+
permissions:
12+
contents: read
13+
14+
on:
15+
push:
16+
paths:
17+
- "src/leiningen.ts"
18+
- ".github/workflows/test-leiningen-jar-download.yml"
19+
pull_request:
20+
paths:
21+
- "src/leiningen.ts"
22+
- ".github/workflows/test-leiningen-jar-download.yml"
23+
workflow_dispatch:
24+
25+
jobs:
26+
test-leiningen-specific-version:
27+
strategy:
28+
matrix:
29+
os: [ubuntu-latest, macOS-latest]
30+
version: ["2.9.1", "2.10.0", "2.11.2", "2.12.0"]
31+
32+
runs-on: ${{ matrix.os }}
33+
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
38+
- name: Prepare java
39+
uses: actions/setup-java@v4
40+
with:
41+
distribution: "zulu"
42+
java-version: "11"
43+
44+
- name: Install Leiningen ${{ matrix.version }}
45+
uses: ./
46+
with:
47+
lein: ${{ matrix.version }}
48+
github-token: ${{ secrets.GITHUB_TOKEN }}
49+
50+
- name: Verify lein version
51+
run: |
52+
echo "Expected version: ${{ matrix.version }}"
53+
lein version
54+
# Verify the version matches (lein version outputs: Leiningen X.Y.Z on Java ...)
55+
lein version 2>&1 | grep -q "Leiningen ${{ matrix.version }}"
56+
57+
- name: Verify LEIN_JAR is set
58+
run: |
59+
echo "LEIN_JAR=$LEIN_JAR"
60+
test -n "$LEIN_JAR" || (echo "LEIN_JAR not set" && exit 1)
61+
test -f "$LEIN_JAR" || (echo "LEIN_JAR file does not exist" && exit 1)
62+
63+
- name: Verify JAR is in self-installs directory
64+
run: |
65+
echo "LEIN_HOME=$LEIN_HOME"
66+
ls -la "$LEIN_HOME/self-installs/"
67+
test -f "$LEIN_HOME/self-installs/leiningen-${{ matrix.version }}-standalone.jar"
68+
69+
test-leiningen-latest:
70+
strategy:
71+
matrix:
72+
os: [ubuntu-latest, macOS-latest]
73+
74+
runs-on: ${{ matrix.os }}
75+
76+
steps:
77+
- name: Checkout
78+
uses: actions/checkout@v4
79+
80+
- name: Prepare java
81+
uses: actions/setup-java@v4
82+
with:
83+
distribution: "zulu"
84+
java-version: "11"
85+
86+
- name: Install Leiningen latest
87+
uses: ./
88+
with:
89+
lein: latest
90+
github-token: ${{ secrets.GITHUB_TOKEN }}
91+
92+
- name: Verify lein works
93+
run: lein version
94+
95+
- name: Verify LEIN_JAR is set
96+
run: |
97+
echo "LEIN_JAR=$LEIN_JAR"
98+
test -n "$LEIN_JAR" || (echo "LEIN_JAR not set" && exit 1)
99+
test -f "$LEIN_JAR" || (echo "LEIN_JAR file does not exist" && exit 1)
100+
101+
- name: Verify JAR is in self-installs directory
102+
run: |
103+
echo "LEIN_HOME=$LEIN_HOME"
104+
ls -la "$LEIN_HOME/self-installs/"
105+
# Should have exactly one JAR file
106+
test $(ls "$LEIN_HOME/self-installs/"*.jar | wc -l) -eq 1
107+
108+
test-leiningen-windows:
109+
strategy:
110+
matrix:
111+
version: ["2.11.2", "2.12.0"]
112+
113+
runs-on: windows-latest
114+
115+
steps:
116+
- name: Checkout
117+
uses: actions/checkout@v4
118+
119+
- name: Prepare java
120+
uses: actions/setup-java@v4
121+
with:
122+
distribution: "zulu"
123+
java-version: "11"
124+
125+
- name: Install Leiningen ${{ matrix.version }}
126+
uses: ./
127+
with:
128+
lein: ${{ matrix.version }}
129+
github-token: ${{ secrets.GITHUB_TOKEN }}
130+
131+
- name: Verify lein version (PowerShell)
132+
shell: powershell
133+
run: |
134+
lein version
135+
if (-not $env:LEIN_JAR) { throw "LEIN_JAR not set" }
136+
if (-not (Test-Path $env:LEIN_JAR)) { throw "LEIN_JAR file does not exist" }
137+
138+
- name: Verify lein version (cmd)
139+
shell: cmd
140+
run: lein version
141+
142+
- name: Verify JAR location (PowerShell)
143+
shell: powershell
144+
run: |
145+
Write-Host "LEIN_HOME=$env:LEIN_HOME"
146+
Get-ChildItem "$env:LEIN_HOME\self-installs"
147+
148+
test-leiningen-caching:
149+
runs-on: ubuntu-latest
150+
151+
steps:
152+
- name: Checkout
153+
uses: actions/checkout@v4
154+
155+
- name: Prepare java
156+
uses: actions/setup-java@v4
157+
with:
158+
distribution: "zulu"
159+
java-version: "11"
160+
161+
- name: Install Leiningen (first run - should download)
162+
uses: ./
163+
with:
164+
lein: "2.11.2"
165+
github-token: ${{ secrets.GITHUB_TOKEN }}
166+
167+
- name: Verify first installation
168+
run: lein version
169+
170+
- name: Install Leiningen (second run - should use cache)
171+
uses: ./
172+
with:
173+
lein: "2.11.2"
174+
github-token: ${{ secrets.GITHUB_TOKEN }}
175+
176+
- name: Verify cached installation
177+
run: lein version
178+
179+
test-leiningen-create-project:
180+
strategy:
181+
matrix:
182+
os: [ubuntu-latest, macOS-latest]
183+
184+
runs-on: ${{ matrix.os }}
185+
186+
steps:
187+
- name: Checkout
188+
uses: actions/checkout@v4
189+
190+
- name: Prepare java
191+
uses: actions/setup-java@v4
192+
with:
193+
distribution: "zulu"
194+
java-version: "11"
195+
196+
- name: Install Leiningen
197+
uses: ./
198+
with:
199+
lein: "2.12.0"
200+
github-token: ${{ secrets.GITHUB_TOKEN }}
201+
202+
- name: Create and test a new project
203+
run: |
204+
cd /tmp
205+
lein new app test-project
206+
cd test-project
207+
# Skip 'lein test' as default app template includes a failing test (FIXME)
208+
lein run

__tests__/leiningen.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {VERSION} from '../src/version'
1010
const toolPath = join(__dirname, 'runner', 'tools', 'leiningen')
1111
const tempPath = join(__dirname, 'runner', 'temp', 'leiningen')
1212
const downloadPath = join(__dirname, 'runner', 'download')
13+
const jarDownloadPath = join(__dirname, 'runner', 'download', 'leiningen.jar')
1314
const cachePath = join(__dirname, 'runner', 'cache')
1415

1516
import * as leiningen from '../src/leiningen'
@@ -55,12 +56,21 @@ describe('leiningen tests', () => {
5556
})
5657

5758
it('Install leiningen with normal version', async () => {
59+
// First call downloads lein script, second downloads the JAR
5860
tc.downloadTool.mockResolvedValueOnce(downloadPath)
61+
tc.downloadTool.mockResolvedValueOnce(jarDownloadPath)
5962
fs.stat.mockResolvedValueOnce({isFile: () => true} as never)
6063
tc.cacheDir.mockResolvedValueOnce(cachePath)
6164

6265
await leiningen.setup('2.9.1')
6366

67+
// Verify JAR was downloaded from GitHub releases
68+
expect(tc.downloadTool).toHaveBeenCalledWith(
69+
'https://github.com/technomancy/leiningen/releases/download/2.9.1/leiningen-2.9.1-standalone.jar',
70+
expect.any(String),
71+
undefined
72+
)
73+
6474
expect(io.mkdirP).toHaveBeenNthCalledWith(
6575
1,
6676
join(tempPath, 'temp_2000000000')
@@ -69,6 +79,22 @@ describe('leiningen tests', () => {
6979
2,
7080
join(tempPath, 'temp_2000000000', 'leiningen', 'bin')
7181
)
82+
// Verify self-installs directory was created
83+
expect(io.mkdirP).toHaveBeenNthCalledWith(
84+
3,
85+
join(tempPath, 'temp_2000000000', 'leiningen', 'self-installs')
86+
)
87+
// Verify JAR was moved to self-installs
88+
expect(io.mv).toHaveBeenCalledWith(
89+
jarDownloadPath,
90+
join(
91+
tempPath,
92+
'temp_2000000000',
93+
'leiningen',
94+
'self-installs',
95+
'leiningen-2.9.1-standalone.jar'
96+
)
97+
)
7298
expect(exec.exec.mock.calls[0]).toMatchObject([
7399
'./lein version',
74100
[],
@@ -92,12 +118,33 @@ describe('leiningen tests', () => {
92118
})
93119

94120
it('Install latest leiningen', async () => {
121+
// Mock fetch for getting latest version
122+
global.fetch = jest.fn().mockResolvedValue({
123+
ok: true,
124+
json: jest.fn().mockResolvedValue({tag_name: '2.12.0'})
125+
})
126+
127+
// First call downloads lein script, second downloads the JAR
95128
tc.downloadTool.mockResolvedValueOnce(downloadPath)
129+
tc.downloadTool.mockResolvedValueOnce(jarDownloadPath)
96130
fs.stat.mockResolvedValueOnce({isFile: () => true} as never)
97131
tc.cacheDir.mockResolvedValueOnce(cachePath)
98132

99133
await leiningen.setup('latest')
100134

135+
// Verify latest version was fetched
136+
expect(global.fetch).toHaveBeenCalledWith(
137+
'https://api.github.com/repos/technomancy/leiningen/releases/latest',
138+
expect.any(Object)
139+
)
140+
141+
// Verify JAR was downloaded with resolved version
142+
expect(tc.downloadTool).toHaveBeenCalledWith(
143+
'https://github.com/technomancy/leiningen/releases/download/2.12.0/leiningen-2.12.0-standalone.jar',
144+
expect.any(String),
145+
undefined
146+
)
147+
101148
expect(io.mkdirP).toHaveBeenNthCalledWith(
102149
1,
103150
join(tempPath, 'temp_2000000000')

dist/index.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,13 +1123,16 @@ const os = __importStar(__nccwpck_require__(857));
11231123
const fs = __importStar(__nccwpck_require__(2621));
11241124
const utils = __importStar(__nccwpck_require__(9277));
11251125
exports.identifier = 'Leiningen';
1126+
const LEIN_JAR_BASE_URL = 'https://github.com/technomancy/leiningen/releases/download';
11261127
function setup(version, githubAuth) {
11271128
return __awaiter(this, void 0, void 0, function* () {
11281129
let toolPath = tc.find(exports.identifier, utils.getCacheVersionString(version), os.arch());
11291130
if (toolPath && version !== 'latest') {
11301131
core.info(`Leiningen found in cache ${toolPath}`);
11311132
}
11321133
else {
1134+
// Resolve 'latest' to actual version number
1135+
const resolvedVersion = version === 'latest' ? yield getLatestVersion(githubAuth) : version;
11331136
const binScripts = [];
11341137
if (utils.isWindows()) {
11351138
for (const ext of ['ps1', 'bat']) {
@@ -1139,8 +1142,12 @@ function setup(version, githubAuth) {
11391142
else {
11401143
binScripts.push(yield tc.downloadTool(`https://raw.githubusercontent.com/technomancy/leiningen/${version === 'latest' ? 'stable' : version}/bin/lein`, path.join(utils.getTempDir(), 'lein'), githubAuth));
11411144
}
1145+
const jarFileName = `leiningen-${resolvedVersion}-standalone.jar`;
1146+
const jarUrl = `${LEIN_JAR_BASE_URL}/${resolvedVersion}/${jarFileName}`;
1147+
core.info(`Downloading Leiningen JAR from ${jarUrl}`);
1148+
const jarPath = yield tc.downloadTool(jarUrl, path.join(utils.getTempDir(), jarFileName), githubAuth);
11421149
const tempDir = path.join(utils.getTempDir(), `temp_${Math.floor(Math.random() * 2000000000)}`);
1143-
const leiningenDir = yield installLeiningen(binScripts, tempDir);
1150+
const leiningenDir = yield installLeiningen(binScripts, jarPath, resolvedVersion, tempDir);
11441151
core.debug(`Leiningen installed to ${leiningenDir}`);
11451152
toolPath = yield tc.cacheDir(leiningenDir, exports.identifier, utils.getCacheVersionString(version));
11461153
}
@@ -1152,14 +1159,27 @@ function setup(version, githubAuth) {
11521159
core.addPath(path.join(toolPath, 'bin'));
11531160
});
11541161
}
1155-
function installLeiningen(binScripts, destinationFolder) {
1162+
function getLatestVersion(githubAuth) {
1163+
return __awaiter(this, void 0, void 0, function* () {
1164+
const response = yield fetch('https://api.github.com/repos/technomancy/leiningen/releases/latest', {
1165+
headers: githubAuth ? { Authorization: githubAuth } : {}
1166+
});
1167+
if (!response.ok) {
1168+
throw new Error(`Failed to fetch latest Leiningen version: ${response.statusText}`);
1169+
}
1170+
const data = (yield response.json());
1171+
return data.tag_name;
1172+
});
1173+
}
1174+
function installLeiningen(binScripts, jarPath, version, destinationFolder) {
11561175
return __awaiter(this, void 0, void 0, function* () {
11571176
yield io.mkdirP(destinationFolder);
1177+
const toolDir = path.join(destinationFolder, 'leiningen');
11581178
for (const binScript of binScripts) {
11591179
const bin = path.normalize(binScript);
11601180
const binStats = yield fs.stat(bin);
11611181
if (binStats.isFile()) {
1162-
const binDir = path.join(destinationFolder, 'leiningen', 'bin');
1182+
const binDir = path.join(toolDir, 'bin');
11631183
yield io.mkdirP(binDir);
11641184
yield io.mv(bin, path.join(binDir, `${path.basename(bin)}`));
11651185
if (!utils.isWindows()) {
@@ -1170,10 +1190,13 @@ function installLeiningen(binScripts, destinationFolder) {
11701190
throw new Error('Not a file');
11711191
}
11721192
}
1193+
const selfInstallsDir = path.join(toolDir, 'self-installs');
1194+
yield io.mkdirP(selfInstallsDir);
1195+
const jarFileName = `leiningen-${version}-standalone.jar`;
1196+
yield io.mv(jarPath, path.join(selfInstallsDir, jarFileName));
11731197
const version_cmd = utils.isWindows()
1174-
? 'powershell .\\lein.ps1 self-install'
1198+
? 'powershell .\\lein.ps1 version'
11751199
: './lein version';
1176-
const toolDir = path.join(destinationFolder, 'leiningen');
11771200
const env = {
11781201
LEIN_HOME: toolDir
11791202
};

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)