|
| 1 | +name: reuse build and upload |
| 2 | + |
| 3 | +on: |
| 4 | + |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + bin_name: |
| 8 | + type: string |
| 9 | + has_ffi: |
| 10 | + type: boolean |
| 11 | + secrets: |
| 12 | + OSS_KEY_ID: |
| 13 | + OSS_KEY_SECRET: |
| 14 | + OSS_ENDPOINT: |
| 15 | + OSS_BUCKET: |
| 16 | + FTP_HOST: |
| 17 | + required: true |
| 18 | + FTP_USER: |
| 19 | + required: true |
| 20 | + FTP_PWD: |
| 21 | + required: true |
| 22 | + GODEYE_URL: |
| 23 | + required: true |
| 24 | + token: |
| 25 | + required: true |
| 26 | + |
| 27 | +jobs: |
| 28 | + |
| 29 | + build: |
| 30 | + runs-on: ubuntu-20.04 |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v2 |
| 33 | + with: |
| 34 | + submodules: 'true' |
| 35 | + fetch-depth: '0' |
| 36 | + |
| 37 | + - name: vars |
| 38 | + id: vars |
| 39 | + run: | |
| 40 | + export commit=$(git rev-parse HEAD) |
| 41 | + export short=$(git rev-parse --short HEAD) |
| 42 | + export github_tag=${{github.ref_name}} |
| 43 | + export tag=$github_tag |
| 44 | + export branch=$github_tag |
| 45 | + export git_message=$(git rev-list --format=%s --max-count=1 HEAD | tail +2) |
| 46 | + export repo_name=${GITHUB_REPOSITORY##*/} |
| 47 | + export artifact_name=${repo_name}_$(git rev-parse --short HEAD).tar.gz |
| 48 | + export pub_method=pushTest |
| 49 | + export job_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID |
| 50 | + export oss_exists=0 |
| 51 | + export ftp_exists=0 |
| 52 | + export is_tag_create=false |
| 53 | + export rx_tag='^refs\/tags\/.*' |
| 54 | + export rx_version_tag='^v([0-9]+\.){0,2}(\*|[0-9]+)(-rc[0-9]*){0,1}$' |
| 55 | + if [[ "${{github.ref}}" =~ $rx_tag ]]; then |
| 56 | + export is_tag_create=true |
| 57 | + if [[ "${{github.ref_name}}" =~ $rx_version_tag ]]; then |
| 58 | + export pub_method=pushRelease |
| 59 | + fi |
| 60 | + fi |
| 61 | + if [[ "${{secrets.OSS_KEY_ID}}" != "" && \ |
| 62 | + "${{secrets.OSS_KEY_SECRET}}" != "" && \ |
| 63 | + "${{secrets.OSS_ENDPOINT}}" != "" && \ |
| 64 | + "${{secrets.OSS_BUCKET}}" != "" ]]; then |
| 65 | + export oss_exists=1 |
| 66 | + fi |
| 67 | + if [[ "${{secrets.FTP_HOST}}" != "" ]]; then |
| 68 | + export ftp_exists=1 |
| 69 | + fi |
| 70 | + echo "::set-output name=commit::$commit" |
| 71 | + echo "::set-output name=short::$short" |
| 72 | + echo "::set-output name=github_tag::$github_tag" |
| 73 | + echo "::set-output name=git_message::$git_message" |
| 74 | + echo "::set-output name=repo_name::$repo_name" |
| 75 | + echo "::set-output name=branch::$branch" |
| 76 | + echo "::set-output name=tag::$tag" |
| 77 | + echo "::set-output name=artifact_name::$artifact_name" |
| 78 | + echo "::set-output name=job_url::$job_url" |
| 79 | + echo "::set-output name=pub_method::$pub_method" |
| 80 | + echo "::set-output name=is_tag_create::$is_tag_create" |
| 81 | + echo "::set-output name=oss_exists::$oss_exists" |
| 82 | + echo "::set-output name=ftp_exists::$ftp_exists" |
| 83 | + - name: show environment |
| 84 | + run: | |
| 85 | + echo bin_name = ${{inputs.bin_name}} |
| 86 | + echo has_ffi = ${{inputs.has_ffi}} |
| 87 | + echo event = ${{github.event_name}} |
| 88 | + echo github_repository: $GITHUB_REPOSITORY |
| 89 | + echo vars.commit = ${{steps.vars.outputs.commit}} |
| 90 | + echo vars.short_commit = ${{steps.vars.outputs.short}} |
| 91 | + echo vars.github_tag = ${{steps.vars.outputs.github_tag}} |
| 92 | + echo vars.git_message = "${{steps.vars.outputs.git_message}}" |
| 93 | + echo vars.repo_name = ${{steps.vars.outputs.repo_name}} |
| 94 | + echo vars.branch = ${{steps.vars.outputs.branch}} |
| 95 | + echo vars.tag = ${{steps.vars.outputs.tag}} |
| 96 | + echo vars.artifact_name = ${{steps.vars.outputs.artifact_name}} |
| 97 | + echo vars.pub_method = ${{steps.vars.outputs.pub_method}} |
| 98 | + echo secrets.godeye_url = ${{ secrets.GODEYE_URL }} |
| 99 | + echo vars.oss_exists = ${{steps.vars.outputs.oss_exists}} |
| 100 | + echo vars.ftp_exists = ${{steps.vars.outputs.ftp_exists}} |
| 101 | + echo vars.is_tag_create = ${{steps.vars.outputs.is_tag_create}} |
| 102 | + echo github.ref = ${{github.ref}} |
| 103 | + echo github.ref_name = ${{github.ref_name}} |
| 104 | + echo vars.job_url = ${{steps.vars.outputs.job_url}} |
| 105 | + echo ftp_url = ftp://${{secrets.FTP_HOST}}/${{steps.vars.outputs.repo_name}}/${{steps.vars.outputs.artifact_name}} |
| 106 | + - name: Set up Go |
| 107 | + uses: actions/setup-go@v2 |
| 108 | + with: |
| 109 | + go-version: 1.18 |
| 110 | + |
| 111 | + - name: install deps |
| 112 | + if: ${{ !inputs.has_ffi }} |
| 113 | + run: | |
| 114 | + sudo apt-get update |
| 115 | + sudo apt-get install ncftp |
| 116 | + - name: install more deps |
| 117 | + if: ${{ inputs.has_ffi }} |
| 118 | + run: | |
| 119 | + sudo apt-get update |
| 120 | + sudo apt-get -o Acquire::Retries=3 install make ncftp mesa-opencl-icd ocl-icd-opencl-dev gcc git bzr jq pkg-config curl clang build-essential hwloc libhwloc-dev wget -y && sudo apt upgrade -y |
| 121 | + - name: Build |
| 122 | + run: | |
| 123 | + go clean --modcache && make |
| 124 | + mkdir ./release |
| 125 | + if [[ "${{steps.vars.outputs.repo_name}}" == "venus-market" ]]; then |
| 126 | + mv ./market-client ./venus-market ./release |
| 127 | + fi |
| 128 | + if [[ "${{steps.vars.outputs.repo_name}}" != "venus-market" ]]; then |
| 129 | + mv ./${{inputs.bin_name}} ./release |
| 130 | + fi |
| 131 | + - name: Zip Release |
| 132 | + uses: TheDoctor0/zip-release@0.6.0 |
| 133 | + with: |
| 134 | + filename: ${{steps.vars.outputs.artifact_name}} |
| 135 | + path: ./release |
| 136 | + type: tar |
| 137 | + |
| 138 | + - name: upload artifacts |
| 139 | + uses: actions/upload-artifact@v2 |
| 140 | + if: ${{ steps.vars.outputs.pub_method == 'pushRelease' }} |
| 141 | + with: |
| 142 | + name: ${{steps.vars.outputs.artifact_name}} |
| 143 | + path: ./${{steps.vars.outputs.artifact_name}} |
| 144 | + if-no-files-found: error |
| 145 | + |
| 146 | + - name: Release |
| 147 | + uses: softprops/action-gh-release@v1 |
| 148 | + if: startsWith(github.ref, 'refs/tags/') |
| 149 | + continue-on-error: true |
| 150 | + with: |
| 151 | + files: | |
| 152 | + ./${{steps.vars.outputs.artifact_name}} |
| 153 | +
|
| 154 | + - name: upload ftp |
| 155 | + id: uploadftp |
| 156 | + if: ${{ steps.vars.outputs.ftp_exists == '1' }} |
| 157 | + continue-on-error: true |
| 158 | + run: | |
| 159 | + ncftpput -m -R -v -u ${{secrets.FTP_USER}} -p ${{secrets.FTP_PWD}} ${{secrets.FTP_HOST}} ./${{steps.vars.outputs.repo_name}} ./${{steps.vars.outputs.artifact_name}} |
| 160 | + echo "upload file: ${{steps.vars.outputs.artifact_name}} successfully!" |
| 161 | + - name: setup oss |
| 162 | + id: setuposs |
| 163 | + if: ${{ steps.vars.outputs.oss_exists == '1' && steps.uploadftp.outcome != 'success' && steps.vars.outputs.pub_method == 'pushTest' }} |
| 164 | + uses: manyuanrong/setup-ossutil@master |
| 165 | + with: |
| 166 | + endpoint: ${{secrets.OSS_ENDPOINT}} |
| 167 | + access-key-id: ${{ secrets.OSS_KEY_ID }} |
| 168 | + access-key-secret: ${{ secrets.OSS_KEY_SECRET }} |
| 169 | + |
| 170 | + - name: cp files to aliyun |
| 171 | + id: cposs |
| 172 | + if: ${{ steps.setuposs.outcome == 'success' }} |
| 173 | + run: | |
| 174 | + ossutil cp ./${{steps.vars.outputs.artifact_name}} ${{secrets.OSS_BUCKET}} |
| 175 | + export signed_url=`ossutil sign ${{secrets.OSS_BUCKET}}/${{steps.vars.outputs.artifact_name}} --timeout 31104000 | sed -n 1p` |
| 176 | + echo '::set-output name=oss_signed_url::$(signed_url)' |
| 177 | + - name: push god-eye |
| 178 | + run: | |
| 179 | + export link=${{steps.vars.outputs.job_url}} |
| 180 | + if [[ "${{ steps.release.outcome }}" == "success" ]]; then |
| 181 | + export link=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download/${{steps.vars.outputs.github_tag}}/${{steps.vars.outputs.artifact_name}} |
| 182 | + elif [[ "${{ steps.uploadftp.outcome }}" == "success" ]]; then |
| 183 | + export link=ftp://${{secrets.FTP_HOST}}/${{steps.vars.outputs.repo_name}}/${{steps.vars.outputs.artifact_name}} |
| 184 | + elif [[ "${{ steps.cposs.outcome }}" == "success" ]]; then |
| 185 | + export link=${{steps.cposs.outputs.oss_signed_url}} |
| 186 | + fi |
| 187 | + echo download target file : $link |
| 188 | + set +e |
| 189 | + curl --max-time 20 -X PUT ${{secrets.GODEYE_URL}}/${{steps.vars.outputs.pub_method}} \ |
| 190 | + --data-urlencode "type=1" \ |
| 191 | + --data-urlencode "commitId=${{steps.vars.outputs.commit}}" \ |
| 192 | + --data-urlencode "branch=${{steps.vars.outputs.branch}}" \ |
| 193 | + --data-urlencode "programName=${{steps.vars.outputs.repo_name}}" \ |
| 194 | + --data-urlencode "link=$link" \ |
| 195 | + --data-urlencode "description=message:${{steps.vars.outputs.git_message}}, branch:${{steps.vars.outputs.branch}}, commit:${{steps.vars.outputs.short}}, tag:${{steps.vars.outputs.github_tag}}" \ |
| 196 | + --data-urlencode "version=${{steps.vars.outputs.short}}" |
| 197 | + set -e |
0 commit comments