From 6e7d46ab5f4066cfa80109284cd0dd236e085394 Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Fri, 5 Aug 2022 09:29:57 +0800 Subject: [PATCH 1/2] ci: add docker_image.yml --- .github/workflows/baisc_checks.yml | 1 - .github/workflows/docker-image.yml | 47 ++++++++++++++++++++++++++++++ .github/workflows/tag-workflow.yml | 35 +++++++--------------- .github/workflows/test.yml | 1 - 4 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/baisc_checks.yml b/.github/workflows/baisc_checks.yml index 00d0eb1c5c..8acd6e80af 100644 --- a/.github/workflows/baisc_checks.yml +++ b/.github/workflows/baisc_checks.yml @@ -4,7 +4,6 @@ on: push: branches: - master - - main pull_request: branches: - '**' diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000000..0e3fb4658c --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,47 @@ +name: Docker Image CI + +on: + push: + branches: ['prep/**', 'release/**', 'test/**', master] + tags: ['**'] + +jobs: + + build: + + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v3 + - name: Create vars + id: vars + run: | + export github_tag=${{ github.ref_name }} + export is_tag_create=false + + export rx_tag='^refs\/tags\/.*' + export rx_version_tag='^v([0-9]+\.){0,2}(\*|[0-9]+)(-rc[0-9]*){0,1}$' + if [[ "${{github.ref}}" =~ $rx_tag ]]; then + export is_tag_create=true + fi + + echo "::set-output name=github_tag::$github_tag" + echo "::set-output name=is_tag_create::$is_tag_create" + + - name: Show environment + run: | + echo is_tag_create = ${{ steps.vars.outputs.is_tag_create }} + echo github_tag = ${{ steps.vars.outputs.github_tag }} + + - name: Build the Docker image + if: ${{ steps.vars.outputs.is_tag_create == 'true' }} + run: | + make docker-buildenv + make docker-runtime + docker build . --file dockerfile --tag filvenus/venus:latest + docker tag filvenus/venus:latest filvenus/venus:${{ steps.vars.outputs.github_tag }} + docker login --username=filvenus --password ${{ secrets.DOCKER_PASSWORD }} + docker push filvenus/venus:${{ steps.vars.outputs.github_tag }} + docker push filvenus/venus:latest + docker push filvenus/venus-runtime:latest + docker push filvenus/venus-buildenv:latest diff --git a/.github/workflows/tag-workflow.yml b/.github/workflows/tag-workflow.yml index f50f251c90..570112d287 100644 --- a/.github/workflows/tag-workflow.yml +++ b/.github/workflows/tag-workflow.yml @@ -2,9 +2,10 @@ name: build for test/release on: push: - branches: ['prep/**', 'release/**', 'test/**', master, main] + branches: ['prep/**', 'release/**', 'test/**', master] tags: ['**'] workflow_dispatch: + jobs: build: runs-on: ubuntu-20.04 @@ -96,7 +97,7 @@ jobs: - name: Build run: | - go clean --modcache && make deps && make + go clean --modcache && make mkdir ./release && mv ./venus ./release - name: Zip Release @@ -106,6 +107,14 @@ jobs: path: ./release type: tar + - name: upload artifacts + if: ${{ steps.vars.outputs.pub_method == 'pushRelease' }} + uses: actions/upload-artifact@v2 + with: + name: ${{steps.vars.outputs.artifact_name}} + path: ./${{steps.vars.outputs.artifact_name}} + if-no-files-found: error + - name: release id: release uses: ncipollo/release-action@v1 @@ -144,15 +153,6 @@ jobs: 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 == 'pushRelease' }} - continue-on-error: true - uses: actions/upload-artifact@v2 - with: - name: ${{steps.vars.outputs.artifact_name}} - path: ./release - if-no-files-found: error - - name: push god-eye run: | export link=${{steps.vars.outputs.job_url}} @@ -174,16 +174,3 @@ jobs: --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 - - - name: Publish the Docker image - if: ${{ steps.vars.outputs.is_tag_create == 'true' }} - run: | - make docker-buildenv - make docker-runtime - docker build . --file dockerfile --tag filvenus/venus:latest - docker tag filvenus/venus:latest filvenus/venus:${{steps.vars.outputs.github_tag}} - docker login --username=filvenus --password ${{ secrets.DOCKER_PASSWORD }} - docker push filvenus/venus:${{steps.vars.outputs.github_tag}} - docker push filvenus/venus:latest - docker push filvenus/venus-runtime:latest - docker push filvenus/venus-buildenv:latest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 37dd689f0d..0fc741cd35 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,6 @@ on: push: branches: - master - - main pull_request: branches: - '**' From 47ecc43ea945e367c945b695faf1231d02c83588 Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Mon, 8 Aug 2022 09:52:06 +0800 Subject: [PATCH 2/2] ci: add common workflow --- .github/workflows/build_upload.yml | 13 ++++ ...g-workflow.yml => common_build_upload.yml} | 38 ++++++++--- .github/workflows/common_docker_image.yml | 54 ++++++++++++++++ .github/workflows/common_go.yml | 64 +++++++++++++++++++ .github/workflows/docker-image.yml | 47 -------------- .github/workflows/docker_image.yml | 11 ++++ .github/workflows/test.yml | 7 -- 7 files changed, 170 insertions(+), 64 deletions(-) create mode 100644 .github/workflows/build_upload.yml rename .github/workflows/{tag-workflow.yml => common_build_upload.yml} (91%) create mode 100644 .github/workflows/common_docker_image.yml create mode 100644 .github/workflows/common_go.yml delete mode 100644 .github/workflows/docker-image.yml create mode 100644 .github/workflows/docker_image.yml diff --git a/.github/workflows/build_upload.yml b/.github/workflows/build_upload.yml new file mode 100644 index 0000000000..c04c1d2e33 --- /dev/null +++ b/.github/workflows/build_upload.yml @@ -0,0 +1,13 @@ +name: build and upload + +on: + push: + branches: ['prep/**', 'release/**', 'test/**', master] + tags: ['**'] + +jobs: + build_upload: + uses: ./.github/workflows/common_build_upload.yml + with: + bin_name: 'venus' + has_ffi: true diff --git a/.github/workflows/tag-workflow.yml b/.github/workflows/common_build_upload.yml similarity index 91% rename from .github/workflows/tag-workflow.yml rename to .github/workflows/common_build_upload.yml index 570112d287..36749c9b41 100644 --- a/.github/workflows/tag-workflow.yml +++ b/.github/workflows/common_build_upload.yml @@ -1,12 +1,16 @@ -name: build for test/release +name: reuse build and upload on: - push: - branches: ['prep/**', 'release/**', 'test/**', master] - tags: ['**'] - workflow_dispatch: + + workflow_call: + inputs: + bin_name: + type: string + has_ffi: + type: boolean jobs: + build: runs-on: ubuntu-20.04 steps: @@ -67,6 +71,8 @@ jobs: - name: show environment run: | + echo bin_name = ${{inputs.bin_name}} + echo has_ffi = ${{inputs.has_ffi}} echo event = ${{github.event_name}} echo github_repository: $GITHUB_REPOSITORY echo vars.commit = ${{steps.vars.outputs.commit}} @@ -86,11 +92,20 @@ jobs: 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 deps + if: ${{ !inputs.has_ffi }} + run: | + sudo apt-get update + sudo apt-get install ncftp + + - name: install more deps + if: ${{ inputs.has_ffi }} run: | sudo apt-get update 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 @@ -98,7 +113,13 @@ jobs: - name: Build run: | go clean --modcache && make - mkdir ./release && mv ./venus ./release + mkdir ./release + if [[ "${{steps.vars.outputs.repo_name}}" == "venus-market" ]]; then + mv ./market-client ./venus-market ./release + fi + if [[ "${{steps.vars.outputs.repo_name}}" != "venus-market" ]]; then + mv ./${{inputs.bin_name}} ./release + fi - name: Zip Release uses: TheDoctor0/zip-release@0.6.0 @@ -108,8 +129,8 @@ jobs: type: tar - name: upload artifacts - if: ${{ steps.vars.outputs.pub_method == 'pushRelease' }} uses: actions/upload-artifact@v2 + if: ${{ steps.vars.outputs.pub_method == 'pushRelease' }} with: name: ${{steps.vars.outputs.artifact_name}} path: ./${{steps.vars.outputs.artifact_name}} @@ -129,7 +150,6 @@ jobs: - 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!" @@ -137,7 +157,6 @@ jobs: - 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}} @@ -147,7 +166,6 @@ jobs: - 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` diff --git a/.github/workflows/common_docker_image.yml b/.github/workflows/common_docker_image.yml new file mode 100644 index 0000000000..011a7be310 --- /dev/null +++ b/.github/workflows/common_docker_image.yml @@ -0,0 +1,54 @@ +name: Reuse Docker Image CI + +on: + + workflow_call: + +jobs: + + build_docker_image: + + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v3 + - name: Create vars + id: vars + run: | + export github_tag=${{ github.ref_name }} + export repo_name=${GITHUB_REPOSITORY##*/} + export is_tag_create=false + export docker_user_name='filvenus' + + export rx_tag='^refs\/tags\/.*' + export rx_version_tag='^v([0-9]+\.){0,2}(\*|[0-9]+)(-rc[0-9]*){0,1}$' + if [[ "${{github.ref}}" =~ $rx_tag ]]; then + export is_tag_create=true + fi + + echo "::set-output name=github_tag::$github_tag" + echo "::set-output name=repo_name::$repo_name" + echo "::set-output name=is_tag_create::$is_tag_create" + echo "::set-output name=docker_user_name::$docker_user_name" + + - name: Show environment + run: | + echo is_tag_create = ${{ steps.vars.outputs.is_tag_create }} + echo github_tag = ${{ steps.vars.outputs.github_tag }} + echo repo_name = ${{ steps.vars.outputs.repo_name }} + echo docker_user_name = ${{steps.vars.outputs.docker_user_name}} + + - name: Build the Docker image + if: ${{ steps.vars.outputs.is_tag_create == 'true' }} + run: | + if [[ "${{steps.vars.outputs.repo_name}}" = "venus" ]]; then + make docker-buildenv + make docker-runtime + fi + docker build . --file dockerfile --tag ${{steps.vars.outputs.docker_user_name}}/${{steps.vars.outputs.repo_name}}:latest + docker tag ${{steps.vars.outputs.docker_user_name}}/${{steps.vars.outputs.repo_name}}:latest ${{steps.vars.outputs.docker_user_name}}/${{steps.vars.outputs.repo_name}}:${{ steps.vars.outputs.github_tag }} + docker login --username=${{steps.vars.outputs.docker_user_name}} --password ${{ secrets.DOCKER_PASSWORD }} + docker push ${{steps.vars.outputs.docker_user_name}}/${{steps.vars.outputs.repo_name}}:${{ steps.vars.outputs.github_tag }} + docker push ${{steps.vars.outputs.docker_user_name}}/${{steps.vars.outputs.repo_name}}:latest + docker push ${{steps.vars.outputs.docker_user_name}}/${{steps.vars.outputs.repo_name}}-runtime:latest + docker push ${{steps.vars.outputs.docker_user_name}}/${{steps.vars.outputs.repo_name}}-buildenv:latest diff --git a/.github/workflows/common_go.yml b/.github/workflows/common_go.yml new file mode 100644 index 0000000000..58e87c69aa --- /dev/null +++ b/.github/workflows/common_go.yml @@ -0,0 +1,64 @@ +name: build and golangci-lint and test + +on: + + workflow_call: + inputs: + has_ffi: + type: boolean + +jobs: + + check: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - name: vars + id: vars + run: | + export repo_name=${GITHUB_REPOSITORY##*/} + echo "::set-output name=repo_name::$repo_name" + + - name: show vars + run: | + echo vars.repo_name = ${{steps.vars.outputs.repo_name}} + + - name: install deps + if: ${{ inputs.has_ffi }} + run: sudo apt-get -o Acquire::Retries=3 update && sudo apt-get -o Acquire::Retries=3 install make ftp git bzr curl hwloc libhwloc-dev mesa-opencl-icd ocl-icd-opencl-dev wget -y && sudo apt upgrade -y + + - name: Build + env: + GOPROXY: "https://proxy.golang.org,direct" + GO111MODULE: "on" + run: | + make + + - name: Lint + run: | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.44.2 + golangci-lint run --timeout 10m + + - name: Detect changes + run: | + git status --porcelain + test -z "$(git status --porcelain)" + + - name: Run coverage + run: go test -coverpkg=./... -race -coverprofile=coverage.txt -covermode=atomic ./... + + - name: Upload + uses: codecov/codecov-action@v2 + with: + token: + files: ./coverage.txt + flags: unittests + name: ${{steps.vars.outputs.repo_name}} + fail_ci_if_error: true + verbose: true diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 0e3fb4658c..0000000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Docker Image CI - -on: - push: - branches: ['prep/**', 'release/**', 'test/**', master] - tags: ['**'] - -jobs: - - build: - - runs-on: ubuntu-20.04 - - steps: - - uses: actions/checkout@v3 - - name: Create vars - id: vars - run: | - export github_tag=${{ github.ref_name }} - export is_tag_create=false - - export rx_tag='^refs\/tags\/.*' - export rx_version_tag='^v([0-9]+\.){0,2}(\*|[0-9]+)(-rc[0-9]*){0,1}$' - if [[ "${{github.ref}}" =~ $rx_tag ]]; then - export is_tag_create=true - fi - - echo "::set-output name=github_tag::$github_tag" - echo "::set-output name=is_tag_create::$is_tag_create" - - - name: Show environment - run: | - echo is_tag_create = ${{ steps.vars.outputs.is_tag_create }} - echo github_tag = ${{ steps.vars.outputs.github_tag }} - - - name: Build the Docker image - if: ${{ steps.vars.outputs.is_tag_create == 'true' }} - run: | - make docker-buildenv - make docker-runtime - docker build . --file dockerfile --tag filvenus/venus:latest - docker tag filvenus/venus:latest filvenus/venus:${{ steps.vars.outputs.github_tag }} - docker login --username=filvenus --password ${{ secrets.DOCKER_PASSWORD }} - docker push filvenus/venus:${{ steps.vars.outputs.github_tag }} - docker push filvenus/venus:latest - docker push filvenus/venus-runtime:latest - docker push filvenus/venus-buildenv:latest diff --git a/.github/workflows/docker_image.yml b/.github/workflows/docker_image.yml new file mode 100644 index 0000000000..15de95653b --- /dev/null +++ b/.github/workflows/docker_image.yml @@ -0,0 +1,11 @@ +name: Docker Image CI + +on: + push: + branches: ['prep/**', 'release/**', 'test/**', master] + tags: ['**'] + +jobs: + + build_docker_image: + uses: ./.github/workflows/common_docker_image.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0fc741cd35..d4b02dbbd5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,13 +33,6 @@ jobs: cd /tmp/statediff go install ./cmd/statediff || exit 0 - - name: dep - env: - GOPROXY: "https://proxy.golang.org,direct" - GO111MODULE: "on" - run: | - make deps - - name: Build env: GOPROXY: "https://proxy.golang.org,direct"