Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Cherrypick #874 (#953)
Browse files Browse the repository at this point in the history
* Fix action can't run on centos6 (#874)

* fix package

* fix uploading asset

* package for centos 6

* format the code

* remove redudant vars in action

Co-authored-by: Yee <[email protected]>
(cherry picked from commit 5c14e0f)

* cherrypick 847

* update

* udpate

Co-authored-by: jie.wang <[email protected]>
  • Loading branch information
jude-zhu and jievince authored Apr 14, 2021
1 parent 3d81087 commit b4f6f0a
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/actions/upload-assets-action/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Upload file to release assets

**Required** tag name of release branch. Default `${{ github.ref }}`.

### `file-path`
### `asset-path`

**Required** file path to be uploaded. Default `''`.

Expand All @@ -17,6 +17,6 @@ Upload file to release assets
```yaml
uses: ./.github/actions/upload-assets-action
with:
file-path: ${{ steps.pkg.outputs.filepath }}
asset-path: build/cpack_output
tag: ${{ steps.tag.outputs.tag }}
```
31 changes: 22 additions & 9 deletions .github/actions/upload-assets-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
description: 'git tag'
required: true
default: ${{ github.ref }}
file-path:
asset-path:
description: 'file path to be uploaded'
required: true
default: ''
Expand All @@ -15,13 +15,26 @@ runs:
- run: |
GH_RELEASE="https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ inputs.tag }}"
upload_url=$(curl -s --request GET --url $GH_RELEASE | grep -oP '(?<="upload_url": ")[^"]*' | cut -d'{' -f1)
content_type=$(file -b --mime-type ${{ inputs.file-path }})
filename=$(basename "${{ inputs.file-path }}")
j=0
if [ -d ${{ inputs.asset-path }} ]; then
for filename in `ls ${{ inputs.asset-path }}`;
do
folder_list[j]=${{ inputs.asset-path }}/$filename
j=`expr $j + 1`
done
else
folder_list[0]=${{ inputs.asset-path }}
fi
echo "Uploading asset... "
curl --silent \
--request POST \
--url "$upload_url?name=$filename" \
--header "authorization: Bearer ${{ github.token }}" \
--header "content-type: $content_type" \
--data-binary @"${{ inputs.file-path }}"
for filepath in ${folder_list[@]};
do
filename=$(basename "${filepath}")
content_type=$(file -b --mime-type ${filepath})
curl --silent \
--request POST \
--url "$upload_url?name=$filename" \
--header "authorization: Bearer ${{ github.token }}" \
--header "content-type: $content_type" \
--data-binary @"${filepath}"
done
shell: bash
42 changes: 42 additions & 0 deletions .github/actions/upload-to-oss-action/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Upload file to oss

Upload file to oss

## Inputs

### `key-id`

**Required** access key ID of oss. Default `''`.

### `key-secret`

**Required** access key secret of oss. Default `''`.

### `endpoint`

**Required** endpoint of oss. Default `''`.

### `bucket`

**Required** bucket of oss. Default `''`.

### `asset-path`

**Required** file path to be uploaded. Default `''`.

### `target-path`

**Required** path where the oss object is stored. Default `''`.

## Example usage

```yaml
uses: ./.github/actions/upload-to-oss-action
with:
key-id: ${{ secrets.OSS_ID }}
key-secret: ${{ secrets.OSS_SECRET }}
endpoint: ${{ secrets.OSS_ENDPOINT }}
bucket: nebula-graph
asset-path: build/cpack_output
target-path: package/v2-nightly/${{ steps.vars.outputs.subdir }}
```
50 changes: 50 additions & 0 deletions .github/actions/upload-to-oss-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: 'Upload to oss'
description: 'Upload files to oss'
inputs:
key-id:
description: 'access key ID'
required: true
default: ''
key-secret:
description: 'access key secret'
required: true
default: ''
endpoint:
description: 'endpooint'
required: true
default: ''
bucket:
description: 'bucket'
required: true
default: ''
asset-path:
description: 'file path to be uploaded'
required: true
default: ''
target-path:
description: 'file path stored on the OSS'
required: true
default: ''
runs:
using: "composite"
steps:
- run: |
j=0
if [ -d ${{ inputs.asset-path }} ]; then
for filename in `ls ${{ inputs.asset-path }}`;
do
folder_list[j]=${{ inputs.asset-path }}/$filename
j=`expr $j + 1`
done
else
folder_list[0]=${{ inputs.asset-path }}
fi
echo "Uploading to oss... "
for filepath in ${folder_list[@]};
do
ossutil64 -e ${{ inputs.endpoint}} \
-i ${{ inputs.key-id }} \
-k ${{ inputs.key-secret }} \
-f cp $filepath oss://${{ inputs.bucket }}/${{ inputs.target-path }}/$(basename ${filepath})
done
shell: bash
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@ jobs:
filename=$(find pkg-build/cpack_output -type f \( -iname \*.deb -o -iname \*.rpm \))
sha256sum $filename > $filename.$SHA_EXT
subdir=$(echo $tag |sed 's/^v//')
echo "::set-output name=filepath::$filename"
echo "::set-output name=shafilepath::$filename.$SHA_EXT"
echo "::set-output name=subdir::$subdir"
- uses: ./.github/actions/upload-assets-action
with:
asset-path: pkg-build/cpack_output
tag: ${{ steps.tag.outputs.tag }}
- name: upload package to oss
uses: tvrcgo/[email protected]
- uses: ./.github/actions/upload-to-oss-action
with:
key-id: ${{ secrets.OSS_ID }}
key-secret: ${{ secrets.OSS_SECRET }}
Expand Down Expand Up @@ -87,6 +84,7 @@ jobs:
service:
- metad
- storaged
- tools
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/tagname-action
Expand Down

0 comments on commit b4f6f0a

Please sign in to comment.