Bump actions/download-artifact from 3 to 4 #223
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
name: Auto Golang Lint And Unitest | |
on: | |
pull_request: {} | |
push: | |
branches: | |
- main | |
- release-* | |
workflow_dispatch: | |
inputs: | |
ref: | |
description: 'branch, sha, tag' | |
required: true | |
default: main | |
workflow_call: | |
inputs: | |
ref: | |
required: true | |
type: string | |
permissions: write-all | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.after }} | |
cancel-in-progress: true | |
jobs: | |
filter_changes: | |
name: Deduce required tests from code changes | |
runs-on: ubuntu-latest | |
outputs: | |
check: ${{ steps.result.outputs.check }} | |
ref: ${{ steps.result.outputs.ref }} | |
steps: | |
- name: Check Go Code Changes | |
uses: dorny/paths-filter@v2.10.2 | |
if: ${{ github.event_name == 'pull_request' }} | |
id: filter_pr | |
with: | |
base: ${{ github.event.pull_request.base.sha }} | |
ref: ${{ github.event.pull_request.head.sha }} | |
filters: | | |
src: | |
- .github/workflows/lint-golang.yaml | |
- '**/*.go' | |
- 'go.mod' | |
- 'go.sum' | |
- 'api/**/openapi.yaml' | |
- 'charts/**/crds/*.yaml' | |
- name: Result | |
id: result | |
run: | | |
if ${{ github.event_name == 'push' }} ; then | |
echo "trigger by push" | |
echo "::set-output name=check::true" | |
echo "::set-output name=ref::${{ github.sha }}" | |
elif ${{ github.event_name == 'pull_request' }} ; then | |
echo "trigger by pull_request" | |
flag=${{ steps.filter_pr.outputs.src }} | |
echo "::set-output name=check::${flag}" | |
ref=${{ github.event.pull_request.head.sha }} | |
echo "::set-output name=ref::${ref}" | |
elif ${{ inputs.ref != '' }} ; then | |
echo "trigger by workflow_call" | |
echo "::set-output name=check::true" | |
echo "::set-output name=ref::${{ inputs.ref }}" | |
elif ${{ github.event_name == 'workflow_dispatch' }} ; then | |
echo "trigger by workflow_dispatch" | |
echo "::set-output name=check::true" | |
echo "::set-output name=ref::${{ github.event.inputs.ref }}" | |
else | |
echo "error, unexpected event " | |
exit 1 | |
fi | |
lint-golang: | |
needs: filter_changes | |
if: ${{ needs.filter_changes.outputs.check == 'true' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: 1.17.8 | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
persist-credentials: false | |
ref: ${{ needs.filter_changes.outputs.ref }} | |
- name: Check module vendoring | |
run: | | |
go mod tidy | |
go mod vendor | |
if ! test -z "$(git status --porcelain)"; then | |
echo "please run 'go mod tidy && go mod vendor', and submit your changes" | |
exit 1 | |
fi | |
# ================ lint | |
- name: Run golangci-lint | |
id: golangci_lint | |
continue-on-error: true | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
version: latest | |
- name: Check Make lint-golang | |
id: other | |
continue-on-error: true | |
run: | | |
make lint-golang | |
- name: Result | |
run: | | |
result=${{ steps.golangci_lint.outcome }} | |
[ "${result}"x == "failure"x ] && echo "step golangci_lint failed" && exit 1 | |
result=${{ steps.other.outcome }} | |
[ "${result}"x == "failure"x ] && echo "step gokart failed" && exit 3 | |
echo "all succeed" | |
exit 0 | |
quality: | |
needs: filter_changes | |
if: ${{ needs.filter_changes.outputs.check == 'true' }} | |
runs-on: ubuntu-latest | |
permissions: | |
actions: read | |
contents: read | |
security-events: write | |
steps: | |
- name: Install Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: 1.17.8 | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
persist-credentials: false | |
ref: ${{ needs.filter_changes.outputs.ref }} | |
fetch-depth: 0 | |
# ================= quality | |
# too slow | |
# - name: CodeQL Initialize | |
# uses: github/codeql-action/init@v2.1.8 | |
# with: | |
# languages: go | |
# - name: CodeQL Analysis | |
# uses: github/codeql-action/analyze@v2.1.8 | |
- name: gokart | |
id: gokart | |
run: | | |
go install github.com/praetorian-inc/gokart@latest | |
gokart scan --globalsTainted | |
lint_SDK_and_build: | |
needs: filter_changes | |
if: ${{ needs.filter_changes.outputs.check == 'true' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: 1.17.8 | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
persist-credentials: false | |
ref: ${{ needs.filter_changes.outputs.ref }} | |
- name: Check SDK | |
run: | | |
flag="" | |
echo "Check Openapi yaml" | |
if make openapi-validate-spec ; then | |
echo " pass openapi yaml " | |
else | |
echo "error, failed to check openapi yaml " | |
flag="bad" | |
fi | |
echo "Check Openapi SDK" | |
if make openapi-verify ; then | |
echo " pass openapi sdk check" | |
else | |
echo "error, failed to check openapi sdk " | |
flag="bad" | |
fi | |
echo "Check K8S SDK and yaml" | |
if make manifests-verify ; then | |
echo " pass K8S SDK and yaml" | |
else | |
echo "error, failed to K8S SDK and yaml" | |
flag="bad" | |
fi | |
[ -n "$flag" ] && exit 1 | |
exit 0 | |
- name: Build Lint | |
run: | | |
make build-bin | |
unitest: | |
needs: filter_changes | |
if: ${{ needs.filter_changes.outputs.check == 'true' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: 1.17.8 | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
persist-credentials: false | |
ref: ${{ needs.filter_changes.outputs.ref }} | |
# unitest and e2e, _test.go | |
- name: Check label of All test go | |
run: | | |
make check_test_label | |
# ================= unitest | |
- name: Run unitest | |
id: unitest | |
continue-on-error: true | |
run: | | |
make unitest-tests | |
- name: Upload Coverage Artifact | |
if: ${{ steps.unitest.outcome == 'failure' }} | |
uses: actions/upload-artifact@v3.0.0 | |
with: | |
name: coverage.out | |
path: coverage.out | |
retention-days: 1 | |
- name: Upload Report Artifact | |
if: ${{ steps.unitest.outcome == 'failure' }} | |
uses: actions/upload-artifact@v3.0.0 | |
with: | |
name: unitestreport.json | |
path: unitestreport.json | |
retention-days: 1 | |
# ============= upload coverage report | |
- name: Upload to Codecov | |
if: ${{ steps.unitest.outcome != 'failure' }} | |
uses: codecov/codecov-action@v3.1.0 | |
with: | |
directory: './' | |
files: 'coverage.out' | |
flags: unittests | |
name: my-codecov-umbrella | |
fail_ci_if_error: true | |
verbose: true | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: Result | |
if: ${{ steps.unitest.outcome == 'failure' }} | |
run: | | |
echo "unitest failed" | |
exit 1 |