-
Notifications
You must be signed in to change notification settings - Fork 10
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
5 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
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,21 @@ | ||
|
||
name: Release new version | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
publish-ghpkg: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/create-release@v1 | ||
id: create_release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
draft: false | ||
prerelease: false |
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 |
---|---|---|
@@ -1,2 +1,32 @@ | ||
# upload-to-oss | ||
Upload assets to OSS | ||
|
||
# Upload to OSS | ||
|
||
上传单个文件或文件夹下所有文件(不含子文件夹)到 OSS | ||
|
||
## Inputs | ||
|
||
- `key-id`: OSS AccessKeyId | ||
- `key-secret`: OSS AccessKeySecret | ||
- `region`: 区域,如 `oss-cn-shenzhen` | ||
- `bucket`: | ||
- `asset-path`: 本地资源路径 | ||
- `target-path`: OSS 对象存储路径 | ||
|
||
## Outputs | ||
|
||
- `url`: 文件在 OSS 上的 url。上传多个文件时,多个 url 用逗号隔开。 | ||
|
||
## Usage | ||
|
||
```yaml | ||
- name: Upload to oss | ||
id: upload_to_oss | ||
uses: actions/[email protected] | ||
with: | ||
key-id: ${{ secrets.OSS_KEY_ID }} | ||
key-secret: ${{ secrets.OSS_KEY_SECRET }} | ||
region: oss-cn-shenzhen | ||
bucket: tvrcgo | ||
asset-path: ./ | ||
target-path: /github-actions/pika-boilerplate/ | ||
``` |
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,25 @@ | ||
|
||
name: 'Upload to OSS' | ||
description: 'Upload assets to aliyun OSS' | ||
branding: | ||
icon: 'upload-cloud' | ||
color: 'yellow' | ||
inputs: | ||
region: | ||
required: true | ||
key-id: | ||
required: true | ||
key-secret: | ||
required: true | ||
bucket: | ||
required: true | ||
asset-path: | ||
required: true | ||
target-path: | ||
required: true | ||
outputs: | ||
url: | ||
description: oss url | ||
runs: | ||
using: 'node12' | ||
main: 'index.js' |
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,45 @@ | ||
|
||
const core = require('@actions/core'); | ||
const github = require('@actions/github'); | ||
const OSS = require('ali-oss'); | ||
const fs = require('fs'); | ||
const { resolve } = require('path'); | ||
|
||
(async () => { | ||
try { | ||
const oss = new OSS({ | ||
region: core.getInput('region'), | ||
accessKeyId: core.getInput('key-id'), | ||
accessKeySecret: core.getInput('key-secret'), | ||
bucket: core.getInput('bucket') | ||
}) | ||
|
||
const assetPath = core.getInput('asset-path', { required: true }).replace(/\/+$/g, '') | ||
const targetPath = core.getInput('target-path', { required: true }).replace(/\/+$/g, '') | ||
|
||
if (fs.existsSync(assetPath)) { | ||
const stat = fs.lstatSync(assetPath) | ||
// upload file | ||
if (stat.isFile()) { | ||
const filename = assetPath.slice(assetPath.lastIndexOf('/') + 1) | ||
const res = await oss.put(targetPath, assetPath) | ||
core.setOutput('url', res.url) | ||
} | ||
// upload dir | ||
if (stat.isDirectory()) { | ||
const files = fs.readdirSync(resolve(assetPath)) | ||
const res = await Promise.all( | ||
files.filter(f => fs.lstatSync(resolve(assetPath, f)).isFile()) | ||
.map(file => { | ||
return oss.put(`${targetPath}/${file}`, resolve(assetPath, file)) | ||
}) | ||
) | ||
core.setOutput('url', res.map(r => r.url).join(',')) | ||
} | ||
} else { | ||
core.setFailed('asset_path does not exist.') | ||
} | ||
} catch (err) { | ||
core.setFailed(err.message) | ||
} | ||
})() |
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,15 @@ | ||
{ | ||
"name": "upload-to-oss", | ||
"version": "0.1.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"keywords": [], | ||
"author": "tvrcgo", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@actions/core": "^1.2.3", | ||
"@actions/github": "^2.1.1", | ||
"ali-oss": "^6.6.0" | ||
} | ||
} |