generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
28,693 additions
and
19,750 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import axios from 'axios' | ||
import https from 'https' | ||
|
||
// At request level | ||
const agent = new https.Agent({ | ||
rejectUnauthorized: false | ||
}) | ||
|
||
export function uploadByPublicKey(form: FormData) { | ||
return axios.post(process.env['OASISBE_UPLOAD_URL'], form, { | ||
httpsAgent: agent, | ||
headers: JSON.parse(process.env['OASISBE_REQUEST_HEADER']) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import path from 'path' | ||
import { fileFromPath } from 'formdata-node/file-from-path' | ||
import { uploadByPublicKey } from './request' | ||
import crypto from 'crypto' | ||
import fs from 'fs' | ||
import * as core from '@actions/core' | ||
|
||
const publicKey = process.env['OASISBE_PUBLIC_KEY'] | ||
|
||
export async function uploadPackageJS(dirPath: string) { | ||
const distPath = path.join(dirPath, 'dist') | ||
if (!fs.existsSync(distPath)) { | ||
return | ||
} | ||
const pkg = JSON.parse( | ||
fs.readFileSync(path.join(dirPath, 'package.json'), { | ||
encoding: 'utf-8' | ||
}) | ||
) | ||
const version = pkg.version | ||
const files = fs.readdirSync(distPath) | ||
core.debug(`upload package: ${pkg.name}`) | ||
for (let i = 0; i < files.length; i++) { | ||
const filename = files[i] | ||
const filepath = path.join(distPath, filename) | ||
|
||
const res = await upload({ | ||
filename, | ||
filepath, | ||
alias: `${pkg.name}/${version}/${filename}` | ||
}) | ||
core.info(`uploaded: ${res.data}`) | ||
} | ||
} | ||
|
||
export async function upload({ | ||
filename, | ||
alias, | ||
filepath | ||
}: { | ||
filename: string | ||
alias: string | ||
filepath: string | ||
}) { | ||
const form = new FormData() | ||
const message = 'upload' | ||
const signature = crypto.publicEncrypt(publicKey, Buffer.from(message)) | ||
const file = await fileFromPath(filepath, 'index.txt') | ||
form.append('signature', signature.toString('base64')) | ||
form.append('filename', filename) | ||
form.append('alias', alias) | ||
form.append('file', file) | ||
|
||
const result = await uploadByPublicKey(form) | ||
return result.data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { uploadPackageJS, upload } = require('./dist/index') | ||
const path = require('path') | ||
|
||
uploadPackageJS(process.cwd()) | ||
.then(res => console.log(res)) | ||
.catch(err => console.log(err)) | ||
|
||
// upload({ | ||
// filename: 'index.js', | ||
// alias: '1.2.10/192.js', | ||
// filepath: path.join(process.cwd(), 'dist','index.js') | ||
// }) |