Skip to content

Commit

Permalink
ci: 拆分git工作流/split git workflow (#95)
Browse files Browse the repository at this point in the history
ci: split git workflow
  • Loading branch information
simlecode authored Aug 9, 2022
1 parent bd046cb commit a56c1e8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 220 deletions.
196 changes: 16 additions & 180 deletions .github/workflows/build_upload.yml
Original file line number Diff line number Diff line change
@@ -1,187 +1,23 @@
name: build for test/release
name: build and upload

on:
push:
branches: ['prep/**', 'release/**', 'test/**', master, main]
branches: ['prep/**', 'release/**', 'test/**', master]
tags: ['**']
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
fetch-depth: '0'

- name: vars
id: vars
run: |
export bin=bin
export commit=$(git rev-parse HEAD)
export short=$(git rev-parse --short HEAD)
export github_tag=${{github.ref_name}}
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
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
if [[ "${{github.ref_name}}" =~ $rx_version_tag ]]; then
export pub_method=pushRelease
fi
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=bin::$bin"
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"
echo "::set-output name=is_tag_create::$is_tag_create"
- name: show environment
run: |
echo bin = ${{github.bin}}
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}}
echo vars.is_tag_create = ${{steps.vars.outputs.is_tag_create}}
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Build
run: |
sudo make
mkdir ./${{steps.vars.outputs.bin}} && mv ./${{steps.vars.outputs.repo_name}} ./${{steps.vars.outputs.bin}}
- name: Zip Release
uses: TheDoctor0/[email protected]
continue-on-error: true
with:
filename: ${{steps.vars.outputs.artifact_name}}
path: ./${{steps.vars.outputs.bin}}
type: tar

- name: release
id: release
uses: ncipollo/release-action@v1
if: ${{ steps.vars.outputs.pub_method=='pushRelease' }}
continue-on-error: true
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
- name: Publish the Docker image
if: ${{ steps.vars.outputs.is_tag_create == 'true' }}
run: |
docker build . --file dockerfile --tag filvenus/venus-auth:latest
docker tag filvenus/venus-auth:latest filvenus/venus-auth:${{steps.vars.outputs.github_tag }}
docker login --username=filvenus --password ${{ secrets.DOCKER_PASSWORD }}
docker push filvenus/venus-auth:${{steps.vars.outputs.github_tag }}
docker push filvenus/venus-auth:latest
uses: filecoin-project/venus/.github/workflows/common_build_upload.yml@master
with:
bin_name: 'venus-auth'
has_ffi: false
secrets:
OSS_KEY_ID: ${{secrets.OSS_KEY_ID}}
OSS_KEY_SECRET: ${{secrets.OSS_KEY_SECRET}}
OSS_ENDPOINT: ${{secrets.OSS_ENDPOINT}}
OSS_BUCKET: ${{secrets.OSS_BUCKET}}
FTP_HOST: ${{secrets.FTP_HOST}}
FTP_USER: ${{secrets.FTP_USER}}
FTP_PWD: ${{secrets.FTP_PWD}}
GODEYE_URL: ${{secrets.GODEYE_URL}}
token: ${{github.token}}
13 changes: 13 additions & 0 deletions .github/workflows/docker_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Docker Image CI

on:
push:
branches: ['prep/**', 'release/**', 'test/**', master]
tags: ['**']

jobs:

build_docker_image:
uses: filecoin-project/venus/.github/workflows/common_docker_image.yml@master
secrets:
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
45 changes: 5 additions & 40 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,14 @@ name: Go

on:
push:
branches: [master, main]
branches: [master]
pull_request:
branches:
- '**'
workflow_dispatch:

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: Build
env:
GOPROXY: "https://proxy.golang.org,direct"
GO111MODULE: "on"
run: |
make
- name: Change detect
run: |
git status --porcelain
test -z "$(git status --porcelain)"
- 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: Run Test
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: venus-auth
fail_ci_if_error: true
verbose: true
uses: filecoin-project/venus/.github/workflows/common_go.yml@master
with:
has_ffi: false

0 comments on commit a56c1e8

Please sign in to comment.