Skip to content

Commit

Permalink
Merge pull request #193 from cargo-prebuilt/fetch
Browse files Browse the repository at this point in the history
Use fetch instead of http-client
  • Loading branch information
harmless-tech authored Feb 24, 2024
2 parents 763c46f + 9e59c72 commit 6bec37d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 57 deletions.
45 changes: 9 additions & 36 deletions dist/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/index.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"@actions/http-client": "^2.2.0",
"@actions/tool-cache": "^2.0.1"
},
"devDependencies": {
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

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

18 changes: 6 additions & 12 deletions src/minisign.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as tc from '@actions/tool-cache'
import * as httpm from '@actions/http-client'
import {arch, platform} from 'node:process'
import {hashFile} from './sha256'
import {DL_URL} from './vals'
import {DL_URL, PREBUILT_INDEX_PUB_KEY, RSIGN_DL_URL} from './vals'
import path from 'node:path'
import {writeFileSync} from 'node:fs'

const DL =
'https://github.com/cargo-prebuilt/index/releases/download/rsign2-0.6.3/'
const PUB_KEY = 'RWTSqAR1Hbfu6mBFiaz4hb9I9gikhMmvKkVbyz4SJF/oxJcbbScmCqqO'

export async function verifyFileMinisign(
version: string,
fileName: string,
Expand All @@ -20,19 +15,18 @@ export async function verifyFileMinisign(
return new Promise(async resolve => {
const rsign2 = await installRsign2()

const archivePath = path.dirname(filePath)
const client = new httpm.HttpClient('minisign downloader')
const res = await client.get(`${DL_URL}${version}/${fileName}.minisig`)
const minisignFile = await res.readBody()
const res = await fetch(`${DL_URL}${version}/${fileName}.minisig`)
const minisignFile = (await res.text()).trim()

const archivePath = path.dirname(filePath)
const minisignFilePath = `${archivePath}/${fileName}.minisig`
writeFileSync(minisignFilePath, minisignFile)

await exec.exec(rsign2, [
'verify',
`${filePath}`,
'-P',
`${PUB_KEY}`,
`${PREBUILT_INDEX_PUB_KEY}`,
'-x',
`${minisignFilePath}`
])
Expand Down Expand Up @@ -99,7 +93,7 @@ async function installRsign2(): Promise<string> {

if (!dlFile) throw new Error('unsupported or missing platform')

const toolPath = await tc.downloadTool(`${DL}${dlFile}.tar.gz`)
const toolPath = await tc.downloadTool(`${RSIGN_DL_URL}${dlFile}.tar.gz`)
const hash = await hashFile(toolPath)

if (hash !== dlHash)
Expand Down
6 changes: 2 additions & 4 deletions src/sha256.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as httpm from '@actions/http-client'
import {readFileSync} from 'node:fs'
import {createHash} from 'node:crypto'
import {DL_URL} from './vals'
Expand All @@ -8,9 +7,8 @@ export async function verifyFileHash(
filePath: string
): Promise<void> {
return new Promise(async resolve => {
const client = new httpm.HttpClient('sha256 downloader')
const res = await client.get(`${DL_URL}${version}/hashes.sha256`)
const sha256File = await res.readBody()
const res = await fetch(`${DL_URL}${version}/hashes.sha256`)
const sha256File = (await res.text()).trim()

const fileHash = await hashFile(filePath)

Expand Down
4 changes: 4 additions & 0 deletions src/vals.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
export const DL_URL =
'https://github.com/cargo-prebuilt/cargo-prebuilt/releases/download/v'
export const RSIGN_DL_URL =
'https://github.com/cargo-prebuilt/index/releases/download/rsign2-0.6.3/'
export const PREBUILT_INDEX_PUB_KEY =
'RWTSqAR1Hbfu6mBFiaz4hb9I9gikhMmvKkVbyz4SJF/oxJcbbScmCqqO'

0 comments on commit 6bec37d

Please sign in to comment.