diff --git a/.github/workflows/tag-workflow.yml b/.github/workflows/tag-workflow.yml new file mode 100644 index 00000000..a9604711 --- /dev/null +++ b/.github/workflows/tag-workflow.yml @@ -0,0 +1,182 @@ +name: build for test/release + +on: + create: + tags: + - '**' + pull_request: + branches: + - master + push: + branches: + - master + - test* + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: 'true' + fetch-depth: '0' + + - name: vars + id: vars + run: | + export commit=$(git rev-parse HEAD) + export short=$(git rev-parse --short HEAD) + export github_tag=${GITHUB_REF##*/} + export git_message=$(git rev-list --format=%s --max-count=1 HEAD | tail +2) + export repo_name=${GITHUB_REPOSITORY##*/} + export branch=$(git symbolic-ref --short -q HEAD) + export tag=$(git describe --tags $(git rev-list --tags --max-count=1)) + export artifact_name=${repo_name}_$(git rev-parse --short HEAD).tar.gz + export pub_method=pushTest + export job_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID + export oss_exists=0 + export ftp_exists=0 + if [[ "${{github.event_name}}" == "create" ]] && ([[ "$github_tag" =~ "v1." ]] || [[ "$github_tag" =~ "v2." ]]); then + export pub_method=pushRelease + fi + if [[ "$branch" == "" ]]; then + export branch=$github_tag + fi + if [[ "$tag" == "" ]]; then + export tag=$github_tag + fi + if [[ "${{secrets.OSS_KEY_ID}}" != "" && \ + "${{secrets.OSS_KEY_SECRET}}" != "" && \ + "${{secrets.OSS_ENDPOINT}}" != "" && \ + "${{secrets.OSS_BUCKET}}" != "" ]]; then + export oss_exists=1 + fi + if [[ "${{secrets.FTP_HOST}}" != "" ]]; then + export ftp_exists=1 + fi + echo "::set-output name=commit::$commit" + echo "::set-output name=short::$short" + echo "::set-output name=github_tag::$github_tag" + echo "::set-output name=git_message::$git_message" + echo "::set-output name=repo_name::$repo_name" + echo "::set-output name=branch::$branch" + echo "::set-output name=tag::$tag" + echo "::set-output name=artifact_name::$artifact_name" + echo "::set-output name=job_url::$job_url" + echo "::set-output name=pub_method::$pub_method" + echo "::set-output name=oss_exists::$oss_exists" + echo "::set-output name=ftp_exists::$ftp_exists" + + - name: show environment + run: | + echo event = ${{github.event_name}} + echo github_repository: $GITHUB_REPOSITORY + echo vars.commit = ${{steps.vars.outputs.commit}} + echo vars.short_commit = ${{steps.vars.outputs.short}} + echo vars.github_tag = ${{steps.vars.outputs.github_tag}} + echo vars.git_message = ${{steps.vars.outputs.git_message}} + echo vars.repo_name = ${{steps.vars.outputs.repo_name}} + echo vars.branch = ${{steps.vars.outputs.branch}} + echo vars.tag = ${{steps.vars.outputs.tag}} + echo vars.artifact_name = ${{steps.vars.outputs.artifact_name}} + echo vars.pub_method = ${{steps.vars.outputs.pub_method}} + echo secrets.godeye_url = ${{ secrets.GODEYE_URL }} + echo vars.oss_exists = ${{steps.vars.outputs.oss_exists}} + echo vars.ftp_exists = ${{steps.vars.outputs.ftp_exists}} + echo github.ref = ${{github.ref}} + echo github.ref_name = ${{github.ref_name}} + echo vars.job_url = ${{steps.vars.outputs.job_url}} + echo ftp_url = ftp://${{secrets.FTP_HOST}}/${{steps.vars.outputs.repo_name}}/${{steps.vars.outputs.artifact_name}} + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + - name: Install GCC + uses: egor-tensin/setup-gcc@v1 + with: + version: latest + platform: x64 + - name: Setup Rust + run: (sudo apt-get update && sudo apt-get install -y clang libssl-dev && which cargo && which rustc) || (curl https://sh.rustup.rs -sSf | sh -s -- -y) + - name: install deps + run: sudo apt-get 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 + - name: Build + run: | + sudo make deps + sudo make + mkdir ./release && mv ./market-client ./venus-market ./release + + - name: Zip Release + uses: TheDoctor0/zip-release@0.6.0 + with: + filename: ${{steps.vars.outputs.artifact_name}} + path: ./release + type: tar + + - name: release + id: release + uses: ncipollo/release-action@v1 + if: ${{ steps.vars.outputs.pub_method=='pushRelease' }} + with: + artifacts: ${{steps.vars.outputs.artifact_name}} + tag: ${{ steps.vars.outputs.github_tag }} + commit: ${{ steps.vars.outputs.commit }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: upload ftp + id: uploadftp + if: ${{ steps.vars.outputs.ftp_exists == '1' }} + continue-on-error: true + run: | + 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}} + echo "upload file: ${{steps.vars.outputs.artifact_name}} successfully!" + + - name: setup oss + id: setuposs + if: ${{ steps.vars.outputs.oss_exists == '1' && steps.uploadftp.outcome != 'success' && steps.vars.outputs.pub_method == 'pushTest' }} + continue-on-error: true + uses: manyuanrong/setup-ossutil@master + with: + endpoint: ${{secrets.OSS_ENDPOINT}} + access-key-id: ${{ secrets.OSS_KEY_ID }} + access-key-secret: ${{ secrets.OSS_KEY_SECRET }} + + - name: cp files to aliyun + id: cposs + if: ${{ steps.setuposs.outcome == 'success' }} + continue-on-error: true + run: | + ossutil cp ./${{steps.vars.outputs.artifact_name}} ${{secrets.OSS_BUCKET}} + export signed_url=`ossutil sign ${{secrets.OSS_BUCKET}}/${{steps.vars.outputs.artifact_name}} --timeout 31104000 | sed -n 1p` + echo '::set-output name=oss_signed_url::$(signed_url)' + + - name: upload artifacts + if: ${{ steps.vars.outputs.pub_method == 'pushTest' && steps.uploadftp.outcome != 'success' && steps.cposs.outcome != 'success' }} + continue-on-error: true + uses: actions/upload-artifact@v2 + with: + name: ${{steps.vars.outputs.artifact_name}} + path: ./${{steps.vars.outputs.artifact_name}} + if-no-files-found: error + + - name: push god-eye + run: | + export link=${{steps.vars.outputs.job_url}} + if [[ "${{ steps.release.outcome }}" == "success" ]]; then + export link=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download/${{steps.vars.outputs.github_tag}}/${{steps.vars.outputs.artifact_name}} + elif [[ "${{ steps.uploadftp.outcome }}" == "success" ]]; then + export link=ftp://${{secrets.FTP_HOST}}/${{steps.vars.outputs.repo_name}}/${{steps.vars.outputs.artifact_name}} + elif [[ "${{ steps.cposs.outcome }}" == "success" ]]; then + export link=${{steps.cposs.outputs.oss_signed_url}} + fi + echo download target file : $link + set +e + curl --max-time 20 -X PUT ${{secrets.GODEYE_URL}}/${{steps.vars.outputs.pub_method}} \ + --data-urlencode "type=1" \ + --data-urlencode "commitId=${{steps.vars.outputs.commit}}" \ + --data-urlencode "branch=${{steps.vars.outputs.branch}}" \ + --data-urlencode "programName=${{steps.vars.outputs.repo_name}}" \ + --data-urlencode "link=$link" \ + --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}}" \ + --data-urlencode "version=${{steps.vars.outputs.short}}" + set -e \ No newline at end of file