You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-11-06 09:09:19 +02:00
(feat) Golang integration tests dynamic workflow
* Dynamic version detection of Golang * Dynamic Golang integration tests run matrix * Golang timeout to build set at 5 min * Golang integration test timeout to run set at 10 min * Consumer tests timeout set at 20 min Co-authored-by: Alexey Matvievsky <alexey.matvievsky@sap.com>
This commit is contained in:
committed by
GitHub
parent
b28df9d9dd
commit
2dfca180a7
1
.github/workflows/consumer-tests-pr.yml
vendored
1
.github/workflows/consumer-tests-pr.yml
vendored
@@ -19,6 +19,7 @@ jobs:
|
|||||||
github.event.comment.author_association == 'MEMBER'
|
github.event.comment.author_association == 'MEMBER'
|
||||||
)
|
)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 20
|
||||||
steps:
|
steps:
|
||||||
- uses: styfle/cancel-workflow-action@0.10.0
|
- uses: styfle/cancel-workflow-action@0.10.0
|
||||||
- name: Get pull request URL
|
- name: Get pull request URL
|
||||||
|
|||||||
1
.github/workflows/consumer-tests.yml
vendored
1
.github/workflows/consumer-tests.yml
vendored
@@ -10,6 +10,7 @@ jobs:
|
|||||||
consumer_tests:
|
consumer_tests:
|
||||||
name: Consumer tests
|
name: Consumer tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 20
|
||||||
steps:
|
steps:
|
||||||
- uses: styfle/cancel-workflow-action@0.10.0
|
- uses: styfle/cancel-workflow-action@0.10.0
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|||||||
62
.github/workflows/integration-tests-pr.yml
vendored
62
.github/workflows/integration-tests-pr.yml
vendored
@@ -6,13 +6,6 @@ on:
|
|||||||
- created
|
- created
|
||||||
- edited
|
- edited
|
||||||
|
|
||||||
env:
|
|
||||||
GHA_GO_VERSION: 1.18.x
|
|
||||||
TIMEOUT: 10m
|
|
||||||
|
|
||||||
PIPER_INTEGRATION_GITHUB_TOKEN: ${{secrets.PIPER_INTEGRATION_GITHUB_TOKEN}}
|
|
||||||
PIPER_INTEGRATION_SONAR_TOKEN: ${{secrets.PIPER_INTEGRATION_SONAR_TOKEN}}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
start:
|
start:
|
||||||
name: Start
|
name: Start
|
||||||
@@ -26,6 +19,7 @@ jobs:
|
|||||||
github.event.comment.author_association == 'MEMBER'
|
github.event.comment.author_association == 'MEMBER'
|
||||||
)
|
)
|
||||||
outputs:
|
outputs:
|
||||||
|
go_version: ${{ steps.go_version.outputs.go_version }}
|
||||||
sha: ${{ steps.sha.outputs.sha }}
|
sha: ${{ steps.sha.outputs.sha }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -52,6 +46,10 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
repository: ${{ steps.repository.outputs.repository }}
|
repository: ${{ steps.repository.outputs.repository }}
|
||||||
ref: ${{ steps.branch_name.outputs.branch_name }}
|
ref: ${{ steps.branch_name.outputs.branch_name }}
|
||||||
|
- name: Get GO version
|
||||||
|
id: go_version
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=go_version::$(cat go.mod | grep go | head -1 | awk '{print $2}')"
|
||||||
- name: Get commit SHA
|
- name: Get commit SHA
|
||||||
id: sha
|
id: sha
|
||||||
run: |
|
run: |
|
||||||
@@ -78,7 +76,7 @@ jobs:
|
|||||||
ref: ${{ needs.start.outputs.sha }}
|
ref: ${{ needs.start.outputs.sha }}
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: ${{ env.GHA_GO_VERSION }}
|
go-version: ${{ needs.start.outputs.go_version }}
|
||||||
- name: Build
|
- name: Build
|
||||||
# with `-tags release` we ensure that shared test utilities won't end up in the binary
|
# with `-tags release` we ensure that shared test utilities won't end up in the binary
|
||||||
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o piper -tags release
|
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o piper -tags release
|
||||||
@@ -91,6 +89,8 @@ jobs:
|
|||||||
|
|
||||||
build_integration_tests:
|
build_integration_tests:
|
||||||
name: Build integration tests
|
name: Build integration tests
|
||||||
|
outputs:
|
||||||
|
matrix: ${{ steps.matrix.outputs.matrix }}
|
||||||
needs:
|
needs:
|
||||||
- start
|
- start
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -100,9 +100,14 @@ jobs:
|
|||||||
ref: ${{ needs.start.outputs.sha }}
|
ref: ${{ needs.start.outputs.sha }}
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: ${{ env.GHA_GO_VERSION }}
|
go-version: ${{ needs.start.outputs.go_version }}
|
||||||
- name: Build
|
- name: Build
|
||||||
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test -c -o integration_tests -tags integration ./integration/...
|
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test -c -o integration_tests -tags integration ./integration/...
|
||||||
|
- name: Form integration tests run matrix
|
||||||
|
if: success()
|
||||||
|
id: matrix
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=matrix::$(go run .github/workflows/parse_integration_test_list.go -file ./integration/github_actions_integration_test_list.yml)"
|
||||||
- name: Upload integration tests binary
|
- name: Upload integration tests binary
|
||||||
if: success()
|
if: success()
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
@@ -117,40 +122,16 @@ jobs:
|
|||||||
- build_integration_tests
|
- build_integration_tests
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix: ${{ fromJson(needs.build_integration_tests.outputs.matrix) }}
|
||||||
os:
|
runs-on: ubuntu-latest
|
||||||
- ubuntu-latest
|
timeout-minutes: 10
|
||||||
version:
|
|
||||||
# tough CNB tests are decomposed to reduce pipeline execution time
|
|
||||||
- '"(TestCNBIntegrationBindings|TestCNBIntegrationWrongBuilderProject|TestCNBIntegrationNonZipPath|TestCNBIntegrationZipPath|TestCNBIntegrationPreserveFilesIgnored)"'
|
|
||||||
- '"TestCNBIntegrationPreserveFiles\b"'
|
|
||||||
- '"TestCNBIntegrationNPMProject"'
|
|
||||||
- '"TestCNBIntegrationMultiImage"'
|
|
||||||
- '"TestCNBIntegrationNPMCustomBuildpacksBuildpacklessProject"'
|
|
||||||
- '"TestCNBIntegrationNPMCustomBuildpacksFullProject"'
|
|
||||||
- '"TestCNBIntegrationProjectDescriptor"'
|
|
||||||
|
|
||||||
- '"TestGolangIntegration"'
|
|
||||||
- '"TestGradleIntegration"'
|
|
||||||
|
|
||||||
# Jenkins tests are still not implemented(skipped) yet
|
|
||||||
# - '"TestJenkinsIntegration"'
|
|
||||||
|
|
||||||
- '"TestMavenIntegration"'
|
|
||||||
- '"TestMTAIntegration"'
|
|
||||||
- '"TestNexusIntegration"'
|
|
||||||
|
|
||||||
# these are light-weighted tests, so we can use only one pod to reduce resource consumption
|
|
||||||
- '"Test(Gauge|GCS|GitHub|GitOps|Influx|NPM|Piper|Python|Sonar|Vault|Karma)Integration"'
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: ${{ needs.start.outputs.sha }}
|
ref: ${{ needs.start.outputs.sha }}
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: ${{ env.GHA_GO_VERSION }}
|
go-version: ${{ needs.start.outputs.go_version }}
|
||||||
- name: Download Piper binary
|
- name: Download Piper binary
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
@@ -161,13 +142,16 @@ jobs:
|
|||||||
name: integration_tests
|
name: integration_tests
|
||||||
path: ./integration/
|
path: ./integration/
|
||||||
- name: Run test
|
- name: Run test
|
||||||
|
env:
|
||||||
|
PIPER_INTEGRATION_GITHUB_TOKEN: ${{secrets.PIPER_INTEGRATION_GITHUB_TOKEN}}
|
||||||
|
PIPER_INTEGRATION_SONAR_TOKEN: ${{secrets.PIPER_INTEGRATION_SONAR_TOKEN}}
|
||||||
run: |
|
run: |
|
||||||
chmod +x piper
|
chmod +x piper
|
||||||
cd ./integration
|
cd ./integration
|
||||||
chmod +x integration_tests
|
chmod +x integration_tests
|
||||||
./integration_tests -test.v -test.timeout ${TIMEOUT} -test.run ${{ matrix.version }}
|
./integration_tests -test.v -test.run ${{ matrix.run }}
|
||||||
|
|
||||||
Finish:
|
finish:
|
||||||
name: Finish
|
name: Finish
|
||||||
if: always() && needs.start.result == 'success'
|
if: always() && needs.start.result == 'success'
|
||||||
needs:
|
needs:
|
||||||
|
|||||||
64
.github/workflows/integration-tests.yml
vendored
64
.github/workflows/integration-tests.yml
vendored
@@ -6,22 +6,20 @@ on:
|
|||||||
- master
|
- master
|
||||||
- it/**
|
- it/**
|
||||||
|
|
||||||
env:
|
|
||||||
GHA_GO_VERSION: 1.18.x
|
|
||||||
TIMEOUT: 10m
|
|
||||||
|
|
||||||
PIPER_INTEGRATION_GITHUB_TOKEN: ${{secrets.PIPER_INTEGRATION_GITHUB_TOKEN}}
|
|
||||||
PIPER_INTEGRATION_SONAR_TOKEN: ${{secrets.PIPER_INTEGRATION_SONAR_TOKEN}}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
start:
|
start:
|
||||||
name: Start
|
name: Start
|
||||||
outputs:
|
outputs:
|
||||||
|
go_version: ${{ steps.go_version.outputs.go_version }}
|
||||||
sha: ${{ steps.sha.outputs.sha }}
|
sha: ${{ steps.sha.outputs.sha }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: styfle/cancel-workflow-action@0.10.0
|
- uses: styfle/cancel-workflow-action@0.10.0
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
- name: Get GO version
|
||||||
|
id: go_version
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=go_version::$(cat go.mod | grep go | head -1 | awk '{print $2}')"
|
||||||
- name: Get commit SHA
|
- name: Get commit SHA
|
||||||
id: sha
|
id: sha
|
||||||
run: |
|
run: |
|
||||||
@@ -42,13 +40,14 @@ jobs:
|
|||||||
needs:
|
needs:
|
||||||
- start
|
- start
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 5
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: ${{ needs.start.outputs.sha }}
|
ref: ${{ needs.start.outputs.sha }}
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: ${{ env.GHA_GO_VERSION }}
|
go-version: ${{ needs.start.outputs.go_version }}
|
||||||
- name: Build
|
- name: Build
|
||||||
# with `-tags release` we ensure that shared test utilities won't end up in the binary
|
# with `-tags release` we ensure that shared test utilities won't end up in the binary
|
||||||
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o piper -tags release
|
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o piper -tags release
|
||||||
@@ -61,18 +60,26 @@ jobs:
|
|||||||
|
|
||||||
build_integration_tests:
|
build_integration_tests:
|
||||||
name: Build integration tests
|
name: Build integration tests
|
||||||
|
outputs:
|
||||||
|
matrix: ${{ steps.matrix.outputs.matrix }}
|
||||||
needs:
|
needs:
|
||||||
- start
|
- start
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 5
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: ${{ needs.start.outputs.sha }}
|
ref: ${{ needs.start.outputs.sha }}
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: ${{ env.GHA_GO_VERSION }}
|
go-version: ${{ needs.start.outputs.go_version }}
|
||||||
- name: Build
|
- name: Build
|
||||||
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test -c -o integration_tests -tags integration ./integration/...
|
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test -c -o integration_tests -tags integration ./integration/...
|
||||||
|
- name: Form integration tests run matrix
|
||||||
|
if: success()
|
||||||
|
id: matrix
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=matrix::$(go run .github/workflows/parse_integration_test_list.go -file ./integration/github_actions_integration_test_list.yml)"
|
||||||
- name: Upload integration tests binary
|
- name: Upload integration tests binary
|
||||||
if: success()
|
if: success()
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
@@ -87,40 +94,16 @@ jobs:
|
|||||||
- build_integration_tests
|
- build_integration_tests
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix: ${{ fromJson(needs.build_integration_tests.outputs.matrix) }}
|
||||||
os:
|
runs-on: ubuntu-latest
|
||||||
- ubuntu-latest
|
timeout-minutes: 10
|
||||||
version:
|
|
||||||
# tough CNB tests are decomposed to reduce pipeline execution time
|
|
||||||
- '"(TestCNBIntegrationBindings|TestCNBIntegrationWrongBuilderProject|TestCNBIntegrationNonZipPath|TestCNBIntegrationZipPath|TestCNBIntegrationPreserveFilesIgnored)"'
|
|
||||||
- '"TestCNBIntegrationPreserveFiles\b"'
|
|
||||||
- '"TestCNBIntegrationNPMProject"'
|
|
||||||
- '"TestCNBIntegrationMultiImage"'
|
|
||||||
- '"TestCNBIntegrationNPMCustomBuildpacksBuildpacklessProject"'
|
|
||||||
- '"TestCNBIntegrationNPMCustomBuildpacksFullProject"'
|
|
||||||
- '"TestCNBIntegrationProjectDescriptor"'
|
|
||||||
|
|
||||||
- '"TestGolangIntegration"'
|
|
||||||
- '"TestGradleIntegration"'
|
|
||||||
|
|
||||||
# Jenkins tests are still not implemented(skipped) yet
|
|
||||||
# - '"TestJenkinsIntegration"'
|
|
||||||
|
|
||||||
- '"TestMavenIntegration"'
|
|
||||||
- '"TestMTAIntegration"'
|
|
||||||
- '"TestNexusIntegration"'
|
|
||||||
|
|
||||||
# these are light-weighted tests, so we can use only one pod to reduce resource consumption
|
|
||||||
- '"Test(Gauge|GCS|GitHub|GitOps|Influx|NPM|Piper|Python|Sonar|Vault|Karma)Integration"'
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: ${{ needs.start.outputs.sha }}
|
ref: ${{ needs.start.outputs.sha }}
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: ${{ env.GHA_GO_VERSION }}
|
go-version: ${{ needs.start.outputs.go_version }}
|
||||||
- name: Download Piper binary
|
- name: Download Piper binary
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
@@ -131,13 +114,16 @@ jobs:
|
|||||||
name: integration_tests
|
name: integration_tests
|
||||||
path: ./integration/
|
path: ./integration/
|
||||||
- name: Run test
|
- name: Run test
|
||||||
|
env:
|
||||||
|
PIPER_INTEGRATION_GITHUB_TOKEN: ${{secrets.PIPER_INTEGRATION_GITHUB_TOKEN}}
|
||||||
|
PIPER_INTEGRATION_SONAR_TOKEN: ${{secrets.PIPER_INTEGRATION_SONAR_TOKEN}}
|
||||||
run: |
|
run: |
|
||||||
chmod +x piper
|
chmod +x piper
|
||||||
cd ./integration
|
cd ./integration
|
||||||
chmod +x integration_tests
|
chmod +x integration_tests
|
||||||
./integration_tests -test.v -test.timeout ${TIMEOUT} -test.run ${{ matrix.version }}
|
./integration_tests -test.v -test.run ${{ matrix.run }}
|
||||||
|
|
||||||
Finish:
|
finish:
|
||||||
name: Finish
|
name: Finish
|
||||||
if: always() && needs.start.result == 'success'
|
if: always() && needs.start.result == 'success'
|
||||||
needs:
|
needs:
|
||||||
|
|||||||
21
.github/workflows/parse_integration_test_list.go
vendored
Normal file
21
.github/workflows/parse_integration_test_list.go
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"github.com/ghodss/yaml"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
file := flag.String("file", "../../integration/github_actions_integration_test_list.yml", "Tests to be executed")
|
||||||
|
flag.Parse()
|
||||||
|
f, _ := os.ReadFile(*file)
|
||||||
|
var Matrix struct {
|
||||||
|
Run interface{} `json:"run,omitempty" yaml:"run"`
|
||||||
|
}
|
||||||
|
yaml.Unmarshal(f, &Matrix)
|
||||||
|
output, _ := json.Marshal(Matrix)
|
||||||
|
fmt.Println(string(output))
|
||||||
|
}
|
||||||
24
integration/github_actions_integration_test_list.yml
Normal file
24
integration/github_actions_integration_test_list.yml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Every run element will be executed in a different pod of job matrix
|
||||||
|
# Use it to optimize resource consumption and execution time
|
||||||
|
run:
|
||||||
|
# tough CNB tests are decomposed to reduce pipeline execution time
|
||||||
|
- '"(TestCNBIntegrationBindings|TestCNBIntegrationWrongBuilderProject|TestCNBIntegrationNonZipPath|TestCNBIntegrationZipPath|TestCNBIntegrationPreserveFilesIgnored)"'
|
||||||
|
- '"TestCNBIntegrationPreserveFiles\b"'
|
||||||
|
- '"TestCNBIntegrationNPMProject"'
|
||||||
|
- '"TestCNBIntegrationMultiImage"'
|
||||||
|
- '"TestCNBIntegrationNPMCustomBuildpacksBuildpacklessProject"'
|
||||||
|
- '"TestCNBIntegrationNPMCustomBuildpacksFullProject"'
|
||||||
|
- '"TestCNBIntegrationProjectDescriptor"'
|
||||||
|
|
||||||
|
- '"TestGolangIntegration"'
|
||||||
|
- '"TestGradleIntegration"'
|
||||||
|
|
||||||
|
# Jenkins tests are still not implemented(skipped) yet
|
||||||
|
#- '"TestJenkinsIntegration"'
|
||||||
|
|
||||||
|
- '"TestMavenIntegration"'
|
||||||
|
- '"TestMTAIntegration"'
|
||||||
|
- '"TestNexusIntegration"'
|
||||||
|
|
||||||
|
# these are light-weighted tests, so we can use only one pod to reduce resource consumption
|
||||||
|
- '"Test(Gauge|GCS|GitHub|GitOps|Influx|NPM|Piper|Python|Sonar|Vault|Karma)Integration"'
|
||||||
Reference in New Issue
Block a user