2022-09-20 08:24:04 +02:00
|
|
|
name: Integration tests (Pull Request)
|
|
|
|
|
|
|
|
on:
|
|
|
|
issue_comment:
|
|
|
|
types:
|
|
|
|
- created
|
|
|
|
- edited
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
start:
|
|
|
|
name: Start
|
|
|
|
if: |
|
|
|
|
(
|
2022-09-20 18:29:21 +02:00
|
|
|
github.event.comment.body == '/it' ||
|
|
|
|
github.event.comment.body == '/it-go'
|
|
|
|
) && (
|
2022-09-20 08:24:04 +02:00
|
|
|
github.event.comment.author_association == 'COLLABORATOR' ||
|
|
|
|
github.event.comment.author_association == 'OWNER' ||
|
|
|
|
github.event.comment.author_association == 'MEMBER'
|
|
|
|
)
|
2022-09-20 18:29:21 +02:00
|
|
|
outputs:
|
2022-09-22 19:12:13 +02:00
|
|
|
go_version: ${{ steps.go_version.outputs.go_version }}
|
2022-09-20 18:29:21 +02:00
|
|
|
sha: ${{ steps.sha.outputs.sha }}
|
|
|
|
runs-on: ubuntu-latest
|
2022-09-20 08:24:04 +02:00
|
|
|
steps:
|
2022-09-22 12:14:53 +02:00
|
|
|
- uses: styfle/cancel-workflow-action@0.10.0
|
2022-09-21 09:08:15 +02:00
|
|
|
- name: Get pull request URL
|
|
|
|
id: pull_request
|
|
|
|
run: |
|
|
|
|
echo "::set-output name=pull_request::$(curl ${{ github.event.comment.issue_url }} |
|
|
|
|
jq '.pull_request.url' |
|
|
|
|
sed 's/\"//g')"
|
2022-09-22 12:14:53 +02:00
|
|
|
- name: Get repository
|
|
|
|
id: repository
|
|
|
|
run: |
|
|
|
|
echo "::set-output name=repository::$(curl ${{ steps.pull_request.outputs.pull_request }} |
|
|
|
|
jq '.head.repo.full_name' |
|
|
|
|
sed 's/\"//g')"
|
2022-09-21 09:08:15 +02:00
|
|
|
- name: Get branch name
|
|
|
|
id: branch_name
|
|
|
|
run: |
|
|
|
|
echo "::set-output name=branch_name::$(curl ${{ steps.pull_request.outputs.pull_request }} |
|
|
|
|
jq '.head.ref' |
|
|
|
|
sed 's/\"//g')"
|
2022-09-20 18:29:21 +02:00
|
|
|
- uses: actions/checkout@v3
|
2022-09-21 09:08:15 +02:00
|
|
|
with:
|
2022-09-22 12:14:53 +02:00
|
|
|
repository: ${{ steps.repository.outputs.repository }}
|
2022-09-21 09:08:15 +02:00
|
|
|
ref: ${{ steps.branch_name.outputs.branch_name }}
|
2022-09-22 19:12:13 +02:00
|
|
|
- name: Get GO version
|
|
|
|
id: go_version
|
|
|
|
run: |
|
|
|
|
echo "::set-output name=go_version::$(cat go.mod | grep go | head -1 | awk '{print $2}')"
|
2022-09-20 18:29:21 +02:00
|
|
|
- name: Get commit SHA
|
|
|
|
id: sha
|
|
|
|
run: |
|
|
|
|
echo "::set-output name=sha::$(git log --format=%H -n 1)"
|
2022-09-20 08:24:04 +02:00
|
|
|
- name: Update status
|
|
|
|
run: |
|
|
|
|
curl \
|
|
|
|
--location \
|
2022-09-20 18:29:21 +02:00
|
|
|
--request POST 'https://api.github.com/repos/SAP/jenkins-library/statuses/${{ steps.sha.outputs.sha }}' \
|
2022-09-20 08:24:04 +02:00
|
|
|
-H 'Content-Type: application/json' \
|
|
|
|
--data '{"state": "pending",
|
|
|
|
"context": "Go / integration-tests",
|
|
|
|
"target_url": "https://github.com/SAP/jenkins-library/actions/runs/${{ github.run_id }}"}' \
|
|
|
|
-H 'Authorization: token ${{secrets.INTEGRATION_TEST_VOTING_TOKEN}}'
|
|
|
|
|
|
|
|
build_piper:
|
|
|
|
name: Build Piper
|
|
|
|
needs:
|
|
|
|
- start
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2022-09-20 18:29:21 +02:00
|
|
|
- uses: actions/checkout@v3
|
2022-09-20 08:24:04 +02:00
|
|
|
with:
|
2022-09-20 18:29:21 +02:00
|
|
|
ref: ${{ needs.start.outputs.sha }}
|
2022-09-20 08:24:04 +02:00
|
|
|
- uses: actions/setup-go@v3
|
|
|
|
with:
|
2022-09-22 19:12:13 +02:00
|
|
|
go-version: ${{ needs.start.outputs.go_version }}
|
2022-09-20 08:24:04 +02:00
|
|
|
- name: Build
|
|
|
|
# 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
|
|
|
|
- name: Upload Piper binary
|
|
|
|
if: success()
|
|
|
|
uses: actions/upload-artifact@v3
|
|
|
|
with:
|
|
|
|
name: piper
|
|
|
|
path: piper
|
|
|
|
|
|
|
|
build_integration_tests:
|
|
|
|
name: Build integration tests
|
2022-09-22 19:12:13 +02:00
|
|
|
outputs:
|
|
|
|
matrix: ${{ steps.matrix.outputs.matrix }}
|
2022-09-20 08:24:04 +02:00
|
|
|
needs:
|
|
|
|
- start
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2022-09-20 18:29:21 +02:00
|
|
|
- uses: actions/checkout@v3
|
2022-09-20 08:24:04 +02:00
|
|
|
with:
|
2022-09-20 18:29:21 +02:00
|
|
|
ref: ${{ needs.start.outputs.sha }}
|
2022-09-20 08:24:04 +02:00
|
|
|
- uses: actions/setup-go@v3
|
|
|
|
with:
|
2022-09-22 19:12:13 +02:00
|
|
|
go-version: ${{ needs.start.outputs.go_version }}
|
2022-09-20 08:24:04 +02:00
|
|
|
- name: Build
|
|
|
|
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test -c -o integration_tests -tags integration ./integration/...
|
2022-09-22 19:12:13 +02:00
|
|
|
- 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)"
|
2022-09-20 08:24:04 +02:00
|
|
|
- name: Upload integration tests binary
|
|
|
|
if: success()
|
|
|
|
uses: actions/upload-artifact@v3
|
|
|
|
with:
|
|
|
|
name: integration_tests
|
|
|
|
path: integration_tests
|
|
|
|
|
|
|
|
run_integration_tests:
|
|
|
|
name: Run integration tests
|
|
|
|
needs:
|
|
|
|
- build_piper
|
|
|
|
- build_integration_tests
|
2022-12-12 09:55:38 +02:00
|
|
|
- start
|
2022-09-20 08:24:04 +02:00
|
|
|
strategy:
|
|
|
|
fail-fast: true
|
2022-09-22 19:12:13 +02:00
|
|
|
matrix: ${{ fromJson(needs.build_integration_tests.outputs.matrix) }}
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
timeout-minutes: 10
|
2022-09-20 08:24:04 +02:00
|
|
|
steps:
|
2022-09-20 18:29:21 +02:00
|
|
|
- uses: actions/checkout@v3
|
2022-09-20 08:24:04 +02:00
|
|
|
with:
|
2022-09-20 18:29:21 +02:00
|
|
|
ref: ${{ needs.start.outputs.sha }}
|
2022-09-20 08:24:04 +02:00
|
|
|
- uses: actions/setup-go@v3
|
|
|
|
with:
|
2022-09-22 19:12:13 +02:00
|
|
|
go-version: ${{ needs.start.outputs.go_version }}
|
2022-09-20 08:24:04 +02:00
|
|
|
- name: Download Piper binary
|
|
|
|
uses: actions/download-artifact@v3
|
|
|
|
with:
|
|
|
|
name: piper
|
|
|
|
- name: Download integration tests binary
|
|
|
|
uses: actions/download-artifact@v3
|
|
|
|
with:
|
|
|
|
name: integration_tests
|
|
|
|
path: ./integration/
|
|
|
|
- name: Run test
|
2022-09-22 19:12:13 +02:00
|
|
|
env:
|
|
|
|
PIPER_INTEGRATION_GITHUB_TOKEN: ${{secrets.PIPER_INTEGRATION_GITHUB_TOKEN}}
|
|
|
|
PIPER_INTEGRATION_SONAR_TOKEN: ${{secrets.PIPER_INTEGRATION_SONAR_TOKEN}}
|
2023-01-19 11:02:56 +02:00
|
|
|
PIPER_tmsServiceKey: ${{secrets.PIPER_TMSSERVICEKEY}}
|
2022-09-20 08:24:04 +02:00
|
|
|
run: |
|
|
|
|
chmod +x piper
|
|
|
|
cd ./integration
|
|
|
|
chmod +x integration_tests
|
2022-09-22 19:12:13 +02:00
|
|
|
./integration_tests -test.v -test.run ${{ matrix.run }}
|
2022-09-20 08:24:04 +02:00
|
|
|
|
2022-09-22 19:12:13 +02:00
|
|
|
finish:
|
2022-09-20 08:24:04 +02:00
|
|
|
name: Finish
|
|
|
|
if: always() && needs.start.result == 'success'
|
|
|
|
needs:
|
|
|
|
- start
|
|
|
|
- build_piper
|
|
|
|
- build_integration_tests
|
|
|
|
- run_integration_tests
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Update status
|
|
|
|
run: |
|
|
|
|
if [[ "${{ needs.run_integration_tests.result }}" == "success" ]]
|
|
|
|
then
|
|
|
|
curl \
|
|
|
|
--location \
|
2022-09-20 18:29:21 +02:00
|
|
|
--request POST 'https://api.github.com/repos/SAP/jenkins-library/statuses/${{ needs.start.outputs.sha }}' \
|
2022-09-20 08:24:04 +02:00
|
|
|
-H 'Content-Type: application/json' \
|
|
|
|
--data '{"state": "success",
|
|
|
|
"context": "Go / integration-tests",
|
|
|
|
"target_url": "https://github.com/SAP/jenkins-library/actions/runs/${{ github.run_id }}"}' \
|
|
|
|
-H 'Authorization: token ${{secrets.INTEGRATION_TEST_VOTING_TOKEN}}' && \
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
curl \
|
|
|
|
--location \
|
2022-09-20 18:29:21 +02:00
|
|
|
--request POST 'https://api.github.com/repos/SAP/jenkins-library/statuses/${{ needs.start.outputs.sha }}' \
|
2022-09-20 08:24:04 +02:00
|
|
|
-H 'Content-Type: application/json' \
|
|
|
|
--data '{"state": "failure",
|
|
|
|
"context": "Go / integration-tests",
|
|
|
|
"target_url": "https://github.com/SAP/jenkins-library/actions/runs/${{ github.run_id }}"}' \
|
|
|
|
-H 'Authorization: token ${{secrets.INTEGRATION_TEST_VOTING_TOKEN}}' && \
|
|
|
|
exit 1
|
|
|
|
fi
|