Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [#55] Run steps in parallel to speed up CICD #96

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,25 @@ permissions:
packages: read
jobs:
MCVS-golang-action:
runs-on: ubuntu-20.04
strategy:
matrix:
testing-type:
- component
- coverage
- integration
- lint
- security-golang-modules
- security-grype
- security-trivy
- unit
runs-on: ubuntu-22.04
steps:
- uses: actions/[email protected]
- uses: schubergphilis/mcvs-golang-action@v0.1.1
- uses: schubergphilis/mcvs-golang-action@v0.9.0
with:
golang-unit-tests-exclusions: |-
\(cmd\/some-app\|internal\/app\/some-app\)
testing-type: ${{ matrix.testing-type }}
token: ${{ secrets.GITHUB_TOKEN }}
```

Expand Down
51 changes: 43 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ inputs:
golang-number-of-tests-in-parallel:
description: |
Number of test in parallel.
testing-type:
description: |
The testing type, e.g. integration, unit or some other.
trivy-action-db:
default: "ghcr.io/aquasecurity/trivy-db:2"
description: |
Expand All @@ -44,18 +47,23 @@ runs:
- run: |
pip install --user yamllint==1.35.1
yamllint -d '{extends: default, rules: {comments: {min-spaces-from-content: 1}}}' .
if: inputs.testing-type == 'lint'
shell: bash
#
# Install the golang version that has been defined in the go.mod file.
#
# yamllint disable rule:line-length
- uses: actions/[email protected]
if: inputs.testing-type == 'component' || inputs.testing-type == 'coverage' || inputs.testing-type == 'integration' || inputs.testing-type == 'unit'
with:
go-version-file: "go.mod"
cache: false
# yamllint enable rule:line-length
#
# Verify downloaded dependencies.
#
- name: verify golang modules
if: inputs.testing-type == 'security-golang-modules'
shell: bash
run: |
go mod verify
Expand All @@ -69,7 +77,7 @@ runs:
# but it does not provide clarity how to resolve it when positive.
#
- name: gci
if: inputs.gci == 'true'
if: inputs.gci == 'true' && inputs.testing-type == 'lint'
shell: bash
run: |
go install github.com/daixiang0/[email protected]
Expand All @@ -82,25 +90,32 @@ runs:
#
# Code security scanning.
#
# * Grype
#
- uses: anchore/[email protected]
if: inputs.token != '' && inputs.testing-type == 'security-grype'
with:
only-fixed: false
output-format: table
path: "."
severity-cutoff: high
#
# * Trivy
#
- uses: 030/[email protected]
if: inputs.token != '' && inputs.testing-type == 'security-trivy'
- name: Log in to GitHub Packages Docker registry
if: inputs.token != ''
if: inputs.token != '' && inputs.testing-type == 'security-trivy'
shell: bash
run: |
echo "${{ inputs.token }}" |\
docker login ghcr.io -u ${{ github.actor }} --password-stdin
#
# Duplicated trivy-action parameters as dependabot does NOT support
# Duplicated trivy-action parameters as GitHub actions do NOT support
# anchors: https://github.com/actions/runner/issues/1182
#
- uses: aquasecurity/[email protected]
if: inputs.token != ''
if: inputs.token != '' && inputs.testing-type == 'security-trivy'
env:
TRIVY_DB_REPOSITORY: ${{ inputs.trivy-action-db }}
TRIVY_JAVA_DB_REPOSITORY: ${{ inputs.trivy-action-java-db }}
Expand All @@ -114,7 +129,7 @@ runs:
severity: "CRITICAL,HIGH"
trivyignores: .trivyignore
- uses: aquasecurity/[email protected]
if: inputs.token == ''
if: inputs.token == '' && inputs.testing-type == 'security-trivy'
env:
TRIVY_DB_REPOSITORY: ${{ inputs.trivy-action-db }}
TRIVY_JAVA_DB_REPOSITORY: ${{ inputs.trivy-action-java-db }}
Expand All @@ -128,7 +143,9 @@ runs:
#
# Run golangci-lint.
#
- uses: golangci/[email protected]
- name: golangci-lint
uses: golangci/[email protected]
if: inputs.testing-type == 'lint'
with:
args: |-
--enable-all \
Expand All @@ -140,6 +157,7 @@ runs:
# Unit tests.
#
- name: unit tests
if: inputs.testing-type == 'unit'
shell: bash
run: |
${GITHUB_ACTION_PATH}/src/go-test.sh \
Expand All @@ -149,9 +167,25 @@ runs:
"${{ inputs.golang-unit-tests-exclusions }}" \
""
#
# Unit & integration tests including code coverage.
# Integration tests.
#
- name: integration tests
if: inputs.testing-type == 'integration'
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
run: |
${GITHUB_ACTION_PATH}/src/go-test.sh \
"" \
"" \
"${{ inputs.golang-number-of-tests-in-parallel }}" \
"${{ inputs.golang-unit-tests-exclusions }}" \
"integration"
#
# Coverage.
#
- name: unit & integrations tests and code coverage
- name: code coverage
if: inputs.testing-type == 'coverage'
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
Expand Down Expand Up @@ -183,6 +217,7 @@ runs:
# Component tests.
#
- name: component tests
if: inputs.testing-type == 'component'
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
Expand Down
Loading