Skip to content

Commit

Permalink
check known checksums
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Sep 18, 2023
1 parent af1dec7 commit e20a558
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, oracle-aarch64]
rye-version: ['0.11.0', '0.12.0']
rye-version: ['0.11.0', '0.12.0', '0.13.0']
steps:
- uses: actions/checkout@v4
- name: Install specific version
Expand Down
18 changes: 17 additions & 1 deletion dist/save-cache/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/save-cache/index.js.map

Large diffs are not rendered by default.

37 changes: 33 additions & 4 deletions dist/setup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/setup/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "setup-rye",
"version": "1.1.0",
"version": "1.2.0",
"private": true,
"description": "TypeScript template action",
"main": "dist/index.js",
Expand Down
29 changes: 23 additions & 6 deletions src/setup-rye.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import * as octokit from '@octokit/rest'
import * as path from 'path'
import fetch from 'node-fetch'
import {restoreCache} from './restore-cache'
import {Architecture, OWNER, REPO, validateCheckSum, getArch} from './utils'
import {
Architecture,
OWNER,
REPO,
KNOWN_CHECKSUMS,
validateCheckSum,
getArch
} from './utils'

async function run(): Promise<void> {
const platform = 'linux'
Expand Down Expand Up @@ -102,15 +109,25 @@ async function downloadVersion(

try {
const downloadPath = await tc.downloadTool(downloadUrl)
let isValid = true
if (checkSum !== undefined && checkSum !== '') {
const isValid = await validateCheckSum(downloadPath, checkSum)
if (!isValid) {
throw new Error(
`Checksum for ${downloadPath} did not match ${checkSum}.`
)
isValid = await validateCheckSum(downloadPath, checkSum)
} else {
core.debug(`Checksum not provided. Checking known checksums.`)
const key = `${arch}-${platform}-${version}`
if (key in KNOWN_CHECKSUMS) {
const knownChecksum = KNOWN_CHECKSUMS[`${arch}-${platform}-${version}`]
isValid = await validateCheckSum(downloadPath, knownChecksum)
} else {
core.debug(`No known checksum found for ${key}.`)
}
}

if (!isValid) {
throw new Error(`Checksum for ${downloadPath} did not match ${checkSum}.`)
}
core.debug(`Checksum for ${downloadPath} is valid.`)

await extract(downloadPath)
return downloadPath
} catch (err) {
Expand Down
33 changes: 33 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,39 @@ export const WINDOWS_PLATFORMS = ['win32', 'win64']
export const REPO = 'rye'
export const OWNER = 'mitsuhiko'

export const KNOWN_CHECKSUMS: {[key: string]: string} = {
'aarch64-linux-0.13.0':
'f09e4f0cc9114a1bc8b5f39f45fe7f20bb2c1b1a416afe4fdba02c5295f0d7df',
'aarch64-macos-0.13.0':
'e082822e44dceee8a535690cca76643c1428c41bc492cbe7160a873a66c4a3e5',
'x86-windows-0.13.0':
'f89ade3e9362741b02c245436e49908518c1f92677e33f366b47cdb000942a4e',
'x86_64-linux-0.13.0':
'07daa41c993594c3aeed4eff59974d01d10949f6a51bcdd1f8ada2866d87f795',
'x86_64-macos-0.13.0':
'921335016f8e74cad9918d67ec4f721c360bfff9ccb76c77959e1b295f4c9c8b',
'x86_64-windows-0.13.0':
'749a8caa46e834527af4527825e0d829dfe758486963e038f27b3c00c5a75641',

'aarch64-linux-0.12.0':
'dfc209bb35213b82b7dbe0784a60184fe3263e204a90da9f1bf672aacbbbdce1',
'aarch64-macos-0.12.0':
'01cd35aed836c4dc10841c3a622b3398354a0b124df1a59eefe60bd0296533cd',
'x86-windows-0.12.0':
'be48999d3c073405765f19064dd273e54ae529e81f31f81b3faa689a70974149',
'x86_64-linux-0.12.0':
'c48d850e90649d868d512f60af67c74aa844d80f951fdb38589220662e709da7',
'x86_64-macos-0.12.0':
'2b36b6d17218983a4c6f53c09ae45f1088525d289c8b5b6703b9081f771ad653',
'x86_64-windows-0.12.0':
'3dfae62b3f42ff89cbbe3c61582a871db034fb8a8c504b107a4e3613f9d18be4',

'x86_64-linux-0.11.0':
'00e795573477a2fe2b3c0ac748240364c3369218d314d1df47d2653764e9bfb1',
'aarch64-linux-0.11.0':
'7e0b1f6e3490a79c1d2600e8c04dd9ed4ea04d29d6c80f1f5a84a79736e9a21d'
}

export type Architecture = 'x86' | 'x86_64' | 'aarch64'

export async function validateCheckSum(
Expand Down

0 comments on commit e20a558

Please sign in to comment.