@@ -5,20 +5,21 @@ import * as io from '@actions/io'
55import * as octokit from '@octokit/rest'
66import * as path from 'path'
77import fetch from 'node-fetch'
8- import { OWNER , REPO } from './utils'
8+ import { OWNER , REPO , validateCheckSum } from './utils'
99
1010async function run ( ) : Promise < void > {
1111 const platform = 'linux'
1212 const arch = 'x64'
1313 const versionInput = core . getInput ( 'version' )
14+ const checkSum = core . getInput ( 'checksum' )
1415
1516 try {
1617 const version = await resolveVersion ( versionInput )
1718 let cachedPath = tryGetFromCache ( arch , version )
1819 if ( cachedPath ) {
1920 core . info ( `Found Rye in cache for ${ version } ` )
2021 } else {
21- cachedPath = await setupRye ( platform , arch , version )
22+ cachedPath = await setupRye ( platform , arch , version , checkSum )
2223 }
2324 addRyeToPath ( cachedPath )
2425 addMatchers ( )
@@ -65,24 +66,34 @@ function tryGetFromCache(arch: string, version: string): string | undefined {
6566async function setupRye (
6667 platform : string ,
6768 arch : string ,
68- version : string
69+ version : string ,
70+ checkSum : string | undefined
6971) : Promise < string > {
70- const downloadPath = await downloadVersion ( platform , arch , version )
72+ const downloadPath = await downloadVersion ( platform , arch , version , checkSum )
7173 const cachedPath = await installRye ( downloadPath , arch , version )
7274 return cachedPath
7375}
7476
7577async function downloadVersion (
7678 platform : string ,
7779 arch : string ,
78- version : string
80+ version : string ,
81+ checkSum : string | undefined
7982) : Promise < string > {
8083 const binary = `rye-x86_64-${ platform } `
8184 const downloadUrl = `https://github.com/mitsuhiko/rye/releases/download/${ version } /${ binary } .gz`
8285 core . info ( `Downloading Rye from "${ downloadUrl } " ...` )
8386
8487 try {
8588 const downloadPath = await tc . downloadTool ( downloadUrl )
89+ if ( checkSum !== undefined && checkSum !== '' ) {
90+ const isValid = await validateCheckSum ( downloadPath , checkSum )
91+ if ( ! isValid ) {
92+ throw new Error (
93+ `Checksum for ${ downloadPath } did not match ${ checkSum } .`
94+ )
95+ }
96+ }
8697
8798 await extract ( downloadPath )
8899 return downloadPath
0 commit comments