Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/resources/asdf/asdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ export class AsdfResource extends Resource<AsdfConfig> {
await CoreUtils.installViaPkgMgr('curl');
}

const { data: latestVersion } = await $.spawn('curl -s https://api.github.com/repos/asdf-vm/asdf/releases/latest | grep \'"tag_name":\' | sed -E \'s/.*"([^"]+)".*/\\1/\'');
// Extract latest version from GitHub's /releases/latest redirect — avoids API rate limits
const { data: locationData } = await $.spawn(
"curl -sI https://github.com/asdf-vm/asdf/releases/latest | grep -i 'location:' | sed 's|.*/tag/||' | tr -d '\\r\\n'"
);
const latestVersion = locationData.trim();
if (!latestVersion) {
throw new Error('Failed to determine the latest asdf version from GitHub. Check network connectivity.');
}

// Create .asdf directory if it doesn't exist
const asdfDir = path.join(os.homedir(), '.local', 'bin');
Expand Down
6 changes: 4 additions & 2 deletions test/asdf/asdf-install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ describe('Asdf install tests', async () => {
validateDestroy: async () => {
expect(await testSpawn('which asdf')).toMatchObject({ status: SpawnStatus.ERROR });
expect(await testSpawn('which deno')).toMatchObject({ status: SpawnStatus.ERROR });
expect(await testSpawn('which go')).toMatchObject({ status: SpawnStatus.ERROR });
// Check the asdf shim is gone rather than `which go` — system Go may be pre-installed on the runner
expect(await testSpawn('test -f ~/.asdf/shims/go')).toMatchObject({ status: SpawnStatus.ERROR });
}
});

Expand All @@ -59,7 +60,8 @@ describe('Asdf install tests', async () => {
},
validateDestroy: async () => {
expect(await testSpawn('which asdf')).toMatchObject({ status: SpawnStatus.ERROR });
expect(await testSpawn('which go')).toMatchObject({ status: SpawnStatus.ERROR });
// Check the asdf shim is gone rather than `which go` — system Go may be pre-installed on the runner
expect(await testSpawn('test -f ~/.asdf/shims/go')).toMatchObject({ status: SpawnStatus.ERROR });
}
});
})
Expand Down