-
Notifications
You must be signed in to change notification settings - Fork 3
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
3 changed files
with
111 additions
and
6 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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Container image that runs your code | ||
FROM alpine:3.10 | ||
FROM centos:7 | ||
|
||
# Copies your code file from your action repository to the filesystem path `/` of the container | ||
COPY entrypoint.sh /entrypoint.sh | ||
COPY *.sh / | ||
|
||
# Code file to execute when the docker container starts up (`entrypoint.sh`) | ||
ENTRYPOINT ["/entrypoint.sh"] |
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,15 +1,25 @@ | ||
name: 'Hello World' | ||
description: 'Greet someone and record the time' | ||
inputs: | ||
who-to-greet: # id of input | ||
description: 'Who to greet' | ||
github_token: | ||
description: 'GITHUB_TOKEN for uploading releases to Github asserts.' | ||
required: true | ||
default: 'World' | ||
default: '' | ||
os: # id of input | ||
description: 'os the running programs operating system target: one of darwin, freebsd, linux, and so on.' | ||
required: false | ||
default: '' | ||
arch: | ||
description: 'arch is the running programs architecture target: one of 386, amd64, arm, s390x, and so on.' | ||
required: false | ||
default: '' | ||
outputs: | ||
time: # id of output | ||
description: 'The time we greeted you' | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
args: | ||
- ${{ inputs.who-to-greet }} | ||
- ${{ inputs.github_token }} | ||
- ${{ inputs.os }} | ||
- ${{ inputs.arch }} |
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,95 @@ | ||
#!/bin/bash -eux | ||
#GITHUB_WORKSPACE=/Users/guang/tmp/koko | ||
|
||
if [ '${INPUT_UPLOAD_URL}' ];then | ||
RELEASE_ASSETS_UPLOAD_URL=${INPUT_UPLOAD_URL} | ||
else | ||
RELEASE_ASSETS_UPLOAD_URL=$(cat ${GITHUB_EVENT_PATH} | jq -r .release.upload_url) | ||
RELEASE_ASSETS_UPLOAD_URL=${RELEASE_ASSETS_UPLOAD_URL%\{?name,label\}} | ||
fi | ||
#RELEASE_ASSETS_UPLOAD_URL='https://uploads.github.com/repos/ibuler/koko/releases/27862783/assets' | ||
#INPUT_GITHUB_TOKEN= | ||
|
||
function get_md5() { | ||
file=$1 | ||
if [[ "$(uname)" == "Darwin" ]];then | ||
echo $(md5 ${file} | awk '{ print $NF }') | ||
else | ||
echo $(md5sum ${file} | cut -d ' ' -f 1) | ||
fi | ||
} | ||
|
||
# First to build it | ||
workspace=${GITHUB_WORKSPACE} | ||
build_dir='' | ||
if [[ -f ${workspace}/build.sh ]];then | ||
build_dir=${workspace} | ||
fi | ||
|
||
if [[ -z ${build_dir} && -f ${workspace}/utils/build.sh ]];then | ||
build_dir=${workspace}/utils | ||
fi | ||
|
||
if [[ -z ${build_dir} ]];then | ||
echo "No build script found at: PROJECT/build.sh" | ||
exit 10 | ||
fi | ||
|
||
cd ${build_dir} && bash build.sh | ||
|
||
# 准备打包 | ||
cd ${workspace}/release | ||
for i in $(ls);do | ||
if [[ ! -d $i ]];then | ||
continue | ||
fi | ||
if [[ "${OS}" && "${ARCH}" ]];then | ||
tar_dirname=$i-${RELEASE_TAG:-"master"}-${OS}-${ARCH} | ||
mv $i ${tar_dirname} | ||
else | ||
tar_dirname=$i | ||
fi | ||
tar_filename=${tar_dirname}.tar.gz | ||
tar czvf ${tar_filename} ${tar_dirname} | ||
md5sum=$(get_md5 ${tar_filename}) | ||
echo ${md5sum} > ${tar_filename}.md5 && rm -rf ${tar_dirname} | ||
done | ||
|
||
function upload_zip() { | ||
file=$1 | ||
curl \ | ||
--fail \ | ||
-X POST \ | ||
--data-binary @${file} \ | ||
-H 'Content-Type: application/gzip' \ | ||
-H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" \ | ||
"${RELEASE_ASSETS_UPLOAD_URL}?name=${file}" | ||
return $? | ||
} | ||
|
||
function upload_octet() { | ||
file=$1 | ||
curl \ | ||
--fail \ | ||
-X POST \ | ||
--data @${file} \ | ||
-H 'Content-Type: application/octet-stream' \ | ||
-H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" \ | ||
"${RELEASE_ASSETS_UPLOAD_URL}?name=${file}" | ||
return $? | ||
} | ||
|
||
# 打包完上传 | ||
for i in $(ls);do | ||
# 因为可能是md5已被上传了 | ||
if [ ! -f $i ];then | ||
continue | ||
fi | ||
if [[ $i == *.tar.gz ]];then | ||
upload_zip $i && rm -f ${i} | ||
|
||
if [[ -f $i.md5 ]];then | ||
upload_octet $i.md5 && rm -f ${i} | ||
fi | ||
fi | ||
done |